{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "4835cc14", "metadata": {}, "outputs": [], "source": [ "import os\n", "import json\n", "from itertools import combinations\n", "IMAGE_DIR = \"/root/siton-tmp/images_divided\"" ] }, { "cell_type": "code", "execution_count": 3, "id": "5bdfe87c", "metadata": {}, "outputs": [], "source": [ "data_file = 'data/extended_data_summary_v2.jsonl'\n", "with open(data_file, 'r') as f:\n", " data = [json.loads(line) for line in f]\n", "\n", "data_2by2 = [\n", " item for item in data if item['layout'] == '2x2'\n", "]\n", "with open('data/2by2_data_summary.jsonl', 'w') as f:\n", " for item in data_2by2:\n", " f.write(json.dumps(item) + '\\n')" ] }, { "cell_type": "code", "execution_count": null, "id": "fb8c9036", "metadata": {}, "outputs": [], "source": [ "folders = sorted([\n", " f for f in os.listdir(IMAGE_DIR)\n", " if os.path.isdir(os.path.join(IMAGE_DIR, f)) and not f.startswith('.')\n", "])\n", "data = []\n", "for cnt, idx in enumerate(folders):\n", " folder_path = os.path.join(IMAGE_DIR, idx)\n", " images = sorted([img for img in os.listdir(folder_path) if img.endswith('.png')])\n", " first_indices, second_indices = zip(*[\n", " list(map(int, img.split('.')[0].split('_')))\n", " for img in images\n", " ])\n", " first_indices = sorted(set(first_indices))\n", " second_indices = sorted(set(second_indices))\n", " \n", " for i in first_indices:\n", " for j in second_indices:\n", " ref_img = f\"{i}_{j}.png\"\n", " candidates = [\n", " [\n", " f\"{x}_{y}.png\"\n", " for x in first_indices\n", " ]\n", " for y in second_indices if y != j\n", " ]\n", " items = [\n", " {\n", " 'ref_image': ref_img,\n", " 'rank_images': cand,\n", " 'idx': idx,\n", " } for cand in candidates\n", " ]\n", " data.extend(items)\n" ] }, { "cell_type": "code", "execution_count": 19, "id": "36e0603b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'ref_image': '0_0.png',\n", " 'rank_images': ['0_1.png', '1_1.png', '2_1.png', '3_1.png'],\n", " 'idx': '0000'},\n", " {'ref_image': '0_0.png',\n", " 'rank_images': ['0_2.png', '1_2.png', '2_2.png', '3_2.png'],\n", " 'idx': '0000'},\n", " {'ref_image': '0_1.png',\n", " 'rank_images': ['0_0.png', '1_0.png', '2_0.png', '3_0.png'],\n", " 'idx': '0000'},\n", " {'ref_image': '0_1.png',\n", " 'rank_images': ['0_2.png', '1_2.png', '2_2.png', '3_2.png'],\n", " 'idx': '0000'},\n", " {'ref_image': '0_2.png',\n", " 'rank_images': ['0_0.png', '1_0.png', '2_0.png', '3_0.png'],\n", " 'idx': '0000'},\n", " {'ref_image': '0_2.png',\n", " 'rank_images': ['0_1.png', '1_1.png', '2_1.png', '3_1.png'],\n", " 'idx': '0000'},\n", " {'ref_image': '1_0.png',\n", " 'rank_images': ['0_1.png', '1_1.png', '2_1.png', '3_1.png'],\n", " 'idx': '0000'},\n", " {'ref_image': '1_0.png',\n", " 'rank_images': ['0_2.png', '1_2.png', '2_2.png', '3_2.png'],\n", " 'idx': '0000'},\n", " {'ref_image': '1_1.png',\n", " 'rank_images': ['0_0.png', '1_0.png', '2_0.png', '3_0.png'],\n", " 'idx': '0000'},\n", " {'ref_image': '1_1.png',\n", " 'rank_images': ['0_2.png', '1_2.png', '2_2.png', '3_2.png'],\n", " 'idx': '0000'}]" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data[:10]" ] } ], "metadata": { "kernelspec": { "display_name": "pbw-torch-env", "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.11" } }, "nbformat": 4, "nbformat_minor": 5 }