Skip to content

earlyBirdy/sintrones-edge-ai-starter-kit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

116 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“¦ Sintrones Edge AI Starter Kit

Test Status

Edge AI Vision Inspection + Industrial IoT Sensor Gateway (Vehicle / Factory / City)

A production‑minded, open framework to build Edge AI systems that combine vision inspection, sensor telemetry, and industrial I/O on rugged hardware. It ships a Streamlit dashboard (19+ tabs), a SQLite backbone, Model Packs, Fleet, and a Benchmark Matrix to accelerate PoCs β†’ pilots β†’ deployments.


🀝 Sales + Technical Collaboration

  • πŸ› οΈ Support System Integrators and SMEs with demo‑ready tools
  • 🀝 Collaborate on R&D and Proof‑of‑Concepts
  • 🌏 Promote industrial AI adoption across Thailand & SEA markets

Use it as a base to build your own PoC, integrate with IIoT, or contribute modules β€” the repo helps you accelerate time‑to‑demo and validate value at the edge.


🧭 Positioning & Advantages (edge‑first)

  • Local‑first & offline‑tolerant: on‑device inference, logs, KPIs (privacy‑preserving).
  • Open & modular: Python + Streamlit with plugin API; no lock‑in.
  • Fast time‑to‑demo: pre‑wired 19‑tab dashboard (Traceability, Yield, Fleet, Benchmarks).
  • Lifecycle‑ready: Model Packs (versioned) + Fleet (devices, deployments, events).
  • Best runtime per device: Benchmark Matrix picks ONNX/OpenVINO/TensorRT by latency and accuracy.
  • From anomalies to rules: Triage + ROC/A‑B to promote to deterministic pass/fail.

πŸ†“ vs πŸ’Ό Commercial Version

Feature Open-Source Starter Kit Commercial Offering
Real-time AI Inference (YOLO, etc.) βœ… Yes βœ… Yes
Dashboard UI (Streamlit/Grafana) βœ… Yes βœ… Yes
OTA Agent βœ… Yes βœ… Enhanced
Health Monitoring βœ… CLI Tool βœ… Web Dashboard
AI Agent Automation (Recovery, Adapter) βœ… Yes βœ… Advanced
Odoo / Cloud / AWS Integration 🟑 Manual βœ… Plug-in Ready
Hardware Acceleration Support 🟑 Generic βœ… Tuned Drivers
Long-term Support + SLA ❌ βœ… Yes
Turnkey Packaging (VM/Image) ❌ βœ… Yes

πŸ“¦ Deployment Options

Mode Description
Standalone Fully offline, single‑box; dashboard & sensor integration
Edge-to-Cloud MQTT sync to MES/BI; CSV/Parquet export or other IoT platforms
Vehicle AI Add GPS/CANbus for on-road deployments
Containerized docker compose -f packaging/docker-compose.yml up --build

🎯 Use Cases

  • πŸ“¦ Smart Logistics – Detect vehicles or goods, monitor temperature/vibration
  • 🏭 Factory Automation – Visual inspection + machine health monitoring
  • πŸ™οΈ Smart Cities – Public space detection, traffic analytics, air quality

πŸ“š Additional Resources

  • πŸ“˜ Use Cases: Real-world Edge AI applications in factories, vehicles, and smart cities
  • 🀝 Contributing Guide: How to get involved and contribute to this project

