workers / wine_inventory / src / pince_shelf / vision / onnx_batch.py¶
Path: workers/wine_inventory/src/pince_shelf/vision/onnx_batch.py
Lane: workers
Executable: yes
Purpose¶
Component: Bottle End Detection (Batch ONNX Inference) Lane: workers / wine_inventory / pince_shelf / vision
Purpose¶
Perform batch ONNX inference to detect bottle-end positions on rectified shelf images. This worker processes one or more shelf snapshots and generates structured detection results suitable for inventory reconciliation.
Architectural Role¶
This script belongs to the autonomous vision pipeline of wine_platform. It operates headless and is designed for execution on Raspberry Pi hardware using CPUExecutionProvider (no GPU required).
It is typically triggered by: - cron job - systemd timer/service - manual CLI execution for debugging
Processing Pipeline¶
- Load ONNX model (bottle-end detector).
- Load input shelf images (previously rectified/cropped).
- Preprocess images (resize, normalize, format for model).
- Run batch inference using onnxruntime.
- Post-process predictions (confidence filtering, bounding box mapping).
- Export structured detection results (JSON / debug artifacts).
- Optionally integrate with stock update logic.
Inputs¶
- Rectified shelf images (from crop/ROI pipeline)
- ONNX model file
- Configuration from:
- pince_shelf.ini
- shared environment variables
- Optional runtime CLI arguments
Outputs¶
- Detection results (structured data)
- Debug images (optional)
- Log output (stdout / systemd journal)
- Optional inventory update trigger
Configuration & Environment¶
Expected environment variables may include: - MODEL_PATH - SNAPSHOT_DIR - DEBUG flags - Execution provider configuration
ONNX Runtime Providers: - CPUExecutionProvider (default on Raspberry Pi)
Operational Constraints¶
- Must run headless (no GUI).
- Must tolerate missing GPU (fallback to CPU).
- Must handle corrupted or empty image batches gracefully.
- Should not crash entire worker lane on single-image failure.
Failure Modes¶
- ONNX model file missing or incompatible
- Invalid provider configuration
- Corrupted input images
- Empty detection results
- Filesystem write errors
- Insufficient memory on Raspberry Pi
Logging¶
Designed for journalctl / systemd logging. All critical failures should be explicit and traceable.
Performance Notes¶
- Batch processing preferred for efficiency.
- Model loading should occur once per execution.
- Large image sets may require memory monitoring on Pi.
Security Considerations¶
- No external network calls expected during inference.
- All model execution is local.
- Ensure model files are trusted and not user-supplied.
Authoritative Source¶
wine_platform/workers/wine_inventory This script is part of the automated cellar inventory vision system.
Entry points¶
__main__guard detected
Key symbols¶
Classes¶
YoloV8OnnxDetector
Functions¶
_match_circle_indices_to_boxes(boxes, circles, margin)_point_in_or_near_box(x, y, box, margin)blur_score(bgr)clamp_count_by_type(count, cell_type)count_bottles(image, minR, maxR, minDistCoeff, debug)detect_caps(gray, minR, maxR, minDistCoeff)detect_cell_type_from_black_bg(bgr)letterbox(img, new_shape, color)main()nms_xyxy(boxes_xyxy, scores, iou_thres)run(cfg)
Configuration & environment¶
- (no env vars detected by regex)
Dependencies (imports)¶
__future__csvcv2loggingnumpyonnxruntimepathlibpince_shelf.config.settingstime
Operational notes (fill in)¶
- Headless/interactive:
- Systemd unit (if any):
- Schedules/triggers:
- Debug artifacts:
- Failure modes: