File size: 1,598 Bytes
7b76145 |
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 48 49 50 51 52 53 54 55 56 |
import json
# Load the original JSON file
with open('/home/yiyangai/stephenqs/datasets/mehrankazemi___re_mi/default/0.0.0/re_mi-test-02.json', 'r') as f:
data = json.load(f)
# Function to convert the dataset
def convert_format(data):
converted_data = []
for item in data:
new_item = {
"id": item["id"],
"image": None,
"conversations": [
{
"from": "human",
"content": []
},
{
"from": "gpt",
"content": [
{
"text": item["label"],
"image": None
}
]
}
]
}
# Add the main question with the first image
new_item["conversations"][0]["content"].append({
"text": item["question"],
"image": item.get("image_1", None)
})
# If there are more images, add them with null text
for i in range(2, 7):
img_key = f"image_{i}"
if item.get(img_key):
new_item["conversations"][0]["content"].append({
"text": None,
"image": item[img_key]
})
converted_data.append(new_item)
return converted_data
# Convert the dataset
converted_data = convert_format(data)
# Save the converted data to a new JSON file
with open('converted_dataset-02.json', 'w') as f:
json.dump(converted_data, f, indent=4)
|