|
|
import json |
|
|
from collections import defaultdict |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process_ego4d_annotations(json_file_path, output_json_path=None): |
|
|
|
|
|
with open(json_file_path, 'r') as f: |
|
|
data = json.load(f) |
|
|
|
|
|
|
|
|
grouped = {} |
|
|
|
|
|
for entry in data: |
|
|
vid = entry['video_id'] |
|
|
|
|
|
if vid not in grouped: |
|
|
|
|
|
grouped[vid] = { |
|
|
'caption': entry['caption'], |
|
|
'frames': [] |
|
|
} |
|
|
|
|
|
frame_path = entry['image_path'].replace("videos", "frames") |
|
|
mask_path = entry['mask'] |
|
|
|
|
|
grouped[vid]['frames'].append({ |
|
|
'frame_path': frame_path, |
|
|
'mask_path': mask_path, |
|
|
'points': entry['clicked_points'] |
|
|
}) |
|
|
|
|
|
|
|
|
if output_json_path: |
|
|
with open(output_json_path, 'w') as outf: |
|
|
json.dump(grouped, outf, indent=2) |
|
|
|
|
|
return grouped |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
input_json = '/share/data/drive_1/heakl/benchmark/annotated/autonomous_driving/autonomous_annot.json' |
|
|
output_json = '/share/data/drive_1/heakl/benchmark/annotated/autonomous_driving/autonomous_new.json' |
|
|
|
|
|
grouped_dict = process_ego4d_annotations(input_json, output_json) |
|
|
|
|
|
import pprint |
|
|
pprint.pprint(grouped_dict) |