AI training, local testing, HLS export, and Ultra96 deployment support for the CG4002 project.
This workspace currently supports:
- gesture classification with
6classes:Raise,Shake,Chop,Stir,Swing,Punch - voice classification with
6classes:Bulbasaur,Charizard,Greninja,Lugia,Mewtwo,Pikachu - local browser-based testing for both models
- HLS header export for the Windows Vitis flow
- Ultra96 MQTT deployment with separate gesture and voice accelerators
- Training notebook: train_gesture_cnn.ipynb
- Current dated dataset folder: data/gesture/20260406
- Dataset content: merged raw gyro/acc gesture packets,
100measurements per class,600measurements total - Preprocessing contract:
- raw count band:
15to300 - motion trim by gyro magnitude threshold
5.0 - trimmed count band:
40to300 - baseline removal from first
5frames - FFT resample to
60 x 6
- raw count band:
- Runtime normalisation strategy: software z-score using
gesture_mean.npyandgesture_std.npy
- Training notebook: train_voice_cnn.ipynb
- Active combined artefact folder: data/audio/20260406_combined
- Active raw source buckets:
- data/audio/20260406/new
- data/audio/20260406/old
- data/audio/20260406/synthetic
- reviewed dashboard voice clips under dashboard/data
- Current runtime normalisation files: ultra96/deployment/voice_mean.npy and ultra96/deployment/voice_std.npy
- Test policy: stratified random file split, randomised per run by default unless you pin
SPLIT_SEED - Preprocessing contract:
- decode raw audio to mono
16 kHz - tighter silence trim plus focus windowing
- pre-emphasis
- cepstral mean normalisation before dataset z-score
- MFCC extraction to
40 x 50
- decode raw audio to mono
- Runtime normalisation strategy: software MFCC z-score using
voice_mean.npyandvoice_std.npy
CG4002-AI/
├── README.md
├── dashboard/
│ ├── server.py
│ ├── runtime.py
│ └── static/
├── data/
│ ├── audio/
│ └── gesture/
├── hls/
│ ├── gesture/
│ ├── voice/
│ └── voice_new/
├── notebooks/
│ ├── train_gesture_cnn.ipynb
│ └── train_voice_cnn.ipynb
├── tools/
│ ├── import_gesture_packets.py
│ ├── preprocess_voice_audio.py
│ └── voice_feature_pipeline.py
└── ultra96/
├── README.md
├── deployment/
├── local-ai-test/
└── mqtt-test/
The recommended way to run anything in this workspace is to use the project venv directly:
cd /Users/luozhiyang/Projects/CG4002-Code/CG4002-AI
./.venv/bin/python --versionIf shell activation is unreliable on your machine, prefer the project venv directly:
./.venv/bin/python <script.py>Run the notebook top to bottom:
cd /Users/luozhiyang/Projects/CG4002-Code/CG4002-AI/notebooks
jupyter notebookThen open train_gesture_cnn.ipynb.
Important notes:
- The notebook now auto-selects the latest dated gesture folder when
GESTURE_DIR_OVERRIDE = None. - The current latest folder is data/gesture/20260406.
imudata.csvis auto-built from flat txt logs if needed.- Gesture export uses
fuse_input_norm=False.
Main gesture artefacts produced under the selected gesture folder:
gesture_X_test.npygesture_y_test.npymean.npystd.npypreprocess_meta.jsongesture_cnn_weights.h
Run train_voice_cnn.ipynb top to bottom.
Important notes:
- The notebook uses the shared deployment-aligned pipeline in voice_feature_pipeline.py.
USE_CLEANED_AUDIOshould stayFalsefor deployment parity.- The active output label is
20260406_combined. - The notebook currently supports two voice model variants:
deployed: current 16/32-channel HLS-compatible modelexperimental: modestly wider 20/40-channel model with a separate HLS folder under hls/voice_new
- Voice export uses
fuse_input_norm=False. - The dashboard can load a notebook checkpoint directly from
voice_dashboard_model.pt, so local dashboard testing is no longer limited to the current HLS-compatible voice shape.
Main voice artefacts are expected under the selected audio artefact folder:
voice_manifest.csvvoice_features.npyvoice_X_train.npyvoice_X_test.npyvoice_X_test_norm.npyvoice_y_train.npyvoice_y_test.npyvoice_mean.npyvoice_std.npyvoice_labels.jsonvoice_preprocess_config.jsonvoice_test_predictions.csvvoice_dashboard_model.ptvoice_cnn_weights.h
After fully rerunning the notebooks, the usual files to copy to your Windows HLS workspace are:
- data/gesture/20260406/gesture_cnn_weights.h
- hls/gesture/gesture_cnn.cpp
- hls/gesture/gesture_cnn.h
- hls/gesture/gesture_typedefs.h
- hls/voice/voice_cnn_weights.h
- hls/voice/voice_cnn.cpp
- hls/voice/voice_cnn.h
- hls/voice/voice_typedefs.h
- hls/voice_new/voice_cnn_weights.h
- hls/voice_new/voice_cnn.cpp
- hls/voice_new/voice_cnn.h
- hls/voice_new/voice_typedefs.h
Voice export now follows the selected notebook variant:
deployedexports to hls/voiceexperimentalexports to hls/voice_new
For voice deployment, the software path also needs:
For gesture deployment, the software path also needs:
The local dashboard is useful for testing models before deploying to Ultra96.
Start it with:
cd /Users/luozhiyang/Projects/CG4002-Code/CG4002-AI
./.venv/bin/python dashboard/server.py --host 127.0.0.1 --port 8000Optional explicit artefact paths:
./.venv/bin/python dashboard/server.py \
--host 127.0.0.1 \
--port 8000 \
--gesture-weights data/gesture/20260406/gesture_cnn_weights.h \
--gesture-mean ultra96/deployment/gesture_mean.npy \
--gesture-std ultra96/deployment/gesture_std.npy \
--voice-weights hls/voice/voice_cnn_weights.h \
--voice-mean ultra96/deployment/voice_mean.npy \
--voice-std ultra96/deployment/voice_std.npyThe dashboard supports:
- live gesture inference pushed from the ESP32 bridge
- voice file upload
- browser microphone recording
- raw and processed IMU plots
- raw and processed waveform plots
- processed waveform playback
- processed MFCC visualisation
- exact IMU tables
- a
Cleanuptab that readsvoice_test_predictions.csvand lets you play or delete misclassified test clips
Voice model loading in the dashboard now works like this:
- prefer the newest
voice_dashboard_model.ptcheckpoint if one exists - otherwise fall back to hls/voice/voice_cnn_weights.h
That means the dashboard can test the current experimental notebook model even when Ultra96 and HLS still use the older deployed voice shape.
Use the hardware bridge script in the hardware workspace:
Example:
cd /Users/luozhiyang/Projects/CG4002-Code/CG4002-HW
./.venv/bin/python gesture_live_test.py \
--port /dev/cu.usbserial-1410 \
--baud 115200 \
--server-url http://127.0.0.1:8000/api/gesture/infer- Training preprocessing and deployment preprocessing are aligned.
- Dashboard inference uses the same preprocessing contract.
- Dashboard and Ultra96 both apply
gesture_mean/stdin software. - Gesture export is intentionally non-fused.
- Ultra96 and dashboard both expect the same class order:
Raise,Shake,Chop,Stir,Swing,Punch
- Training feature generation uses the deployment preprocessor.
- Dashboard and Ultra96 both apply
voice_mean/stdin software. - Voice export is intentionally non-fused for the deployed HLS path.
- The dashboard may instead load
voice_dashboard_model.ptfor notebook-parity local testing. - Ultra96 and dashboard both expect the same class order:
Bulbasaur,Charizard,Greninja,Lugia,Mewtwo,Pikachu
See:
The deployment README documents:
- MQTT topics
- input and output JSON packets
- capture directories
- required runtime files
- example run commands