| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
|
|
| import h5py |
| import numpy as np |
| import os |
|
|
| def calculate_statistics(hdf5_path): |
| actions = [] |
| ee_states = [] |
| gripper_states = [] |
| joint_states = [] |
|
|
| with h5py.File(hdf5_path, 'r') as f: |
| for demo in f['data']: |
| actions.append(f[f'data/{demo}/actions'][:]) |
| ee_states.append(f[f'data/{demo}/obs/ee_states'][:]) |
| gripper_states.append(f[f'data/{demo}/obs/gripper_states'][:]) |
| joint_states.append(f[f'data/{demo}/obs/joint_states'][:]) |
| actions = np.concatenate(actions, axis=0) |
| ee_states = np.concatenate(ee_states, axis=0) |
| gripper_states = np.concatenate(gripper_states, axis=0) |
| joint_states = np.concatenate(joint_states, axis=0) |
| stats = { |
| 'actions': { |
| 'mean': np.mean(actions, axis=0), |
| 'std': np.std(actions, axis=0), |
| 'min': np.min(actions, axis=0), |
| 'max': np.max(actions, axis=0), |
| 'q01': np.percentile(actions, 1, axis=0), |
| 'q99': np.percentile(actions, 99, axis=0) |
| }, |
| 'ee_states': { |
| 'mean': np.mean(ee_states, axis=0), |
| 'std': np.std(ee_states, axis=0), |
| 'min': np.min(ee_states, axis=0), |
| 'max': np.max(ee_states, axis=0), |
| 'q01': np.percentile(ee_states, 1, axis=0), |
| 'q99': np.percentile(ee_states, 99, axis=0) |
| }, |
| 'gripper_states': { |
| 'mean': np.mean(gripper_states, axis=0), |
| 'std': np.std(gripper_states, axis=0), |
| 'min': np.min(gripper_states, axis=0), |
| 'max': np.max(gripper_states, axis=0), |
| 'q01': np.percentile(gripper_states, 1, axis=0), |
| 'q99': np.percentile(gripper_states, 99, axis=0) |
| }, |
| 'joint_states': { |
| 'mean': np.mean(joint_states, axis=0), |
| 'std': np.std(joint_states, axis=0), |
| 'min': np.min(joint_states, axis=0), |
| 'max': np.max(joint_states, axis=0), |
| 'q01': np.percentile(joint_states, 1, axis=0), |
| 'q99': np.percentile(joint_states, 99, axis=0) |
| } |
| } |
| return stats |
|
|
| def process_directory(directory): |
| all_stats = { |
| 'actions': [], |
| 'ee_states': [], |
| 'gripper_states': [], |
| 'joint_states': [] |
| } |
| |
| for filename in os.listdir(directory): |
| if filename.endswith('.hdf5'): |
| hdf5_path = os.path.join(directory, filename) |
| stats = calculate_statistics(hdf5_path) |
| for key in all_stats: |
| all_stats[key].append(stats[key]) |
| |
| |
| overall_stats = {} |
| for key, values in all_stats.items(): |
| |
| means = np.array([v['mean'] for v in values]) |
| stds = np.array([v['std'] for v in values]) |
| mins = np.array([v['min'] for v in values]) |
| maxs = np.array([v['max'] for v in values]) |
| q01s = np.array([v['q01'] for v in values]) |
| q99s = np.array([v['q99'] for v in values]) |
| overall_stats[key] = { |
| 'mean': np.mean(means, axis=0), |
| 'std': np.mean(stds, axis=0), |
| 'min': np.min(mins, axis=0), |
| 'max': np.max(maxs, axis=0), |
| 'q01': np.mean(q01s, axis=0), |
| 'q99': np.mean(q99s, axis=0) |
| } |
|
|
| |
| return overall_stats |
|
|
| if __name__ == "__main__": |
| directory = '/home2/czhang/datasets/LIBERO/libero_spatial' |
| stats = process_directory(directory) |
| for key, value in stats.items(): |
| print(f"{key}:") |
| for stat_name, stat_value in value.items(): |
| print(f" {stat_name}: {stat_value}") |
| print("Statistics calculated successfully.") |