-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathconvert2llama.py
47 lines (38 loc) · 1.52 KB
/
convert2llama.py
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
45
46
47
import numpy as np
import json
def convert2llama(root, dst):
with open(root, 'r') as f:
test_file = json.load(f)
output = []
for scene_id in test_file.keys():
scene_data = test_file[scene_id]['key_frames']
for frame_id in scene_data.keys():
image_paths = scene_data[frame_id]['image_paths']
image_paths = [image_paths[key].replace("..", "data") for key in image_paths.keys()]
frame_data_qa = scene_data[frame_id]['QA']
QA_pairs = frame_data_qa["perception"] + frame_data_qa["prediction"] + frame_data_qa["planning"] + frame_data_qa["behavior"]
for idx, qa in enumerate(QA_pairs):
question = qa['Q']
answer = qa['A']
output.append(
{
"id": scene_id + "_" + frame_id + "_" + str(idx),
"image": image_paths,
"conversations": [
{
"from": "human",
"value": "<image>\n" + question
},
{
"from": "gpt",
"value": answer
},
]
}
)
with open(dst, 'w') as f:
json.dump(output, f, indent=4)
if __name__ == '__main__':
root = "test_eval.json"
dst = "test_llama.json"
convert2llama(root, dst)