forked from ljk10/asl_translator_3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaugment.py
More file actions
42 lines (33 loc) · 1.62 KB
/
augment.py
File metadata and controls
42 lines (33 loc) · 1.62 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
40
41
42
import os
import numpy as np
from scipy.ndimage import shift, rotate
DATA_PATH = os.path.join('frontend', 'models')
def augment_data():
print(f"⚡ Generating Clones in {DATA_PATH}...")
files = [f for f in os.listdir(DATA_PATH) if f.endswith('.npy') and "aug" not in f]
count = 0
for file_name in files:
file_path = os.path.join(DATA_PATH, file_name)
try:
data = np.load(file_path) # Shape: (40, 225)
# 1. NOISE CLONE (Simulates bad webcam grain)
noise = np.random.normal(0, 0.01, data.shape)
data_noise = data + noise
np.save(os.path.join(DATA_PATH, file_name.replace('.npy', '_aug_noise.npy')), data_noise)
# 2. SHIFT CLONE (Simulates person standing slightly left/right)
# Shift x-coordinates (indices 0, 3, 6...)
data_shift = data.copy()
data_shift[:, 0::3] += 0.02 # Shift Right
np.save(os.path.join(DATA_PATH, file_name.replace('.npy', '_aug_shift.npy')), data_shift)
# 3. SPEED CLONE (Simulates faster signing)
# We skip every 2nd frame to make it "faster" then pad with zeros
data_fast = np.zeros_like(data)
fast_seq = data[::2] # Take every other frame
data_fast[:len(fast_seq)] = fast_seq
np.save(os.path.join(DATA_PATH, file_name.replace('.npy', '_aug_fast.npy')), data_fast)
count += 3
except Exception as e:
print(f"Skipped {file_name}: {e}")
print(f"✅ Created {count} new training samples!")
if __name__ == "__main__":
augment_data()