File size: 2,835 Bytes
fb5d697
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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)