Junfeng5 commited on
Commit
fe6a6e3
1 Parent(s): 5ced654

Upload convert_ytvis2tao.py

Browse files
Files changed (1) hide show
  1. annotations/convert_ytvis2tao.py +82 -0
annotations/convert_ytvis2tao.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import argparse
3
+
4
+
5
+
6
+
7
+ def parse_args():
8
+ parser = argparse.ArgumentParser("D2 model converter")
9
+
10
+ parser.add_argument("--results", default="", type=str, help="Path to the GLEE output dir ")
11
+ parser.add_argument("--refer", default="", type=str, help="Path to the BURST annotation val dir")
12
+
13
+ return parser.parse_args()
14
+
15
+
16
+ def main():
17
+ args = parse_args()
18
+
19
+ ori_anno = json.load(open(args.results,'rb'))
20
+
21
+ reference_anno = json.load(open(args.refer,'rb'))
22
+
23
+
24
+ num_tracks = 0
25
+ num_miss_video = 0
26
+
27
+
28
+ id_mapping = {}
29
+
30
+ for i, cate_info in enumerate(reference_anno['categories']):
31
+ new_id = i
32
+ old_id = cate_info['id']
33
+ id_mapping.update({new_id:old_id})
34
+
35
+
36
+ ref_sequences_dict = {}
37
+ for ref in reference_anno['sequences']:
38
+ ref_sequences_dict[ref['id']] = ref
39
+
40
+
41
+ # ids = [v['category_id'] for v in ori_anno]
42
+
43
+ sequences_dict = {}
44
+
45
+ for seg in ori_anno:
46
+ vid = seg['video_id']
47
+ if vid not in sequences_dict.keys():
48
+ # import pdb;pdb.set_trace()
49
+ sequences_dict[vid] = {
50
+ 'id': vid,
51
+ 'width': ref_sequences_dict[vid]['width'],
52
+ 'height': ref_sequences_dict[vid]['height'],
53
+ 'seq_name': ref_sequences_dict[vid]['seq_name'],
54
+ 'dataset': ref_sequences_dict[vid]['dataset'],
55
+ 'annotated_image_paths': ref_sequences_dict[vid]['annotated_image_paths'],
56
+ 'fps': ref_sequences_dict[vid]['fps'],
57
+ 'segmentations': [{} for i in range(len(seg['segmentations']))],
58
+ 'track_category_ids': {},
59
+ }
60
+ track_id = str(len(sequences_dict[vid]['track_category_ids']) + 1)
61
+
62
+ for frame, rles in enumerate(seg['segmentations']):
63
+ sequences_dict[vid]['segmentations'][frame][track_id] = {'rle': rles['counts'], 'score':seg['score']}
64
+ # import pdb;pdb.set_trace()
65
+ sequences_dict[vid]['track_category_ids'][track_id] = id_mapping[seg['category_id']]
66
+
67
+
68
+ results = {'sequences':[]}
69
+ for k,v in sequences_dict.items():
70
+ results['sequences'].append(v)
71
+
72
+
73
+ with open('converted_tao_results.json', 'w') as f:
74
+ json.dump(results, f)
75
+
76
+
77
+
78
+ if __name__ == "__main__":
79
+ main()
80
+
81
+
82
+