File size: 2,338 Bytes
a32ffc4 |
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This file is to convert ScanQA to LLaVA-3D dataset format. Ref: https://github.com/ZCMax/LLaVA-3D/issues/5"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# load json and show\n",
"import json\n",
"import os\n",
"\n",
"data = json.load(open('ScanQA_v1.0_train.json'))\n",
"# print(json.dumps(data, indent=4))\n",
"\n",
"# {\"answers\": [\"brown cabinet with tv sitting in it\"], \n",
"# \"object_ids\": [8], \n",
"# \"object_names\": [\"cabinet\"], \n",
"# \"question\": \"What is in the right corner of room by curtains?\", \n",
"# \"question_id\": \"train-scene0000-0\", \n",
"# \"scene_id\": \"scene0000_00\"},\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"\n",
"# Read the input JSON file\n",
"with open('ScanQA_v1.0_train.json', 'r') as f:\n",
" data = json.load(f)\n",
"\n",
"output = []\n",
"\n",
"for entry in data:\n",
" conversation = {\n",
" \"id\": entry['object_ids'][0],\n",
" \"video\": f\"scannet/{entry['scene_id']}\",\n",
" \"conversations\": [\n",
" {\n",
" \"from\": \"human\",\n",
" \"value\": f\"<video>\\n{entry['question']}\"\n",
" },\n",
" {\n",
" \"from\": \"gpt\",\n",
" \"value\": entry['answers'][0].capitalize() + '.'\n",
" }\n",
" ]\n",
" }\n",
" output.append(conversation)\n",
"\n",
"# Write the output to a JSON file\n",
"with open('LLaVA_canQA_v1.0_train.json', 'w') as f:\n",
" json.dump(output, f, indent=4)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|