Upload LLaVA-Next-3D/data_precessing/MGrounding_process.py with huggingface_hub
Browse files
LLaVA-Next-3D/data_precessing/MGrounding_process.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import pdb
|
| 3 |
+
import re
|
| 4 |
+
from tqdm import tqdm
|
| 5 |
+
|
| 6 |
+
data = json.load(open('/mnt/petrelfs/wangzehan/data/MGrounding-630k/Group_Grounding/gg_train_120k.json', 'r'))
|
| 7 |
+
|
| 8 |
+
llava_data = []
|
| 9 |
+
|
| 10 |
+
idx = 0
|
| 11 |
+
|
| 12 |
+
for item in tqdm(data):
|
| 13 |
+
conv = item['conversations']
|
| 14 |
+
|
| 15 |
+
for i in range(len(conv)//2):
|
| 16 |
+
question = conv[2*i]['value']
|
| 17 |
+
answer = conv[2*i+1]['value']
|
| 18 |
+
|
| 19 |
+
caption = question.split('<|object_ref_start|>')[-1].split('<|object_ref_end|>')[0]
|
| 20 |
+
if "It's in the first image" in answer:
|
| 21 |
+
gt = 'The object is located at: Frame-1: '
|
| 22 |
+
elif "It's in the second image" in answer:
|
| 23 |
+
gt = 'The object is located at: Frame-1: '
|
| 24 |
+
elif "It's in the third image" in answer:
|
| 25 |
+
gt = 'The object is located at: Frame-3: '
|
| 26 |
+
elif "It's in the fourth image" in answer:
|
| 27 |
+
gt = 'The object is located at: Frame-4: '
|
| 28 |
+
elif "It's in the fifth image" in answer:
|
| 29 |
+
gt = 'The object is located at: Frame-5: '
|
| 30 |
+
|
| 31 |
+
coords_str = re.findall(r'(\d+)', answer)
|
| 32 |
+
coords_list = [round(int(coord)/1000, 2) for coord in coords_str]
|
| 33 |
+
gt += str(coords_list)
|
| 34 |
+
|
| 35 |
+
llava_item = {"id": idx,
|
| 36 |
+
"video": item['images'],
|
| 37 |
+
"conversations": [{"value": f"<image> Identify the object according to the following description.\n {caption}", "from": "human"}, \
|
| 38 |
+
{"value": gt, "from": "gpt"}],
|
| 39 |
+
"metadata": {"dataset": "MGrounding_refer"}}
|
| 40 |
+
llava_data.append(llava_item)
|
| 41 |
+
idx += 1
|
| 42 |
+
|
| 43 |
+
pdb.set_trace()
|
| 44 |
+
json.dump(llava_data, open('extra_data/annotation/MGrounding_group_grounding_llava_format.json', 'w'))
|