Download scripts/split_ego4d_clips.py from anonseoul/turn-taking-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.03 kB
-
https://huggingface.co/datasets/anonseoul/turn-taking-dataset/resolve/main/scripts/split_ego4d_clips.py
- Command line
-
hf download hf://datasets/anonseoul/turn-taking-dataset/scripts/split_ego4d_clips.py
-
curl -L -o split_ego4d_clips.py https://huggingface.co/datasets/anonseoul/turn-taking-dataset/resolve/main/scripts/split_ego4d_clips.py
2.03 kB
| # split clips into train / val / test set | |
| # From the list, split clips into train / val / test directories | |
| import csv | |
| import shutil | |
| import os | |
| # read clip_uid csv file save as list | |
| def read_uid_csv(filename): | |
| with open(filename, 'r') as f: | |
| reader = csv.reader(f) | |
| uid_list = list(reader) | |
| return uid_list | |
| def split_clips(clips_path, clips_split_path): | |
| subset = ['train', 'val', 'test'] | |
| for split in subset: | |
| if split not in clip_csv_dict.keys(): | |
| print("{} split is not in clip_csv_dict".format(split)) | |
| continue | |
| clip_uids_list = read_uid_csv(clip_csv_dict[split])[0] | |
| os.makedirs(os.path.join(clips_split_path, split),exist_ok=True) | |
| # copy videos from clips_path into clips_split_path | |
| for clip_uid in clip_uids_list: | |
| clip_filename = clip_uid + '.mp4' | |
| src = os.path.join(clips_path, clip_filename) | |
| dst = os.path.join(clips_split_path, split, clip_filename) | |
| shutil.copy(src, dst) | |
| print('copied {} to {}'.format(src, dst)) | |
| clip_csv_dict = { | |
| 'train': 'train_clip_uids.csv', | |
| 'val': 'val_clip_uids.csv', | |
| 'test': 'test_clip_uids.csv' | |
| } | |
| ego4d_path = '/home/junhyeok/datasets/ego4d_dataset/v2/' | |
| clips_path = os.path.join(ego4d_path, 'clips') | |
| clips_split_path = os.path.join(ego4d_path, 'splits') | |
| os.makedirs(clips_split_path, exist_ok=True) | |
| def convert_csv_to_lines_and_save(csv_file_path, output_file_path): | |
| with open(csv_file_path, 'r') as file: | |
| csv_content = file.read().strip() | |
| lines = csv_content.split(',') | |
| # Join the lines with newline character '\n' to create the desired format | |
| converted_text = '\n'.join(lines) | |
| with open(output_file_path, 'w') as file: | |
| file.write(converted_text) | |
| print("Conversion completed. The result is saved to '{}'.".format(output_file_path)) | |
| convert_csv_to_lines_and_save('train_clip_uids.csv', 'train_clip_uids.txt') | |
| convert_csv_to_lines_and_save('val_clip_uids.csv', 'val_clip_uids.txt') | |
| convert_csv_to_lines_and_save('test_clip_uids.csv', 'test_clip_uids.txt') | |