| |
| |
| |
|
|
| import json |
| import pickle |
| import numpy as np |
|
|
| |
|
|
| av_train_annotation_path = '/scratch/junhyeok/ego4d_dataset/v2/annotations/av_test.json' |
|
|
| with open(av_train_annotation_path, "r") as f: |
| av_train_annotations = json.load(f) |
|
|
| av_train_processed = {} |
|
|
| for video in av_train_annotations['videos'] : |
| for clip in video['clips'] : |
| uid = clip['clip_uid'] |
| av_train_processed[uid] = {} |
| |
| end_frame = clip['clip_end_frame'] |
| |
| feature_num = int(np.round(end_frame/6)) |
| if feature_num != 1500 : |
| print('uid : {} , feature_length : {}'.format(uid , feature_num)) |
| anno = np.zeros((feature_num , 3)) |
| |
| anno[:,0]=1 |
|
|
| i=0 |
| for transcript in clip['transcriptions']: |
|
|
| |
| if i==0 : |
| initial_frame = clip['video_start_frame'] |
| i+=1 |
|
|
| |
| start_frame = transcript['video_start_frame'] - initial_frame |
| end_frame = transcript['video_end_frame'] - initial_frame |
|
|
| |
| if int(transcript['person_id']) == 0 : |
| encode_num = 1 |
| if int(transcript['person_id']) >= 1 : |
| encode_num = 2 |
| if int(transcript['person_id']) == -1 : |
| encode_num = 0 |
| |
| |
| if end_frame//6 - start_frame//6 == 0 : |
| anno[(start_frame//6)-1 , 0] = 0 |
| anno[(start_frame//6)-1 , encode_num]=1 |
| else : |
| anno[(start_frame//6)-1 : (end_frame//6) , 0] = 0 |
| anno[(start_frame//6)-1 : (end_frame//6) , encode_num]=1 |
| |
|
|
| |
| av_train_processed[uid]['anno'] = anno |
| av_train_processed[uid]['feature_length'] = feature_num |
| print(end_frame//6) |
| print(transcript['person_id']) |
|
|
| print('Processing DONE!') |
|
|
| with open('train_perfeature.pickle' , 'wb') as f : |
| pickle.dump(av_train_processed , f) |
|
|
| print('SAVED') |