MoCapDataset / filter_dataset.py
gourav-wadhwa's picture
adding everything from the dataset
b2e15d5
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)")