File size: 1,664 Bytes
c2a0942
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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'))