Skip to content

Application Size Optimization (Modular AI Model Management) #1260

@rohan-pandeyy

Description

@rohan-pandeyy

Eliminate bundled ONNX models (~348 MB) from the installer. Replace with a post-install download system that is hardware-aware, integrity-verified, and user-controllable.

An in-depth explanation of each of these implementations can be found here


Pre-implementation

  • Upload all non-Ultralytics ONNX models to models-v1.0 GitHub Release tag
  • Compute and record SHA-256 checksum for each uploaded file

Computed SHA-256:

FILE SHA-256 SUM
FaceNet_128D.onnx c37946ea8cce94141777dcbcccb8a61786c9a7c4f0c9f40471bd27029fa664ed
YOLOv11_Medium.onnx f53a0bf6a141788f329ab92b438045f0ebac73ff10285b9ef0d06551cdbd01ea
YOLOv11_Medium_Face.onnx fd3ab085d776ee1ce59fd47def82c2abf49bbfde3a10a1b5b660b76cb41a6912
YOLOv11_Nano.onnx 634279b40c07c6391472c51ad45b81ebc48706a9a1fe72dd3396322acd0c053b (as mentioned in Ultralytics v8.3.0 release assets
YOLOv11_Nano_Face.onnx 1d09cb0f31d46700a3e80838623aeafa125f2cd0d1c9a12f0b0853bf64b0a83d
YOLOv11_Small.onnx 8bfa953dbe93bef33b09be00da01cb4727f25416cb5d2fdb2a9f1083283b8aaa
YOLOv11_Small_Face.onnx 213333bbecd049c8e1d8bc63b4799df08d2ec52c8f8a6737b37b75ba839d7c03

Backend Foundation

  • Remove APScheduler from requirements.txt; add psutil and httpx
  • app/models/model_registry.py: ModelSpec TypedDict + MODEL_REGISTRY dict
  • app/models/model_registry.json: committed registry export for offline bundling
  • app/utils/model_downloader.py: ensure_model() with streaming download, SHA-256 verification, and retry (with Range-header resumability).
  • YOLO.py: replace eager InferenceSession in __init__ with lazy get_session()
  • FaceNet.py: same lazy pattern; on-demand only, not included in first-run tier download

Backend API

  • app/utils/hardware_detect.py: detect_hardware_tier() using psutil + ort.get_device()
  • app/routes/models.py: models_router with:
    • GET /models/status
    • GET /models/recommended-tier
    • POST /models/download/{model_key}: returns task_id
    • GET /models/download/{task_id}/progress: SSE stream
    • DELETE /models/{model_key}
    • POST /models/setup: accepts tier, triggers download of that tier's two YOLO models
  • Register models_router in main.py

Build and CI

  • backend/PictoPy.spec: excludes ONNX_Exports/, bundles model_registry.json
  • build-and-release.yml: swap inline pyinstaller command for spec file; remove robocopy/cp model-copy steps
  • Verify local build: ONNX_Exports/ absent, model_registry.json present at correct path
  • (Optional) Configure CI matrix to output a "nano-bundled" offline installer variant

Frontend

  • First-run tier selector modal: reads recommended tier, streams SSE progress, dismisses on verified download
  • Model manager panel in settings: per-model download/delete with real-time progress bar
  • Delete guard: warn if active tier's model is being removed

Metadata

Metadata

Assignees

No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions