def convert_sthv1_csv_to_json(class_file_path, train_csv_path, val_csv_path, test_csv_path, video_dir_path, dst_json_path): labels = load_labels(class_file_path) train_database = convert_csv_to_dict(train_csv_path, 'training') val_database = convert_csv_to_dict(val_csv_path, 'validation') if test_csv_path.exists(): test_database = convert_csv_to_dict(test_csv_path, 'testing') dst_data = {} dst_data['labels'] = labels dst_data['database'] = {} dst_data['database'].update(train_database) dst_data['database'].update(val_database) if test_csv_path.exists(): dst_data['database'].update(test_database) count = 0 for k, v in tqdm.tqdm(dst_data['database'].items()): if 'label' in v['annotations']: label = v['annotations']['label'] else: label = 'test' video_path = video_dir_path / k n_frames = get_n_frames(video_path) v['annotations']['segment'] = (1, n_frames + 1) v['video_path'] = str(video_path) # count += 1 # if count == 1000: # break with dst_json_path.open('w') as dst_file: json.dump(dst_data, dst_file)
def convert_photosensitivity_csv_to_json(label_csv_path, train_csv_path, val_csv_path, video_dir_path, dst_json_path): labels = load_labels(label_csv_path) train_database = convert_csv_to_dict(train_csv_path, 'training') val_database = convert_csv_to_dict(val_csv_path, 'validation') dst_data = {} dst_data['labels'] = labels dst_data['database'] = {} dst_data['database'].update(train_database) dst_data['database'].update(val_database) for k, v in dst_data['database'].items(): if v['annotations'] is not None: label = v['annotations']['label'] else: label = 'test' video_path = video_dir_path / label / k # print(video_path) n_frames = get_n_frames(video_path) # print(n_frames) v['annotations']['segment'] = (1, n_frames + 1) with dst_json_path.open('w') as dst_file: json.dump(dst_data, dst_file)
def convert_kinetics_csv_to_json(train_csv_path, val_csv_path, test_csv_path, video_dir_path, video_type, dst_json_path): labels = load_labels(train_csv_path) train_database = convert_csv_to_dict(train_csv_path, 'training') val_database = convert_csv_to_dict(val_csv_path, 'validation') if test_csv_path.exists(): test_database = convert_csv_to_dict(test_csv_path, 'testing') dst_data = {} dst_data['labels'] = labels dst_data['database'] = {} dst_data['database'].update(train_database) dst_data['database'].update(val_database) if test_csv_path.exists(): dst_data['database'].update(test_database) for k, v in dst_data['database'].items(): if 'label' in v['annotations']: label = v['annotations']['label'] else: label = 'test' if video_type == 'jpg': video_path = video_dir_path / label / k if video_path.exists(): n_frames = get_n_frames(video_path) v['annotations']['segment'] = (1, n_frames + 1) else: video_path = video_dir_path / label / f'{k}.hdf5' if video_path.exists(): n_frames = get_n_frames_hdf5(video_path) v['annotations']['segment'] = (0, n_frames) with dst_json_path.open('w') as dst_file: json.dump(dst_data, dst_file)
def convert_ucf101_csv_to_json(label_csv_path, train_csv_path, val_csv_path, video_dir_path, audio_dir_path, dst_json_path, video_type): if audio_dir_path is not None: labels = [x.name for x in sorted(audio_dir_path.iterdir())] else: labels = load_labels(label_csv_path) train_database = convert_csv_to_dict(train_csv_path, 'training', labels) val_database = convert_csv_to_dict(val_csv_path, 'validation', labels) dst_data = {} dst_data['labels'] = labels dst_data['database'] = {} dst_data['database'].update(train_database) dst_data['database'].update(val_database) for k, v in dst_data['database'].items(): if v['annotations'] is not None: label = v['annotations']['label'] else: label = 'test' video_path = video_dir_path / label / k if video_type == 'jpg': n_frames = get_n_frames(video_path) else: video_path = str(video_path) + '.hdf5' n_frames = get_n_frames_hdf5(video_path) v['annotations']['segment'] = (1, n_frames + 1) if audio_dir_path is not None: # save the subset dst_json_path = dst_json_path.parent / dst_json_path.name.replace( 'ucf101', 'ucf51') with dst_json_path.open('w') as dst_file: json.dump(dst_data, dst_file)