Inference & Dashboard¶
Live inference¶
from host.serial_reader import SerialReader
from host.feature_extraction import FeatureExtractor
from host.live_inference import LiveClassifier
classifier = LiveClassifier("models/worker_har_best.pt")
extractor = FeatureExtractor()
with SerialReader("/dev/ttyACM0") as reader:
for frame in reader:
feats = extractor.add_frame(frame)
if feats is not None:
label, conf = classifier.predict(feats)
print(f"{label} ({conf:.2%})")
EMA smoothing¶
LiveClassifier applies exponential moving average smoothing to the model
logits with decay factor 0.6. This reduces jitter between consecutive windows
while keeping the response time under ~1 second.
classifier.reset() # clear EMA state (e.g., between sessions)
top3 = classifier.top_k(feats, k=3) # top-3 labels with confidence
Offline inference (recorded file)¶
from host.data_recorder import DataRecorder
from host.feature_extraction import FeatureExtractor
from host.live_inference import LiveClassifier
data = DataRecorder.load("session_001.h5")
classifier = LiveClassifier("models/worker_har_best.pt")
extractor = FeatureExtractor()
# Iterate over frames in the HDF5 file
for i in range(len(data["timestamps"])):
# reconstruct SensorFrame from HDF5 slices
feats = extractor.add_frame(frame_from_hdf5(data, i))
if feats is not None:
label, conf = classifier.predict(feats)
Dashboard¶
Launch with:
cd wearable_har_v2
.venv/bin/python -m streamlit run host/dashboard.py
Opens at http://localhost:8501.
Panels¶
| Panel | Description |
|---|---|
| Stick figure | 3D stick figure from IMU orientations (wrists, elbows, chest, thigh). Rotates live. |
| Activity gauge | Current classification with confidence bar. Shows top-3 labels. |
| EMG bars | Forearm flexor + lumbar erector activation, 0–100% |
| FSR heatmap | 2×2 foot pressure grid (heel/toe × left/right) |
| Timeline | 30-second scrolling activity timeline with color-coded labels |
| FPS counter | Streamlit rerun rate |
Features¶
- Auto-start: opens
SerialReaderand starts streaming on page load - Model selector: dropdown to pick a
.ptmodel file - Port selector: dropdown for serial port (auto-detects
/dev/ttyACM*) - Dark mode: Streamlit native, toggle in settings menu
Health check¶
curl -s http://localhost:8501/healthz
# → "ok"
Performance notes¶
The dashboard target is 10 FPS (100 ms rerun). Data arrives at 100 Hz; the dashboard decimates by processing every Nth frame. If the UI lags, reduce the number of stick-figure samples or close the timeline panel.