turn-taking-dataset / anno_preprocess /EASYCOM /preprocess_annotation.py
anonseoul's picture
Backup turn-taking-dataset from MIR NAS
fb5d697 verified
import argparse
import json
import os
import pickle
import numpy as np
# 1. for each video segment, get the video length by reading the video
# previously made by js a long before ago
# outdated, don't use this
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) #20fps*60s*json_num/6
#Embedding template
annotation[session] = {}
anno = np.zeros((feature_length, 3))
#To match clip frame with whole video frame
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 :
#Encoding index
if transcript['Participant_ID'] == 2:
encode_num = 1
else:
encode_num = 2
start = (transcript['Start_Frame']+frame_num)//6 #Index starts from 0
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 #20fps*60s
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 !')
#SAVE
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)