βœ… Features

  • SQLite backbone for on‑device metadata (devices, deployments, inspections, benchmarks, events, lineage) β€” default DB path data/edgekit.db (some builds use data/edge.db; both are supported).
  • SQL‑backed tabs: πŸ“‡ Data Traceability, πŸ“ˆ Yield & Quality, πŸ›°οΈ Fleet.
  • Model Packs with validate/smoke‑test hooks + policies for staged/shadow/rollback.
  • Benchmark Matrix now schema‑agnostic (supports engine or model) and persists best runtime/size.
  • Triage Queue wired to local anomalies with save/load state.
  • New/verified modules per E2E probe: Anomaly Log Viewer, Inference Balance, Benchmark Panel, Fine‑Tuning, Multi‑Camera, Saliency/XAI, Health Check, Inspection Rules, Pipeline Builder, I/O Connectors, Governance policy, Few‑Shot Fine‑Tuning, Examples, MES Export.
  • ROC assist + A/B helpers for setting inspection thresholds
  • Gateway sidecar (stub) for MQTTβ†’MES/Cloud and CDC table for safe sync
  • Plugin API so integrators can add custom pre/post/rule steps
  • Dockerfile + docker‑compose and a CI scaffold.
  • Probe summary: 25 passed, 0 failed β€” see probes/e2e_check.py.
  • Vision AI Lifecycle Loop End-to-end data β†’ labeling β†’ retraining β†’ deployment cycle integrated into the dashboard.
  • Label Review Tab Review AI predictions, correct labels, and store feedback in SQLite with β€œLow Confidence Only” filtering.
  • Model Retraining Tab Export labeled datasets into versioned folders (/datasets/vX/) and trigger local retraining scripts.
  • Model Sync (OTA) Pull new model versions from a local Git repository and activate updated .onnx models.
  • SQLite Auto-Schema | Automatically initializes inspection_logs schema for tamper-evident traceability and inspection logging.
  • Modularized Dashboard Tabs | Each function encapsulated as a module (dashboard/*.py) for scalable UI extension.
  • Improved Inference Pipeline | Supports multi-camera input, live capture, preprocessing, and model benchmarking.
  • Industrial Integration Ready | Data can be exported to MES, SFC, or cloud dashboards (via MQTT / REST).
  • Camera Input & Preprocessing: Integrates USB/IP cameras and stream normalization.
  • Inference: Supports both ONNX and PyTorch models for flexible runtime benchmarking.
  • Postprocessing + SQLite Logging: Every prediction is timestamped and recorded in inspection_logs.
  • Label Review & Retraining: Enables closed-loop retraining with labeled data export and trigger automation.
  • Model Sync (OTA): Local Git pull and model activation for secure on-premises updates.

πŸ—ΊοΈ Dashboard Tabs

  1. 🏁 Quick Start β€” KPIs + latest inspections & events
  2. πŸ” Inference β€” recent inference rows (schema‑adaptive)
  3. πŸŽ₯ Live Camera Feed β€” lists endpoints from config/cameras.yaml
  4. πŸ“· Multi‑Cam Feeds β€” 3‑column camera grid
  5. πŸ“ Log Viewer β€” lookback filter; CSV/table; tail preview; download
  6. πŸ“Š Benchmark Matrix β€” best runtime/size persisted to DB
  7. πŸ“ˆ Yield & Quality β€” PASS/FAIL, Pareto, trend (SQL)
  8. πŸ“¦ Model Packs β€” versioned packs, hooks, policies
  9. πŸ›°οΈ Fleet β€” devices, deployments, events (SQL)
  10. βœ… Inspection Rules β€” thresholds & rule sets
  11. 🧱 Pipeline Builder β€” preβ†’modelβ†’postβ†’rulesβ†’outputs
  12. βš™οΈ I/O Connectors β€” files, MQTT/MES stubs
  13. 🧰 Triage Queue β€” anomalies β†’ labeling β†’ promote to rule
  14. πŸ” Governance β€” policy, export guardrails
  15. πŸ› οΈ Few‑Shot Fine‑Tuning β€” list examples & spec
  16. πŸ§ͺ Health Check β€” table existence/counts; filesystem checks
  17. πŸ“‚ Examples β€” downloadable artifacts
  18. πŸ“‡ Data Traceability β€” unit‑level lineage (SQL / compat view)
  19. πŸ“€ MES Export β€” mes_latest.csv export helper
  20. πŸ–οΈ Label Review β€” Review and correct AI predictions, save to SQLite
  21. πŸ” Model Retraining β€” Export reviewed data and trigger retraining scripts
  22. πŸ“‘ Model Sync (OTA) β€” Pull latest model from local Git repo and activate

The three SQL‑backed tabs read from data/edge.db. The Log Viewer is a simple stub; most analytics live in the SQL pages.


Dashboard Tabs SQL‑backed analytics Ops, lifecycle & dev Capture & monitoring

Tabs render fully when their inputs/resources exist (DB rows, config files, folders). Placeholders are shown otherwise.

🧱 Project Structure (consolidated)

Project Structure (consolidated)

sintrones-edge-ai-starter-kit/
β”‚
β”œβ”€β”€ app.py                        # Main Streamlit dashboard entry (tabs + dispatch)
β”‚
β”œβ”€β”€ core/                         # Core DB & schema helpers (WAL, SQLite interface)
β”‚   β”œβ”€β”€ schema.sql                # Base schema definition
β”‚   └── db_helper.py              # SQLite connection & commit utilities
β”‚
β”œβ”€β”€ dashboard/                    # 22 modular Streamlit tabs (each with def render())
β”‚   β”œβ”€β”€ label_tab.py              # Label Review
β”‚   β”œβ”€β”€ retrain_tab.py            # Model Retraining
β”‚   β”œβ”€β”€ model_sync_tab.py         # Model OTA Sync
β”‚   β”œβ”€β”€ benchmark_matrix.py       # run_matrix(), record_benchmark(), best_engine()
β”‚   β”œβ”€β”€ triage.py                 # build_queue_from_anomalies(), save_queue(), add_triage_item()
β”‚   └── ... (existing tabs)
β”‚
β”œβ”€β”€ db/                           # Local database components
β”‚   └── sqlite_utils.py           # Auto-create and handle inspection_logs schema
β”‚
β”œβ”€β”€ retrain/                      # Model retraining pipeline
β”‚   └── retrain.py                # Example retraining trigger (placeholder)
β”‚
β”œβ”€β”€ tools/                        # Development utilities
β”‚   └── patch_app_tabs.py         # Script to auto-patch new tabs into app.py
β”‚
β”œβ”€β”€ config/                       # Configuration files
β”‚   β”œβ”€β”€ app_config.yaml           # DB paths, model paths, labels, thresholds
β”‚   β”œβ”€β”€ cameras.yaml              # Camera & stream configuration
β”‚   β”œβ”€β”€ inspection_rules.yaml     # Rules for classification thresholds
β”‚   β”œβ”€β”€ connectors/               # I/O or MQTT connector definitions
β”‚   └── policy.yaml               # Policy and governance settings
β”‚
β”œβ”€β”€ rules/                        # Rule helpers for ROC, A/B, inspection logic
β”‚
β”œβ”€β”€ gateway/                      # MQTT / OPC-UA sidecar (edge telemetry stub)
β”‚
β”œβ”€β”€ pipelines/                    # Configurable AI / vision pipelines
β”‚
β”œβ”€β”€ quality/                      # Quality analysis modules
β”‚   └── triage.py                 # Queue builder & anomaly manager
β”‚
β”œβ”€β”€ models/                       # Active & fine-tuned models
β”‚   β”œβ”€β”€ model.onnx                # Active ONNX model (in use)
β”‚   β”œβ”€β”€ finetune/                 # Fine-tuned models
β”‚   β”œβ”€β”€ fewshot/                  # Few-shot learning artifacts
β”‚   └── packs/                    # Packaged model bundles
β”‚
β”œβ”€β”€ models_repo/                  # Local Git repo for OTA model sync (pull + activate)
β”‚
β”œβ”€β”€ datasets/                     # Auto-exported reviewed datasets (v1, v2, ...)
β”‚
β”œβ”€β”€ bench/                        # Benchmark tools and matrix records
β”‚   └── benchmark_matrix.py       # run_matrix(), record_benchmark(), best_engine()
β”‚
β”œβ”€β”€ xai_results/                  # Explainability (saliency maps, Grad-CAM outputs)
β”‚
β”œβ”€β”€ benchmarks/                   # Stored benchmark artifacts
β”‚
β”œβ”€β”€ examples/                     # Runnable examples (scripts / demo configs)
β”‚
β”œβ”€β”€ logs/                         # Inspection logs (JSONL, anomalies, events)
β”‚
└── data/
    └── edgekit.db                # Primary SQLite DB (or edge.db in older builds)

---

Install & Run (deterministic)
```bash
# Create a virtualenv and install deps
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt

# Initialize SQLite (idempotent)
python scripts/init_sqlite.py

# Launch dashboard
streamlit run app.py

End‑to‑End Dummy Data Use the E2E seeder & probe to populate SQLite and validate tab queries quickly:

python tools/e2e/generate_dummy_data.py   # seeds devices, inspections, benchmarks, events
python tools/e2e/e2e_probe.py            # prints samples for the same queries the tabs use

After seeding, Yield & Quality, Fleet, Data Traceability, Benchmark Matrix, Log Viewer will show data.


🎯 Edge AI Applications

  • Vision Inspection (Factory QA) β€” multi‑camera inference, anomaly triage, promote‑to‑rule, unit‑level traceability, yield dashboards.
  • Industrial IoT Sensor Gateway β€” MQTT/OPC‑UA/Modbus ingestion, PASS/FAIL triggers, PLC handshake, trend KPIs, export to BI.
  • Vehicle AI (Fleet / Transit / Logistics) β€” on‑device vision + CAN/GNSS, event publishing, OTA model updates.
  • Smart‑City Edge β€” edge vision + environmental sensors, privacy‑preserving analytics, intermittent‑connectivity friendly.

πŸ“Š Vision Inspection Workflow

  1. 🧱 Pipeline Builder β†’ define full flow in recipes/pipeline.yaml (pre β†’ model β†’ post β†’ rules β†’ outputs)
  2. πŸ“¦ Model Packs β†’ import / validate models, attach pipelines & benchmarks
  3. πŸ“Š Benchmark Matrix β†’ persist best runtime / accuracy / size metrics into model pack
  4. πŸ›°οΈ Fleet β†’ manage staged or shadow rollouts (policy-driven deployments)
  5. πŸ” Inference / πŸ“· Multi-Cam β†’ real-time capture, inference, and logging to SQLite
  6. πŸ“ Log Viewer / πŸ“‡ Data Traceability β†’ inspect historical results and correlate with unit-level metadata (serial, station, shift, vendor, model@version, outcome)
  7. 🧰 Triage Queue β†’ review anomalies, assign priorities, and label for retraining (Promote β†’ βœ… Rule)
  8. πŸ–οΈ Label Review β†’ refine AI predictions manually; save corrections to SQLite
  9. πŸ” Model Retraining β†’ export labeled data to /datasets/vX and trigger retrain script
  10. πŸ“‘ Model Sync (OTA) β†’ pull updated ONNX model from local Git repo and activate
  11. πŸ“ˆ Yield & Quality β†’ monitor yield %, DPPM, Pareto, and long-term drift trends; iterate continuously

πŸ“Š Vision Inspection Workflow

[ Camera Input ]
   ↓
[ Preprocessing ]
   ↓
[ Inference β†’ SQLite Logging ]
   ↓
[ Label Review (Human-in-the-loop) ]
   ↓
[ Export to /datasets/vX ]
   ↓
[ Retraining Trigger ]
   ↓
[ Local Git Pull + Model Sync ]
   ↓
[ Updated ONNX Model Deployment ]
   ↓
[ Continuous Yield & Trend Feedback ]

Adds human feedback and on-premise model evolution for adaptive inspection.


🧠 Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         Streamlit UI                             β”‚
β”‚   β”œβ”€β”€ Quick Start / Health / Examples                            β”‚
β”‚   β”œβ”€β”€ Inference / Multi-Camera / Benchmark                       β”‚
β”‚   β”œβ”€β”€ Label Review / Retraining / OTA Model Sync (NEW)           β”‚
β”‚   β”œβ”€β”€ Logs / Rules / Governance / Fleet                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚   Edge AI Pipeline       β”‚
        β”‚  (camera β†’ preprocess β†’  β”‚
        β”‚   infer β†’ log β†’ feedback)β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚   SQLite / Local Storage β”‚
        β”‚   (tamper-evident logs)  β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚   Retraining + OTA Sync  β”‚
        β”‚   (continuous learning)  β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ—„οΈ Data conventions

  • Events: logs/events.jsonl (one JSON per line; includes ts, unit_id, result, station_id, …)
  • Images: logs/anomalies|pass|fail|samples/*.jpg(.json) where sidecar JSON includes metadata (timestamp, unit_id, station_id, camera_id, model@ver, result, defect, score, label).

🧠 Vision AI Lifecycle Loop

Added support for a full closed-loop AI lifecycle directly inside the dashboard:

  • Review β†’ Label β†’ Export β†’ Retrain β†’ Deploy via OTA
  • Local SQLite-based feedback storage and automatic schema creation
  • Retraining integrated with versioned datasets under /datasets/vX/
  • Local OTA model synchronization via models_repo and model_sync_tab.py

Configuration (config/app_config.yaml)

db_path: db/inspection_logs.db
images_base_dir: data/images
labels: ["OK", "scratch", "missing_screw", "dent", "misalignment"]
confidence_threshold: 0.75
models_repo_path: models_repo
active_model_path: models/model.onnx

πŸ“¦ Model Pack schema (minimum)

model_packs/<name>/<version>/modelpack.yaml

model_id: defect-detector
version: 1.2.0
artifacts:
  onnx: artifacts/model.onnx
runtime:
  preferred: onnxruntime
benchmarks:
  "2025-09-12":
    onnxruntime: {fps: 30.0, latency_ms: 33.0, size: "640"}
pipeline: recipes/pipeline.yaml
metrics: {f1: 0.82}
train: {data_commit: 25c1f3...}  # if using DVC/Git-LFS

🧰 Tooling & Utilities

  • e2e_bootstrap_pipeline_v31.py β€” deterministic seeding for demos
  • tab_health_probe.py β€” prints readiness of tables/folders for each tab
  • fix_streamlit_width_api.py β€” repo‑wide Streamlit width migration
  • apply_ui_tweaks_env_footer.py β€” remove/move the β€œEnvironment” panel
  • compat_views.sql β€” safe views powering Inference & Traceability

πŸ§ͺ Testing & CI

pytest tests/
  • Agents, OTA model switch, loggers, schema adapters.
  • GitHub Actions scaffolded in .github/workflows/*.

πŸ“š Additional Resources

  • docs/USE_CASES.md β€” real‑world factory/vehicle/city use cases
  • docs/CONTRIBUTING.md β€” contribution workflow
  • docs/LEGACY_MIGRATION.md β€” old β†’ new paths & commands

πŸ“’ Community & Contact


πŸ“„ License

MIT β€” suitable for research, pilots, and production starters.

About

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published