LogicDrawer YOLO26s gate detector
Detects hand-drawn and printed logic gate symbols in circuit drawings. Seven classes: AND, NAND, NOR, NOT, OR, XNOR, XOR. Trained from random initialization with Ultralytics YOLO26s.
| Architecture | YOLO26s, no NMS, direct box regression |
| Parameters / FLOPs | 9.95 M / 22.8 GFLOPs at 640 (fused: 9.47 M / 20.8) |
| Input | 640 px, grayscale content (3-channel) |
| Checkpoint | logicdrawer_yolo26s.pt, logicdrawer_yolo26s.onnx (opset 18, input 1x3x640x640, output 1x300x6) |
| Training | 235 epochs (best at 135, early stop), 1.26 h on an RTX 4050 Laptop 6 GB |
| Inference | 6.8 ms / image at batch 16 fp16 on the RTX 4050 |
Usage
pip install "ultralytics>=8.4.146" huggingface_hub
from huggingface_hub import hf_hub_download
from ultralytics import YOLO
from PIL import Image, ImageOps
weights = hf_hub_download("KaanAydinli/logicdrawer-yolo26s", "logicdrawer_yolo26s.pt")
model = YOLO(weights)
im = ImageOps.exif_transpose(Image.open("circuit.jpg")).convert("L").convert("RGB")
result = model.predict(im, imgsz=640, conf=0.25)[0]
for box in result.boxes:
print(model.names[int(box.cls)], round(float(box.conf), 3), box.xyxy[0].tolist())
result.save("circuit_pred.jpg")
The training data was converted to grayscale, so convert inputs to grayscale before inference as shown. The .pt needs an ultralytics version that supports YOLO26 (8.4.x). To fetch the files without Python: hf download KaanAydinli/logicdrawer-yolo26s --local-dir logicdrawer-yolo26s.
ONNX
logicdrawer_yolo26s.onnx returns final detections, no NMS needed.
- Input
images: float32[1, 3, 640, 640], RGB, values 0 to 1, image letterboxed to 640x640 with aspect ratio preserved and gray (114) padding. - Output
output0: float32[1, 300, 6], rows ofx1, y1, x2, y2, confidence, class_idin letterboxed pixel coordinates, sorted by confidence. Keep rows above your confidence threshold, subtract the padding offsets and divide by the resize scale to map boxes back to the original image.
import numpy as np, onnxruntime as ort, cv2
from huggingface_hub import hf_hub_download
from PIL import Image, ImageOps
im = np.array(ImageOps.exif_transpose(Image.open("circuit.jpg")).convert("L").convert("RGB"))
h, w = im.shape[:2]
r = 640 / max(h, w)
nh, nw = round(h * r), round(w * r)
canvas = np.full((640, 640, 3), 114, np.uint8)
top, left = (640 - nh) // 2, (640 - nw) // 2
canvas[top:top + nh, left:left + nw] = cv2.resize(im, (nw, nh))
x = canvas.transpose(2, 0, 1)[None].astype(np.float32) / 255.0
onnx_path = hf_hub_download("KaanAydinli/logicdrawer-yolo26s", "logicdrawer_yolo26s.onnx")
session = ort.InferenceSession(onnx_path)
det = session.run(None, {"images": x})[0][0]
names = ["AND", "NAND", "NOR", "NOT", "OR", "XNOR", "XOR"]
for x1, y1, x2, y2, conf, cls in det[det[:, 4] > 0.25]:
box = [(x1 - left) / r, (y1 - top) / r, (x2 - left) / r, (y2 - top) / r]
print(names[int(cls)], round(float(conf), 3), [round(float(v), 1) for v in box])
Data
1,495 grayscale images of logic gate drawings, longest side 640 px, split 1,047 / 224 / 224 (train / valid / test) with 16,868 boxes. The set mixes phone photos of hand-drawn circuits with scanned and rendered schematics; hand-drawn photos are about 8 % of the training images. Per-class, per-source and box-size statistics are in dataset_stats.json.
Training recipe
yolo26s.yaml, pretrained=False, imgsz 640, batch 16, 400 epochs planned with early-stop patience 100, AMP fp16, seed 0, deterministic. Optimizer MuSGD (Muon for conv and matrix weights, Nesterov SGD for the rest), lr0 0.01 with linear decay, momentum 0.9, weight decay 5e-4, warmup 3 epochs. Loss gains box 7.5, cls 0.5, dfl 1.5.
Augmentation: mosaic 1.0, scale ±0.5, translate 0.1, rotation ±5°, horizontal flip 0.5, brightness (hsv_v) 0.4, hue and saturation 0 (grayscale input), no mixup / cutmix / copy-paste. Every setting used is in training_args.yaml.
Training stopped at epoch 235 because validation fitness had not improved for 100 epochs; the best checkpoint is from epoch 135. mAP50 passed 0.95 by epoch 15.
Results
Metrics from best.pt at 640 px. Validation and test splits have the same source mix as train.
| Split | Images | Boxes | Precision | Recall | mAP50 | mAP75 | mAP50-95 |
|---|---|---|---|---|---|---|---|
| valid | 224 | 2,954 | 0.952 | 0.980 | 0.990 | 0.842 | 0.699 |
| test | 224 | 2,723 | 0.915 | 0.960 | 0.961 | 0.785 | 0.659 |
Per-class test AP:
| Class | AP50 | AP50-95 | Class | AP50 | AP50-95 | |
|---|---|---|---|---|---|---|
| AND | 0.975 | 0.716 | OR | 0.964 | 0.627 | |
| NAND | 0.963 | 0.660 | XNOR | 0.930 | 0.661 | |
| NOR | 0.972 | 0.621 | XOR | 0.976 | 0.666 | |
| NOT | 0.949 | 0.663 |
Test split by image type:
| Image type | Images | mAP50 | mAP50-95 |
|---|---|---|---|
| hand-drawn photos | 41 | 0.933 | 0.667 |
| printed or rendered schematics | 183 | 0.961 | 0.659 |
Errors are mostly missed gates in dense scans and background false positives.

Sample predictions
Figure 1

Figure 2

Limitations
- Hand-drawn photos are a small part of the data and the test photos come from few drawing sessions, so the hand-drawn numbers are optimistic. On messy drawings the model confuses bubbled and non-bubbled variants (AND vs NAND, OR vs NOR) and confidences drop to 0.3 to 0.7.
- Box tightness (mAP50-95 about 0.66) is limited by the many ~30 px gates and by inconsistent box padding between annotation sources.
- Inputs are expected in grayscale; colour drawings should be converted first.
- Gates drawn right-to-left or bottom-to-top are rare in the data; horizontal flip augmentation was used, vertical flip was not.
- Detects gate symbols only. Wires, junctions, inputs and outputs are not modelled.
Files
logicdrawer_yolo26s.pt,logicdrawer_yolo26s.onnx: weights.training_args.yaml: every Ultralytics training argument used.metadata.json: environment, model, training curve, valid / test / per-source metrics, confusion matrices, speed.dataset_stats.json: split, class, box-size and source-group statistics.figures/: training curves, PR curves, confusion matrix, label distribution, two sample photos with their annotated predictions.
Environment
Python 3.12.3, torch 2.11.0+cu128, ultralytics 8.4.146, NVIDIA GeForce RTX 4050 Laptop GPU (6 GB), Intel i7-13700H.
License and attribution
Model weights are released under AGPL-3.0, following the Ultralytics license. Trained by KaanAydinli for the LogicDrawer project.