| import json | |
| import pdb | |
| import re | |
| from tqdm import tqdm | |
| data = json.load(open('/mnt/petrelfs/wangzehan/data/MGrounding-630k/Group_Grounding/gg_train_120k.json', 'r')) | |
| llava_data = [] | |
| idx = 0 | |
| for item in tqdm(data): | |
| conv = item['conversations'] | |
| for i in range(len(conv)//2): | |
| question = conv[2*i]['value'] | |
| answer = conv[2*i+1]['value'] | |
| caption = question.split('<|object_ref_start|>')[-1].split('<|object_ref_end|>')[0] | |
| if "It's in the first image" in answer: | |
| gt = 'The object is located at: Frame-1: ' | |
| elif "It's in the second image" in answer: | |
| gt = 'The object is located at: Frame-1: ' | |
| elif "It's in the third image" in answer: | |
| gt = 'The object is located at: Frame-3: ' | |
| elif "It's in the fourth image" in answer: | |
| gt = 'The object is located at: Frame-4: ' | |
| elif "It's in the fifth image" in answer: | |
| gt = 'The object is located at: Frame-5: ' | |
| coords_str = re.findall(r'(\d+)', answer) | |
| coords_list = [round(int(coord)/1000, 2) for coord in coords_str] | |
| gt += str(coords_list) | |
| llava_item = {"id": idx, | |
| "video": item['images'], | |
| "conversations": [{"value": f"<image> Identify the object according to the following description.\n {caption}", "from": "human"}, \ | |
| {"value": gt, "from": "gpt"}], | |
| "metadata": {"dataset": "MGrounding_refer"}} | |
| llava_data.append(llava_item) | |
| idx += 1 | |
| pdb.set_trace() | |
| json.dump(llava_data, open('extra_data/annotation/MGrounding_group_grounding_llava_format.json', 'w')) |