Views
No views yet
| Location | Contents | Use |
|---|---|---|
data/AnyRuler.zip | AnyRuler images and centimeter-mark annotations (998 MB) | Training and testing |
data/Rulers2023_scale.zip | Rulers2023 images and centimeter-mark annotations (2.46 GB) | Evaluation |
weights/final_rulernet.zip | Final RulerNet checkpoint (131 MB) | PyTorch inference, evaluation, or fine-tuning |
weights/final_deepgp.zip | DeepGP solver checkpoint (112 MB) | Optional faster geometric-progression solving |
weights/pretrained_rulernet.zip | Synthetic-data pretrained RulerNet checkpoint (158 MB) | Initialize training to reproduce the paper setup |
model.onnx | CPU-ready ONNX export (57.1 MB) | Lightweight deployment and inference |
pip install -U huggingface_hub1hf download ymp5078/RulerNet data/AnyRuler.zip --local-dir .
2hf download ymp5078/RulerNet data/Rulers2023_scale.zip --local-dir .
3hf download ymp5078/RulerNet weights/final_rulernet.zip --local-dir .
4hf download ymp5078/RulerNet weights/final_deepgp.zip --local-dir .
5hf download ymp5078/RulerNet weights/pretrained_rulernet.zip --local-dir .
6hf download ymp5078/RulerNet model.onnx --local-dir .1unzip data/AnyRuler.zip -d data/
2unzip weights/final_rulernet.zip -d weights/AnyRuler.zip contains 1,416 annotated ruler images. Use it for training or
for evaluating a model with centimeter-mark labels. After extraction, provide
the extracted directory to the code repository with --data-dir.1<data-dir>/
2├── ruler_image/ # input images
3└── cm_marks/ # matching JSON centimeter-mark annotationsRulers2023_scale.zip contains the Rulers2023 evaluation images together
with centimeter-mark annotations. Use it with --test-dataset ruler2023.1<data-dir>/
2├── real-test/images/ # evaluation images
3└── real-test-marks/ # JSON centimeter-mark annotations1git clone https://github.com/ymp5078/RulerNet.git
2cd RulerNet
3pip install -r requirements.txt1python inference.py \
2 --config configs/config_graphic_gen.yaml \
3 --checkpoint <path-to-final_rulernet>/checkpoints/epoch=199-step=20000.ckpt \
4 --img-size 768 768 \
5 --ruler-mode optimize \
6 --image-path <image-or-directory> \
7 --result-dir <output-directory> --gp-solver-path <path-to-final_deepgp>/checkpoints/epoch=999-step=1200000.ckptpretrained_rulernet.zip:1python main.py \
2 --config configs/config_pretrain.yaml \
3 --data-dir <anyruler-data-dir> \
4 --checkpoint <path-to-pretrained_rulernet>/checkpoints/epoch=79-step=128240.ckptsdxl_inference.py;
they are not distributed as a separate archive.model.onnx is the CPU-ready export used by the interactive demo.
It expects a float32 tensor named input with shape (1, 3, 768, 768):
an RGB image scaled to [0, 1], resized while preserving aspect ratio, and
zero-padded to 768 × 768.pip install -U huggingface_hub onnxruntime numpy pillow1import numpy as np
2import onnxruntime as ort
3from huggingface_hub import hf_hub_download
4from PIL import Image
5
6model_path = hf_hub_download(repo_id="ymp5078/RulerNet", filename="model.onnx")
7session = ort.InferenceSession(model_path, providers=["CPUExecutionProvider"])
8
9def preprocess(image_path):
10 image = np.asarray(Image.open(image_path).convert("RGB"), dtype=np.float32) / 255.0
11 height, width = image.shape[:2]
12 scale = min(768 / width, 768 / height)
13 new_width, new_height = int(width * scale), int(height * scale)
14
15 resized = Image.fromarray((image * 255).astype(np.uint8)).resize((new_width, new_height))
16 canvas = np.zeros((768, 768, 3), dtype=np.float32)
17 top = (768 - new_height) // 2
18 left = (768 - new_width) // 2
19 canvas[top:top + new_height, left:left + new_width] = np.asarray(resized) / 255.0
20
21 return np.transpose(canvas, (2, 0, 1))[None].astype(np.float32), (scale, top, left)
22
23input_tensor, transform = preprocess("ruler.jpg")
24init_point, dist, ratio, direction, points_info = session.run(
25 None, {"input": input_tensor}
26)
27
28print("initial point:", init_point[0])
29print("base distance:", dist[0])
30print("geometric-progression ratio:", ratio[0])
31print("ruler direction:", direction[0])
32print("point count and bounds:", points_info[0])| Output | Meaning |
|---|---|
init_point | Predicted starting ruler-mark location in the 768 × 768 processed image |
dist | Base distance between generated marks |
ratio | Geometric-progression ratio between consecutive mark spacings |
direction | Unit direction vector along the ruler |
points_info | Number of generated points followed by [min_x, min_y, max_x, max_y] valid bounds |
(x, y) back to the original image, use (x - left) / scale and
(y - top) / scale, where scale, top, and left are returned by
preprocess.