Smith-Pincette-Drawings v0.1
Part of the Smith-Pincette Model Family. Three compact models that read mechanical engineering drawings: they find the callouts on a sheet (dimensions, hole and thread callouts, GD&T frames, surface symbols, title blocks, tables, ...), transcribe them, and link them to each other. This is a preview release: expect rough edges, and expect the models and files to change.
| Model | Job | Built on | Parameters | Format |
|---|---|---|---|---|
Smith-Pincette-Drawings-Scope (scope/) |
finds 23 callout and region classes on a sheet, their orientation, and the part type | PekingU/rtdetr_v2_r50vd |
43.1M | ONNX |
Smith-Pincette-Drawings-Lens (lens/) |
reads an upright callout crop as text; reads title blocks and tables as JSON | zai-org/GLM-OCR + LoRA adapter |
27.3M (adapter) | PEFT adapter |
Smith-Pincette-Drawings-Prism (prism/) |
classifies pairs of found callouts into relations | trained from scratch | 0.8M | ONNX |
| Version | v0.1 |
| Input | rendered drawing sheets (PDF/PNG/scan); large sheets are tiled |
| Output | boxes with class, score and orientation; text per callout; JSON per title block and table; relations between callouts |
| Runs | Scope and Prism with onnxruntime on CPU or GPU; Lens with PyTorch + transformers + peft |
| License | Apache-2.0 |
Quickstart
pip install onnxruntime numpy pillow huggingface_hub
Find callouts on one sheet with Scope (sheets up to ~2200 px on the long side; larger sheets give better results tiled,
see scope/config.json):
import json
import numpy as np
import onnxruntime as ort
from PIL import Image
from huggingface_hub import snapshot_download
repo = snapshot_download("Holocortex/Smith-Pincette-Drawings", revision="v0.1", allow_patterns=["scope/*"])
cfg = json.load(open(f"{repo}/scope/config.json"))
ort.set_default_logger_severity(3) # hides harmless constant-folding notices while the graph loads
session = ort.InferenceSession(f"{repo}/scope/model.onnx", providers=["CPUExecutionProvider"])
sheet = Image.open("drawing.png").convert("RGB")
size = cfg["image_size"]
x = np.asarray(sheet.resize((size, size), Image.Resampling.BILINEAR), np.float32) / 255.0
logits, boxes, orientation, part_type = session.run(None, {"pixel_values": x.transpose(2, 0, 1)[None]})
scores = 1 / (1 + np.exp(-logits[0]))
for q in np.nonzero(scores.max(-1) >= cfg["score_threshold"])[0]:
cx, cy, w, h = boxes[0, q] * [sheet.width, sheet.height, sheet.width, sheet.height]
code = cfg["labels"][scores[q].argmax()]
print(code, cfg["label_names"][code], f"{scores[q].max():.2f}",
[round(cx - w / 2), round(cy - h / 2), round(cx + w / 2), round(cy + h / 2)],
cfg["orientations"][orientation[0, q].argmax()])
print("part type:", cfg["part_types"][part_type[0].argmax()])
Read a callout crop with Lens (needs pip install torch transformers peft; the GLM-OCR base downloads on first use):
import json
import torch
from huggingface_hub import snapshot_download
from peft import PeftModel
from PIL import Image
from transformers import AutoModelForImageTextToText, AutoProcessor
repo = snapshot_download("Holocortex/Smith-Pincette-Drawings", revision="v0.1", allow_patterns=["lens/*"])
cfg = json.load(open(f"{repo}/lens/lens_config.json"))
processor = AutoProcessor.from_pretrained(cfg["base_model"])
base = AutoModelForImageTextToText.from_pretrained(cfg["base_model"], dtype=torch.bfloat16)
model = PeftModel.from_pretrained(base, f"{repo}/lens").eval()
crop = Image.open("callout.png").convert("RGB") # one upright callout, as cut out by Scope
messages = [{"role": "user", "content": [{"type": "image", "image": crop}, {"type": "text", "text": cfg["prompts"]["callout"]}]}]
text = processor.apply_chat_template(messages, add_generation_prompt=True, tokenize=False, enable_thinking=False)
inputs = processor(text=[text], images=[crop], return_tensors="pt")
with torch.inference_mode():
out = model.generate(**inputs, max_new_tokens=96, do_sample=False)
print(processor.tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
# JSON with the class code and the text, e.g. "class": "C02", "raw_text": "ร45 ยฑ0.2 THRU"
Use the title_block and table prompts in lens_config.json for title-block and table regions (R01, R03).
The full pipeline (tiling, box fusion, crop straightening, Prism relations, reading with Lens) is in the Smith-Pincette-Models package (v0.55.4 or newer):
pip install "smith-pincette[drawings] @ git+https://github.com/holocortex/Smith-Pincette-Models"
from smith_pincette import SmithPincetteDrawings
model = SmithPincetteDrawings.from_pretrained("Holocortex/Smith-Pincette-Drawings", revision="v0.1")
result = model.analyze("drawing.png") # entities with class, box, text; relations between them; part type
Without PyTorch, from_pretrained(..., read=False) finds callouts and relations only. Prism's inputs (pair crops and 16
geometry values) are computed by the package.
Classes
| Group | Classes |
|---|---|
| Callouts | C01 dimension, C02 hole or thread callout, C03 chamfer or undercut, C04 GD&T feature control frame, C05 datum feature symbol, C06 datum target, C07 surface roughness symbol, C08 welding symbol, C09 inspection marker, C10 note item, C11 hardness or heat treatment, C12 stiffness or mechanical spec |
| Regions | R01 title block, R02 revision table, R03 table, R04 notes block, R05 drawing view |
| Features | F01 drawn hole or cutout, F02 bend line, F03 thread representation, F04 symmetry or center axis, F05 section or detail indicator, F06 process geometry marker |
Scope also predicts the text orientation of each box (horizontal, vertical, slanted) and the part type of the
whole sheet (12 types, listed in scope/config.json). Prism relations: MODIFIES, APPLIES_TO,
SAME_FEATURE_ACROSS_VIEWS (or NONE).
Intended use and limitations
- Intended for extracting callouts from mechanical drawings you are allowed to process: quoting, inspection planning, archive search.
- Finding callouts on real drawings is the weak point of this preview. Scope works much better on generated sheets than on real ones. Reading a callout that has been found works better than finding it.
- Prism has been tested on synthetic sheets only.
- Lens reads a crop; it does not check that the value is valid. Check critical values (tolerances, fits, threads) before using them for manufacturing or inspection.
- For native CAD files (DXF, DWG) and vector PDFs, reading the text and geometry directly from the file is more exact than these models.
- Best covered: ISO and ASME drawing conventions, English and German text.
Training data
- Generated drawings (most of the data): synthetic sheets rendered with ezdxf and FreeCAD TechDraw from generated parts and public STEP models, with labels from the generators.
- Cadsy sheets (Apache-2.0), apart from the held-out test parts.
- CAD drawings from GitHub repositories under permissive licenses (MIT, Apache-2.0, BSD, ISC, CC0).
- Real drawings from the public web: publicly accessible drawing PDFs, collected while respecting robots.txt and used for text and data mining. Their callouts were labeled automatically where two open-weight vision-language models agreed.
Files
| File | Content |
|---|---|
scope/model.onnx |
Scope (runs with onnxruntime, no PyTorch needed) |
scope/config.json |
classes, input format, thresholds, tiling settings |
lens/adapter_model.safetensors, lens/adapter_config.json |
Lens LoRA adapter for zai-org/GLM-OCR |
lens/lens_config.json |
prompts and generation settings |
lens/tokenizer.json, lens/tokenizer_config.json, lens/processor_config.json, lens/chat_template.jinja |
tokenizer and processor settings used in training |
prism/model.onnx |
Prism |
prism/config.json |
relation labels, pair inputs, threshold |
Support
Provided as is, without support or warranty.
License
Apache-2.0. Scope builds on PekingU/rtdetr_v2_r50vd (Apache-2.0); Lens is an adapter for zai-org/GLM-OCR
(MIT), which is downloaded from its own repository under its own license.
Model tree for Holocortex/Smith-Pincette-Drawings
Base model
PekingU/rtdetr_v2_r50vd