File size: 2,622 Bytes
b2e15d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import os
import numpy as np

input_path = ["/home/ubuntu/MoCapDataset/AMASSDataset/UnitreeG1_29dof", "/home/ubuntu/MoCapDataset/Retarget/UnitreeG1_29dof"]

files = []
for input_dir in input_path:
    for path, _, filenames in os.walk(input_dir):
        for file in filenames:
            if file.endswith(".npy") or file.endswith(".npz"):
                files.append(os.path.join(path, file))

print(f"Found {len(files)} files")

# Velocity threshold for classification (m/s) - horizontal speed only
WALKING_RUNNING_THRESHOLD = 1.5  # Below this is walking, above is running

walking_count = 0
running_count = 0
skipped_count = 0

for file_path in files:
    try:
        # Load data
        if file_path.endswith(".npy"):
            data = np.load(file_path, allow_pickle=True).item()
        elif file_path.endswith(".npz"):
            data = dict(np.load(file_path, allow_pickle=True))
        
        # Check if qvel exists
        if 'qvel' not in data:
            print(f"Skipping {file_path}: No qvel data")
            skipped_count += 1
            continue
            
        qvel = data['qvel']
        
        horizontal_velocities = qvel[:, :2]
        horizontal_speeds = np.linalg.norm(horizontal_velocities, axis=1)
        
        avg_horizontal_speed = np.mean(horizontal_speeds)
        max_horizontal_speed = np.max(horizontal_speeds)
        
        if avg_horizontal_speed < WALKING_RUNNING_THRESHOLD:
            motion_type = "walking"
            walking_count += 1
        else:
            motion_type = "running"
            running_count += 1
        
        # Add motion type and speed metrics to data
        data['motion_type'] = motion_type
        data['avg_horizontal_speed'] = avg_horizontal_speed
        data['max_horizontal_speed'] = max_horizontal_speed
        
        if file_path.endswith(".npy"):
            np.save(file_path, data)
        elif file_path.endswith(".npz"):
            np.savez(file_path, **data)
        
        print(f"Processed {os.path.basename(file_path)}: {motion_type} (avg: {avg_horizontal_speed:.2f} m/s, max: {max_horizontal_speed:.2f} m/s)")
        
    except Exception as e:
        print(f"Error processing {file_path}: {str(e)}")
        skipped_count += 1
        continue

print(f"\nProcessing complete!")
print(f"Walking files: {walking_count}")
print(f"Running files: {running_count}")
print(f"Skipped files: {skipped_count}")
print(f"Total processed: {walking_count + running_count}")
print(f"\nMotion type markers added to original files.")
print(f"Threshold used: {WALKING_RUNNING_THRESHOLD} m/s (horizontal speed)")