{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "76f1322a", "metadata": {}, "outputs": [], "source": [ "import json\n", "import pandas as pd\n", "from collections import defaultdict" ] }, { "cell_type": "code", "execution_count": null, "id": "17c8145d", "metadata": {}, "outputs": [], "source": [ "vqa_valid = json.load(open('/labels/multiple_choice/multiple_choice_val.json'))" ] }, { "cell_type": "code", "execution_count": null, "id": "47b5d81b", "metadata": {}, "outputs": [], "source": [ "vqa_dict = defaultdict(list)\n", "qid = 0\n", "\n", "for vqa_row in vqa_valid:\n", " image_id = vqa_row['image']\n", " messages = vqa_row['conversations']\n", "\n", " for i in range(0, len(messages), 2):\n", " assert messages[i]['from'] == 'human'\n", " vqa_dict['image_id'].append(image_id)\n", " vqa_dict['qid'].append(qid)\n", " vqa_dict['question'].append(messages[i]['value'])\n", " vqa_dict['answer'].append(messages[i+1]['value'])\n", " qid += 1\n", "vqa_df = pd.DataFrame(vqa_dict)\n", "vqa_df" ] }, { "cell_type": "code", "execution_count": null, "id": "0b53e080", "metadata": {}, "outputs": [], "source": [ "vqa_df.to_csv('/labels/multiple_choice/multiple_choice_valid.csv', index=False)" ] } ], "metadata": { "kernelspec": { "display_name": "eval", "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.12.0" } }, "nbformat": 4, "nbformat_minor": 5 }