Skip to content

Recording Data

Quick start

from host.serial_reader import SerialReader
from host.data_recorder import DataRecorder

with SerialReader("/dev/ttyACM0") as reader:
    with DataRecorder("session_001.h5", label="hammering", subject_id="s01") as rec:
        for frame in reader:
            rec.write_frame(frame)
            if rec.frame_count >= 12000:  # 2 minutes at 100 Hz
                break

print(f"Recorded {rec.frame_count} frames to {rec.path}")

HDF5 schema

Each recording file contains one dataset per sensor type, indexed by frame:

Dataset Shape dtype Description
imus/quat (N, 6, 4) float32 Quaternion w,x,y,z per IMU
imus/acc (N, 6, 3) float32 Linear acceleration x,y,z per IMU
emg (N, 2) float32 MyoWare forearm, back (0–1)
fsr (N, 4) float32 FSR heel/toe ×2 feet (0–1)
bmp (N, 2) float32 BMP390 pressure, altitude
timestamps (N,) uint32 Microsecond timestamps
sequences (N,) uint32 Frame sequence numbers

Datasets are chunked (100 frames per chunk) with gzip level 4 compression.

Metadata

Each file carries HDF5 attributes:

Attribute Value
label Activity label (e.g. "hammering")
subject_id Subject identifier (e.g. "s01")
sample_rate_hz 100.0
num_imus 6
num_emg 2
num_fsr 4
feature_dim 328
activity_labels JSON array of 11 class names
created_at ISO 8601 timestamp

Loading recordings

from host.data_recorder import DataRecorder

data = DataRecorder.load("session_001.h5")
print(data["imus/quat"].shape)    # (12000, 6, 4)
print(data["emg"].shape)          # (12000, 2)
print(data["fsr"].shape)          # (12000, 4)
print(data.attrs["label"])        # "hammering"
print(data.attrs["subject_id"])   # "s01"

DataRecorder.load() returns an h5py.File opened read-only — use standard h5py indexing to slice the datasets.

Recording protocol

For a clean dataset suitable for training:

  1. Label per session: record one activity per file (e.g., s01_hammering_01.h5). Use the label= parameter.
  2. Consistent duration: target 2 minutes (12000 frames) per recording. Longer is fine; the training pipeline windows over the full recording.
  3. Subject ID: unique per person. The LOSO (leave-one-subject-out) cross-validation splits by subject_id.
  4. Rest between recordings: ~30 seconds to avoid carryover motion.
  5. RealSense: record RGB-D if available for ground-truth annotation.

Directory convention

recordings/
├── s01/
│   ├── s01_standing_01.h5
│   ├── s01_walking_01.h5
│   ├── s01_hammering_01.h5
│   └── ...
├── s02/
│   └── ...
└── ...

The training script accepts --data_dir recordings/ and discovers all .h5 files recursively.