Commit ·
33db364
1
Parent(s): 711b622
refactor: add data augmentation options for NinaPro DB5 processing and only 41 gestures setup
Browse files- scripts/README.md +4 -2
- scripts/db5.py +39 -6
scripts/README.md
CHANGED
|
@@ -27,11 +27,13 @@ This guide provides commands to process raw EMG data into HDF5 format using slid
|
|
| 27 |
|
| 28 |
| Dataset | Metric | Seq Len | Stride | Command |
|
| 29 |
| :--- | :--- | :--- | :--- | :--- |
|
| 30 |
-
| **NinaPro DB5** | Gesture | 200 (1s) | 50 | `python scripts/db5.py --data_dir $DATA_PATH/ninapro/DB5/ --save_dir $DATA_PATH/ninapro/DB5/h5_1sec/ --seq_len 200 --stride 50` |
|
| 31 |
-
| **NinaPro DB5** | Gesture | 1000 (5s) | 250 | `python scripts/db5.py --data_dir $DATA_PATH/ninapro/DB5/ --save_dir $DATA_PATH/ninapro/DB5/h5_5sec/ --seq_len 1000 --stride 250` |
|
| 32 |
| **EMG-EPN612** | Gesture | 200 (1s) | N/A | `python scripts/epn.py --data_dir $DATA_PATH/EPN612/ --source_training $DATA_PATH/EPN612/trainingJSON/ --source_testing $DATA_PATH/EPN612/testingJSON/ --dest_dir $DATA_PATH/EPN612/h5_1sec/ --seq_len 200` |
|
| 33 |
| **EMG-EPN612** | Gesture | 1000 (5s) | N/A | `python scripts/epn.py --data_dir $DATA_PATH/EPN612/ --source_training $DATA_PATH/EPN612/trainingJSON/ --source_testing $DATA_PATH/EPN612/testingJSON/ --dest_dir $DATA_PATH/EPN612/h5_5sec/ --seq_len 1000` |
|
| 34 |
| **UCI EMG** | Gesture | 200 (1s) | 50 | `python scripts/uci.py --data_dir $DATA_PATH/UCI_EMG/EMG_data_for_gestures-master/ --save_dir $DATA_PATH/UCI_EMG/EMG_data_for_gestures-master/h5_1sec/ --seq_len 200 --stride 50` |
|
| 35 |
| **UCI EMG** | Gesture | 1000 (5s) | 250 | `python scripts/uci.py --data_dir $DATA_PATH/UCI_EMG/EMG_data_for_gestures-master/ --save_dir $DATA_PATH/UCI_EMG/EMG_data_for_gestures-master/h5_5sec/ --seq_len 1000 --stride 250` |
|
| 36 |
| **NinaPro DB8** | Regression | 200 (0.1s) | 200 | `python scripts/db8.py --data_dir $DATA_PATH/ninapro/DB8/ --save_dir $DATA_PATH/ninapro/DB8/h5_100/ --seq_len 200 --stride 200` |
|
| 37 |
| **NinaPro DB8** | Regression | 1000 (0.5s) | 1000 | `python scripts/db8.py --data_dir $DATA_PATH/ninapro/DB8/ --save_dir $DATA_PATH/ninapro/DB8/h5_500/ --seq_len 1000 --stride 1000` |
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
| Dataset | Metric | Seq Len | Stride | Command |
|
| 29 |
| :--- | :--- | :--- | :--- | :--- |
|
| 30 |
+
| **NinaPro DB5** | Gesture | 200 (1s) | 50 | `python scripts/db5.py --data_dir $DATA_PATH/ninapro/DB5/ --save_dir $DATA_PATH/ninapro/DB5/h5_1sec/ --seq_len 200 --stride 50 --data-augment` |
|
| 31 |
+
| **NinaPro DB5** | Gesture | 1000 (5s) | 250 | `python scripts/db5.py --data_dir $DATA_PATH/ninapro/DB5/ --save_dir $DATA_PATH/ninapro/DB5/h5_5sec/ --seq_len 1000 --stride 250 --data-augment` |
|
| 32 |
| **EMG-EPN612** | Gesture | 200 (1s) | N/A | `python scripts/epn.py --data_dir $DATA_PATH/EPN612/ --source_training $DATA_PATH/EPN612/trainingJSON/ --source_testing $DATA_PATH/EPN612/testingJSON/ --dest_dir $DATA_PATH/EPN612/h5_1sec/ --seq_len 200` |
|
| 33 |
| **EMG-EPN612** | Gesture | 1000 (5s) | N/A | `python scripts/epn.py --data_dir $DATA_PATH/EPN612/ --source_training $DATA_PATH/EPN612/trainingJSON/ --source_testing $DATA_PATH/EPN612/testingJSON/ --dest_dir $DATA_PATH/EPN612/h5_5sec/ --seq_len 1000` |
|
| 34 |
| **UCI EMG** | Gesture | 200 (1s) | 50 | `python scripts/uci.py --data_dir $DATA_PATH/UCI_EMG/EMG_data_for_gestures-master/ --save_dir $DATA_PATH/UCI_EMG/EMG_data_for_gestures-master/h5_1sec/ --seq_len 200 --stride 50` |
|
| 35 |
| **UCI EMG** | Gesture | 1000 (5s) | 250 | `python scripts/uci.py --data_dir $DATA_PATH/UCI_EMG/EMG_data_for_gestures-master/ --save_dir $DATA_PATH/UCI_EMG/EMG_data_for_gestures-master/h5_5sec/ --seq_len 1000 --stride 250` |
|
| 36 |
| **NinaPro DB8** | Regression | 200 (0.1s) | 200 | `python scripts/db8.py --data_dir $DATA_PATH/ninapro/DB8/ --save_dir $DATA_PATH/ninapro/DB8/h5_100/ --seq_len 200 --stride 200` |
|
| 37 |
| **NinaPro DB8** | Regression | 1000 (0.5s) | 1000 | `python scripts/db8.py --data_dir $DATA_PATH/ninapro/DB8/ --save_dir $DATA_PATH/ninapro/DB8/h5_500/ --seq_len 1000 --stride 1000` |
|
| 38 |
+
|
| 39 |
+
>Note: For DB5, we used the `--data-augment` flag to augment the training data by a factor of 3 (see `--augment-factor` in `scripts/db5.py`).
|
scripts/db5.py
CHANGED
|
@@ -226,6 +226,22 @@ def main():
|
|
| 226 |
type=int,
|
| 227 |
help="Step size between windows in samples for segmentation.",
|
| 228 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
args = args.parse_args()
|
| 230 |
|
| 231 |
data_dir = args.data_dir
|
|
@@ -275,10 +291,27 @@ def main():
|
|
| 275 |
rerep = dd["rerepetition"].ravel().astype(int)
|
| 276 |
|
| 277 |
# label shift by exercise
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
|
| 283 |
# filtering at original 200 Hz
|
| 284 |
emg_filt = bandpass_filter_emg(emg, 20, 90, fs=fs)
|
|
@@ -310,8 +343,8 @@ def main():
|
|
| 310 |
X = np.stack(all_data[split], axis=0) # [N, window_size, ch]
|
| 311 |
y = np.array(all_lbls[split], dtype=int)
|
| 312 |
|
| 313 |
-
if split == "train":
|
| 314 |
-
X, y = augment_train_data(X, y, factor=
|
| 315 |
|
| 316 |
# transpose to [N, ch, window_size]
|
| 317 |
X = X.transpose(0, 2, 1)
|
|
|
|
| 226 |
type=int,
|
| 227 |
help="Step size between windows in samples for segmentation.",
|
| 228 |
)
|
| 229 |
+
args.add_argument(
|
| 230 |
+
"--only-41",
|
| 231 |
+
action="store_true",
|
| 232 |
+
help="If set, only the first 41 gestures (common between DB5, DB7) will be processed.",
|
| 233 |
+
)
|
| 234 |
+
args.add_argument(
|
| 235 |
+
"--data-augment",
|
| 236 |
+
action="store_true",
|
| 237 |
+
help="If set, data augmentation will be applied to the training set.",
|
| 238 |
+
)
|
| 239 |
+
args.add_argument(
|
| 240 |
+
"--augment-factor",
|
| 241 |
+
type=int,
|
| 242 |
+
default=3,
|
| 243 |
+
help="Number of augmented versions to create for each training sample.",
|
| 244 |
+
)
|
| 245 |
args = args.parse_args()
|
| 246 |
|
| 247 |
data_dir = args.data_dir
|
|
|
|
| 291 |
rerep = dd["rerepetition"].ravel().astype(int)
|
| 292 |
|
| 293 |
# label shift by exercise
|
| 294 |
+
# E1: 12 gestures [1-12]
|
| 295 |
+
# E2: 17 gestures [1-17]
|
| 296 |
+
# E3: 23 gestures [1-23]
|
| 297 |
+
|
| 298 |
+
if args.only_41:
|
| 299 |
+
# Use only E2 and E3 and remap them to labels 1..17 and 18..40
|
| 300 |
+
# while keeping rest as label 0.
|
| 301 |
+
if "E1" in mat:
|
| 302 |
+
continue
|
| 303 |
+
if "E2" in mat:
|
| 304 |
+
label = np.where(label != 0, label, 0)
|
| 305 |
+
elif "E3" in mat:
|
| 306 |
+
label = np.where(label != 0, label + 17, 0)
|
| 307 |
+
else:
|
| 308 |
+
continue
|
| 309 |
+
else:
|
| 310 |
+
# Flatten the label space to avoid overlap across exercises
|
| 311 |
+
if "E2" in mat:
|
| 312 |
+
label = np.where(label != 0, label + 12, 0)
|
| 313 |
+
elif "E3" in mat:
|
| 314 |
+
label = np.where(label != 0, label + 29, 0)
|
| 315 |
|
| 316 |
# filtering at original 200 Hz
|
| 317 |
emg_filt = bandpass_filter_emg(emg, 20, 90, fs=fs)
|
|
|
|
| 343 |
X = np.stack(all_data[split], axis=0) # [N, window_size, ch]
|
| 344 |
y = np.array(all_lbls[split], dtype=int)
|
| 345 |
|
| 346 |
+
if split == "train" and args.data_augment:
|
| 347 |
+
X, y = augment_train_data(X, y, factor=args.augment_factor)
|
| 348 |
|
| 349 |
# transpose to [N, ch, window_size]
|
| 350 |
X = X.transpose(0, 2, 1)
|