warmup_v2.onnx)Detects the end of every board in a photo of a lumber bundle's end face, so the boards can be counted.
It is the detector behind GNL Vision: Wood Counter (GitHub: GNL-System/gnl-vision),
and replaces v1 (endface_v1.onnx).
| Architecture | Ultralytics YOLO11s, detection head (exported with Ultralytics 8.4.215) |
| Classes | 1: 0 = board_end |
| Format | ONNX, static shape |
| Input | images: float32 [1, 3, 640, 640], RGB, values 0–1, letterboxed with grey (114) padding |
| Output | output0: float32 [1, 5, 8400] = cx, cy, w, h, score per anchor, in 640 px input space, no NMS |
| File size | 37.9 MB (37,928,300 bytes) |
| SHA-256 | 37a0a7ff35480a34f960ab9ed4bd31974a6f0c63638739a56cb8fdce0ff19ead |
Same architecture and public photos as v1, but trained to hold up in yard conditions:
7 bundles from our yard, 4,408 boards, each counted by hand. Not one of them was used in training.
| How the boxes are counted | Boards wrong (total) | Bundles exact |
|---|---|---|
| Count the boxes this model finds | 250 | 0 / 7 |
| Wood Counter app: grid count (rows × columns per pile, rows from the photo when boards have gaps) | 5 | 6 / 7 |
| v1 model with the app's grid count | 25 | 4 / 7 |
The detector alone is within about 2 % on most bundles. It over-detects thin, uneven boards with gaps between them (one bundle: 699 boxes for 564 boards). The app's grid count corrects most of that, and the app flags such bundles yellow for a look.
The app does everything around the model: framing, resizing, tiling, merging, the grid count, checks and the confidence colour.
# from the gnl-vision repository root
pip install huggingface_hub
hf download Hieule1/YOLO11_WoodCounterV2 warmup_v2.onnx --local-dir models
cd backend
$env:WOOD_ENDFACE_MODEL = "$PWD\..\models\warmup_v2.onnx"
.venv\Scripts\python -m uvicorn app.main:app --port 8000
Check it loaded: GET http://localhost:8000/api/health should show "end_model": {"name": "warmup_v2.onnx", "stub": false}.
Backend settings that matter for this model:
| Variable | Value | Why |
|---|---|---|
WOOD_ENDFACE_MODEL |
path to warmup_v2.onnx |
the model to load |
WOOD_CONF |
0.25 (default) |
the confidence threshold the results above were measured with |
WOOD_BOARD_PX |
40 (default) |
the board size, √(w·h) in px, the model was trained at; photos are resized to it |
WOOD_COUNT_METHOD |
lines (default) |
the grid count; columns is the older column count |
The model was trained on 640 px tiles in which a typical board end is about 40 px across (√(w·h)). Counting a bundle photo therefore needs these steps:
output0: transpose to [8400, 5], keep score ≥ 0.25, convert cx, cy, w, h to corners, map back.A complete example (needs pip install onnxruntime opencv-python-headless numpy huggingface_hub):
"""Count board ends in a bundle photo: python count.py photo.jpg x1,y1,x2,y2 (the bundle's frame in pixels)."""
import sys
import cv2
import numpy as np
import onnxruntime as ort
from huggingface_hub import hf_hub_download
TILE, OVERLAP, CONF, TARGET_BOARD_PX = 640, 0.2, 0.25, 40.0
path = hf_hub_download("Hieule1/YOLO11_WoodCounterV2", "warmup_v2.onnx")
session = ort.InferenceSession(path, providers=["CPUExecutionProvider"])
def detect_tile(tile):
"""Boxes [x1, y1, x2, y2, score] in tile pixels for one image up to 640 x 640."""
h, w = tile.shape[:2]
scale = TILE / max(h, w)
resized = cv2.resize(tile, (round(w * scale), round(h * scale)))
canvas = np.full((TILE, TILE, 3), 114, np.uint8) # letterbox with grey padding
canvas[:resized.shape[0], :resized.shape[1]] = resized
blob = cv2.cvtColor(canvas, cv2.COLOR_BGR2RGB).transpose(2, 0, 1)[None].astype(np.float32) / 255.0
preds = session.run(None, {"images": blob})[0][0].T # [8400, 5]: cx, cy, w, h, score
preds = preds[preds[:, 4] >= CONF]
cx, cy, bw, bh, score = preds.T
return np.stack([(cx - bw / 2) / scale, (cy - bh / 2) / scale, (cx + bw / 2) / scale, (cy + bh / 2) / scale, score], 1)
def detect(image):
"""Tiles with overlap over the whole image, merged."""
h, w = image.shape[:2]
step = int(TILE * (1 - OVERLAP))
boxes = []
for y in range(0, max(h - TILE, 0) + step, step):
for x in range(0, max(w - TILE, 0) + step, step):
found = detect_tile(image[y:y + TILE, x:x + TILE])
boxes.append(found + [x, y, x, y, 0])
return merge(np.concatenate(boxes) if boxes else np.zeros((0, 5)))
def merge(boxes, iou_thr=0.5, contain_thr=0.6):
"""Greedy NMS, biggest boxes first, that also drops a box lying mostly inside a kept one (a board cut at a
tile edge is detected twice: whole in one tile, as a fragment in the next)."""
area = (boxes[:, 2] - boxes[:, 0]) * (boxes[:, 3] - boxes[:, 1])
kept = []
for i in np.lexsort((-boxes[:, 4], -area)):
if kept:
k = np.array(kept)
iw = np.clip(np.minimum(boxes[k, 2], boxes[i, 2]) - np.maximum(boxes[k, 0], boxes[i, 0]), 0, None)
ih = np.clip(np.minimum(boxes[k, 3], boxes[i, 3]) - np.maximum(boxes[k, 1], boxes[i, 1]), 0, None)
inter = iw * ih
if (inter / (area[k] + area[i] - inter) > iou_thr).any() or (inter / area[i] > contain_thr).any():
continue
kept.append(i)
return boxes[kept]
photo = cv2.imread(sys.argv[1])
x1, y1, x2, y2 = map(int, sys.argv[2].split(",")) # the bundle's frame in photo pixels
crop = photo[y1:y2, x1:x2]
# 1. probe: measure the typical board, 2. resize so it is ~40 px, 3. detect again
probe_scale = 1280 / max(crop.shape[:2])
probe = detect(cv2.resize(crop, None, fx=probe_scale, fy=probe_scale))
board = np.median(np.sqrt((probe[:, 2] - probe[:, 0]) * (probe[:, 3] - probe[:, 1]))) / probe_scale
scale = min(TARGET_BOARD_PX / board, 3.0)
boxes = detect(cv2.resize(crop, None, fx=scale, fy=scale))
print(f"typical board {board:.0f} px, resized x{scale:.2f}: {len(boxes)} board ends")
On three of the hand-counted factory bundles this script finds 732 board ends for 720 boards, 609 for 600 and
470 for 484. That's the box count, before the app's grid count turns those into exact counts.
The app's reference implementation is backend/app/inference.py, framing.py and scanlines.py in the GitHub repo.
Public photos only (the "warm-up" stage): 804 web photos with about 61,000 labelled board ends, merged and
de-duplicated from two Roboflow datasets (credits below), plus one failure-mode copy for half of them.
Training: 640 px tiles, up to 60 epochs (early stopping) from COCO pre-trained yolo11s.pt.
It has not been trained on photos from our own yard yet. The next versions are fine-tuned on bundles counted in the app; workers' hand counts are kept as the locked test set.
03_evaluate)
before relying on the counts.