How sonikdas745-ctrl/vision_based_inventory_management works
1. What this repo actually is
This is a multi-layer smart inventory system, not a single app. The main production path is: camera/video input → YOLOv8 detection/inventory counting → backend/API stream → Next.js dashboard. Around that are ROS2 nodes for edge hardware deployment and a separate training/export toolchain for producing deployable models.
2. Primary runtime boundaries
There are three real subsystems to diagram:
- Python ML/backend layer in src/
- ROS2 edge/hardware layer in ros2_inventory/
- Next.js dashboard layer in frontend/
The nested Vision_Based_Inventory_Management/ folder looks like a parallel snapshot of the ML stack and model artifacts, so it should be treated as a training/packaging workspace rather than a separate service.
3. Computer vision core
The detection engine is YOLOv8-based. The core model assets live under models/ and runs/detect/models/, with multiple trained variants such as rpc_real_labels, rpc_with_names, and emergency_fast. The Python scripts in src/ and Vision_Based_Inventory_Management/src/ handle inference, preprocessing, training, and export.
4. Training and model lifecycle
The ML pipeline runs from dataset config to training artifacts:
- config/dataset.yaml defines dataset metadata
- src/preprocess.py, src/full_preprocess.py, src/train.py, src/full_train.py prepare and train models
- src/export_model.py produces deployment formats like TFLite, ONNX, OpenVINO, TensorRT
- runs/detect/models/* stores training outputs, weights, and results
This means the model lifecycle is a first-class part of the repo, not an external dependency.
5. Edge/robotics layer
The ROS2 package ros2_inventory is the hardware-facing boundary. It contains:
- camera_node.py for capture
- detection_node.py / new_detection_node.py for inference
- inventory_node.py for inventory state/count aggregation
- api_bridge_node.py to connect ROS2 data to the backend/API world
- pan_tilt_controller.py for hardware actuation
Custom messages (Detection.msg, DetectionArray.msg, InventoryCount.msg) define the data contract between nodes.
6. ROS2 data flow
The ROS2 launch file (launch/inventory_system.launch.py) ties the nodes together. The intended flow is:
camera input on /camera/image_raw → detection results on /detections and annotated frames → inventory aggregation on /inventory_status → optional bridge out to API/backend. This is the edge compute path for Raspberry Pi / Ubuntu deployments.
7. Backend/API boundary
The backend entry point is src/api.py plus supporting modules like src/inference.py, src/utils.py, src/continual_learning.py, and src/create_class.py. It exposes:
- REST endpoints for health, detection, inventory counts/history, model info/switching, export
- WebSocket endpoints for live video and inventory updates
This layer is the integration point between ML inference and clients, and likely owns transient state such as current counts and history snapshots.
8. Dashboard boundary
The frontend is a Next.js app using the App Router (frontend/app/). It is organized as a dashboard with components for:
- live video streams (video-stream.tsx, ROSVideoStream.tsx, detection-overlay.tsx)
- inventory analytics (inventory-dashboard.tsx, stats-cards.tsx, realtime-chart.tsx, shelf-heatmap.tsx)
- operational views (detections-table.tsx, activity-log.tsx, system-info.tsx, control-panel.tsx)
The presence of frontend/app/api/inventory/* route handlers and frontend/lib/api-client.ts suggests the UI talks to the backend through a thin client/BFF layer rather than embedding business logic in components.
9. Frontend live-data path
The dashboard is built around streaming, not just polling. Hooks like use-inventory-stream.ts and components like ROSVideoStream.tsx indicate the UI subscribes to real-time inventory/video updates, which map cleanly to the backend WebSocket layer. There is also mock-data.ts, so some views can operate without live services during development.
10. Configuration and deployment surfaces
Configuration is split by layer:
- .env.example / frontend/.env.example for frontend API URLs
- ros2_inventory/config/params.yaml for camera/model/device parameters
- config/dataset.yaml for dataset setup
The repo also contains many deployment guides (DEPLOYMENT*.md, HARDWARE_CONNECTIONS.md, UBUNTU_SETUP.md, etc.), which reinforces that the system is designed for edge deployment, not just local inference.
11. What to treat as secondary
gui.py and several *_backup / duplicate folders are legacy or alternate packaging paths. They matter for completeness, but the architectural diagram should center on the three active planes: ML/backend, ROS2 edge, and Next.js dashboard.
12. Big-picture system diagram
If you draw this repo accurately, the key arrows are:
- camera/sensor hardware into ROS2
- ROS2 detection/inventory into backend/API
- backend streams and REST data into the dashboard
- training/configuration pipelines feeding model artifacts used by both Python inference and ROS2 deployment
The main design idea is a computer-vision pipeline split across edge execution, service/API integration, and a browser-based monitoring/control UI.
Main entry points: inventory_system.launch.py System launch · api.py API server · camera_node.py Camera node · models Trained models
Components 21
Python ML/backend
Inference, API, training, and export workflows in the Python stack.
- API server · Main backend entry point for REST, WebSocket, and inventory state APIs.
src/api.py - Inference core · Shared detection/runtime logic used by the backend and edge flows.
src/inference.py - Training pipeline · Preprocessing and training scripts for building new detector models.
src/train.py - Model export · Exports trained models into deployment formats for edge/runtime use.
src/export_model.py - ML support · Utility, continual learning, and class-management code around the backend ML stack.
src/utils.py - Dataset config · Dataset metadata and class configuration used by training and preprocessing.
config/dataset.yaml
ROS2 edge layer
Camera, detection, inventory aggregation, and hardware control on the edge device.
- Camera input · Video and image input entering the system from connected cameras or sensors.
- Camera node · Captures frames from the camera stream and publishes them into ROS2.
ros2_inventory/ros2_inventory/camera_node.py - Detection node · Runs model inference on incoming frames and publishes detections.
ros2_inventory/ros2_inventory/detection_node.py - Alt detector · Alternative detection implementation for edge inference.
ros2_inventory/ros2_inventory/new_detection_node.py - Inventory node · Aggregates detections into inventory counts and current stock state.
ros2_inventory/ros2_inventory/inventory_node.py - API bridge · Bridges ROS2 data out toward backend/API consumers.
ros2_inventory/ros2_inventory/api_bridge_node.py - Pan-tilt · Controls camera movement hardware for tracking and positioning.
ros2_inventory/ros2_inventory/pan_tilt_controller.py - ROS messages · Detection and inventory message definitions shared between ROS2 nodes.
ros2_inventory/msg/Detection.msg - System launch · Launches the edge node graph and binds the runtime together.
ros2_inventory/launch/inventory_system.launch.py
Next.js dashboard
Browser dashboard, live streams, and API-facing UI components.
- Dashboard app · App Router entry for the browser-based monitoring and control UI.
frontend/app/page.tsx - Live stream · Live video and overlay components for real-time camera/detection views.
frontend/components/ROSVideoStream.tsx - Inventory views · Charts, tables, and operational panels for inventory monitoring.
frontend/components/inventory-dashboard.tsx - API client · Thin client and hooks used by the dashboard to reach backend inventory APIs.
frontend/lib/api-client.ts
Model workspace
Parallel training and packaging workspace with trained weights and artifacts.
- Trained models · Stored YOLOv8 weights and run outputs used for deployment and experimentation.
runs/detect/models - Training workspace · Parallel ML workspace snapshot containing preprocessing, training, inference, and GUI scripts.
Vision_Based_Inventory_Management/src/train.py
Connections 28
- Camera input → Camera node: frames · Camera hardware feeds the ROS2 capture node.
- Camera node → Detection node: image stream · Captured frames are sent into inference nodes.
- Camera node → Alt detector: image stream · Alternate detector can consume the same camera feed.
- Detection node → ROS messages: detections · Detection outputs are encoded as ROS2 messages.
- Alt detector → ROS messages: detections · Alternate detection outputs use the same message contracts.
- ROS messages → Inventory node: counts · Inventory aggregation consumes detection messages.
- Inventory node → API bridge: inventory state · Aggregated counts are forwarded toward backend/API consumers.
- System launch → Camera node: starts · Launch file orchestrates the camera node.
- System launch → Detection node: starts · Launch file orchestrates the detector node.
- System launch → Inventory node: starts · Launch file orchestrates inventory aggregation.
- System launch → API bridge: starts · Launch file includes the bridge node.
- System launch → Pan-tilt: starts · Launch file can include hardware control.
- Dataset config → Training pipeline: configures · Dataset metadata feeds preprocessing and training.
- Training pipeline → Trained models: produces · Training writes weights and run artifacts.
- Trained models → Inference core: loads · Inference uses trained weights from the artifact store.
- Model export → Trained models: publishes · Exported deployment variants are stored with model artifacts.
- ML support → Training pipeline: supports · Support code is used by training and continual learning.
- API server → Inference core: serves · Backend API wraps inference for live requests and streams.
- API server → ML support: manages · Backend owns model switching, class creation, and continual learning flows.
- API client → API server: requests · Dashboard consumes REST and stream endpoints via the client layer.
- Dashboard app → Live stream: renders · App composes live video and overlay components.
- Dashboard app → Inventory views: renders · App composes analytics and operational views.
- Live stream → API client: subscribes · Live stream components consume backend real-time data.
- Inventory views → API client: fetches · Inventory views fetch current state and history through the API client.
- Training workspace → Trained models: shares weights · Parallel workspace contains training outputs and model files.
- Training workspace → Dataset config: shares config · Nested workspace mirrors the dataset setup for training.
- API bridge → API server: updates · Edge inventory data is bridged into the backend/API layer.
- API server → Dashboard app: streams data · Backend provides live inventory and video data to the dashboard.