| | import argparse |
| | import json |
| | import os |
| | import pickle |
| |
|
| | import numpy as np |
| |
|
| | |
| | |
| | |
| |
|
| | def annotes(args) : |
| | dataset = args.dataset |
| | mode = args.mode |
| | offset = args.offset |
| | video_fps = args.video_fps |
| | anno_fps = args.anno_fps |
| | |
| | video_fps = 20 |
| | anno_fps = 5 |
| | chunk_size = video_fps / anno_fps |
| | |
| | dir_list = os.listdir(dataset) |
| | |
| | annotation = {} |
| | for session in dir_list: |
| | print(f'START PROCESSING {session}') |
| | session_path = os.path.join(dataset, session) |
| | json_path = sorted(os.listdir(session_path)) |
| |
|
| | json_num = len(json_path) |
| | feature_length = int(video_fps*60*json_num/6) |
| |
|
| | |
| | annotation[session] = {} |
| | anno = np.zeros((feature_length, 3)) |
| |
|
| | |
| | frame_num = 0 |
| |
|
| | for file_ in json_path : |
| |
|
| | with open(os.path.join(session_path,file_), 'r') as f: |
| | transcripts = json.load(f) |
| |
|
| | for transcript in transcripts : |
| | |
| | if transcript['Participant_ID'] == 2: |
| | encode_num = 1 |
| | else: |
| | encode_num = 2 |
| |
|
| | start = (transcript['Start_Frame']+frame_num)//6 |
| | end = (transcript['End_Frame']+frame_num)//6 |
| | if start < 0: |
| | start = 0 |
| | |
| | if encode_num == 1 : |
| | end_ = start + offset |
| | anno[start : end_, encode_num] = 1 |
| | else: |
| | anno[start : end, encode_num] = 1 |
| |
|
| | print(f'start : {start} , end : {end}') |
| | frame_num += 1200 |
| | print(f'feature_length : {feature_length}') |
| | anno[np.where(np.sum(anno, axis=1) == 0), 0] = 1 |
| | annotation[session]['anno'] = anno |
| | annotation[session]['feature_length'] = feature_length |
| |
|
| | print('processing done !') |
| | |
| | |
| | with open(f'easycom_{mode}_{offset}.pickle', 'wb') as file : |
| | pickle.dump(annotation , file) |
| |
|
| | print('SAVED') |
| | |
| |
|
| |
|
| | if __name__ == '__main__': |
| |
|
| | parser = argparse.ArgumentParser() |
| | parser.add_argument('--dataset', type = str, default = '/scratch/jisoo/EasyComDataset/Main/Speech_Transcriptions/val') |
| | parser.add_argument('--mode', type = str, default = 'val') |
| | parser.add_argument('--offset', type = int, default = 1) |
| | parser.add_argument('--video-fps', type = int, default = 20, help='original fps of video') |
| | parser.add_argument('--anno-fps', type = int, default = 5, help='fps of annotation') |
| | |
| | args = parser.parse_args() |
| |
|
| | annotes(args) |