|
|
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 video in data: |
|
|
video_id = video['video_id'] |
|
|
caption = video['frames'][0]['caption'] |
|
|
|
|
|
frames = [] |
|
|
for frame in video['frames']: |
|
|
print(frame) |
|
|
frame_data = { |
|
|
"frame_path": frame['image_path'].replace('/home/shehan/workspace_grounding_lmm/Hanan/segment-anything-2/VideoGUI-High-Plan/video_gui_frames', 'videogui/frames/'), |
|
|
"mask_path": frame['mask'].replace('/home/shehan/workspace_grounding_lmm/Hanan/segment-anything-2/VideoGUI-High-Plan/', 'videogui/') \ |
|
|
if frame['mask'] is not None else frame['mask'], |
|
|
"points": [point[:2] for point in frame['clicked_points']] |
|
|
} |
|
|
frames.append(frame_data) |
|
|
|
|
|
grouped[video_id] = { |
|
|
"caption": caption, |
|
|
"frames": frames |
|
|
} |
|
|
|
|
|
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/videogui_data/VideoGUI_final.json' |
|
|
output_json = '/share/data/drive_1/heakl/benchmark/annotated/videogui_data/annotations.json' |
|
|
|
|
|
grouped_dict = process_ego4d_annotations(input_json, output_json) |
|
|
|
|
|
import pprint |
|
|
pprint.pprint(grouped_dict) |
|
|
|