| import pandas as pd |
| import numpy as np |
| import os |
| from tqdm import tqdm |
|
|
| def update_metadata_frames(metadata_path, features_root_path): |
| """更新metadata文件中的实际帧数""" |
| |
| metadata = pd.read_csv(metadata_path) |
| |
| print(f"Processing {len(metadata)} entries from {metadata_path}") |
| |
| |
| actual_frames = [] |
| error_count = 0 |
| |
| for idx, row in tqdm(metadata.iterrows(), total=len(metadata)): |
| |
| feature_path = os.path.join(features_root_path, row['path']) |
| |
| try: |
| |
| features = np.load(feature_path, allow_pickle=True) |
| actual_frames.append(features['visual'].shape[0]) |
| except Exception as e: |
| print(f"Error loading {feature_path}: {e}") |
| actual_frames.append(0) |
| error_count += 1 |
| |
| |
| metadata['num_frames'] = actual_frames |
| |
| |
| metadata.to_csv(metadata_path, index=False) |
| |
| print(f"Updated {metadata_path} with actual frame counts") |
| print(f"Errors: {error_count}, Success: {len(metadata) - error_count}") |
| print(f"Frame count statistics: min={min(actual_frames)}, max={max(actual_frames)}, avg={np.mean(actual_frames):.1f}") |
|
|
| if __name__ == "__main__": |
| features_root = '/apdcephfs_gy5/share_303628665/joyewu/research/AVH-Align/ft_work_features' |
| |
| |
| update_metadata_frames( |
| '/apdcephfs_gy5/share_303628665/joyewu/research/AVH-Align/ft_work_metadata/train_metadata.csv', |
| os.path.join(features_root, 'train') |
| ) |
| |
| |
| update_metadata_frames( |
| '/apdcephfs_gy5/share_303628665/joyewu/research/AVH-Align/ft_work_metadata/val_metadata.csv', |
| os.path.join(features_root, 'val') |
| ) |