forked from ljk10/asl_translator_3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaugment_data.py
More file actions
39 lines (28 loc) · 1.25 KB
/
augment_data.py
File metadata and controls
39 lines (28 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import numpy as np
import os
# CONFIG
DATA_PATH = 'Alphabet_Data'
actions = np.array(['cool', 'who', 'computer']) # Add words you want to augment here!
# Or use os.listdir(DATA_PATH) to do ALL words
def add_noise(data, noise_factor=0.02):
noise = np.random.normal(0, data.std() * noise_factor, data.shape)
return data + noise
def scale_data(data, scale_factor=1.1):
return data * scale_factor
for action in actions:
action_path = os.path.join(DATA_PATH, action)
if not os.path.exists(action_path): continue
files = os.listdir(action_path)
print(f"Augmenting {action}: Found {len(files)} sequences.")
current_count = len(files)
for i, file_name in enumerate(files):
if not file_name.endswith('.npy'): continue
# Load original
data = np.load(os.path.join(action_path, file_name))
# 1. Create "Jitter" version
noisy_data = add_noise(data)
np.save(os.path.join(action_path, str(current_count + i)), noisy_data)
# 2. Create "Scaled" version
scaled_data = scale_data(data)
np.save(os.path.join(action_path, str(current_count + len(files) + i)), scaled_data)
print(f" -> Done. New total: {len(os.listdir(action_path))} sequences.")