{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "1cee2087-3df2-4dd5-9fd0-aa1b6f8360eb", "metadata": {}, "outputs": [], "source": [ "# generate the data for Kaggle\n", "# image+image same paper pairs" ] }, { "cell_type": "code", "execution_count": null, "id": "48c8ade3-9b3f-4b60-bf91-a1344fe341cc", "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": null, "id": "807c2870-4398-4b9b-9bb8-6be2790799e8", "metadata": {}, "outputs": [], "source": [ "# add wasp26_lib to python path\n", "import sys\n", "sys.path.append('../')\n", "\n", "from wasp26_lib import *\n", "\n", "# always load tqdm\n", "from tqdm.auto import tqdm" ] }, { "cell_type": "code", "execution_count": null, "id": "16d237e9-0395-4f02-942c-4e7a47365cbb", "metadata": {}, "outputs": [], "source": [ "from datasets import load_dataset" ] }, { "cell_type": "code", "execution_count": null, "id": "6e0ad43e-e0e6-4ac7-b905-1aebc8f2dd33", "metadata": {}, "outputs": [], "source": [ "dataset_train = load_dataset(path='../data/AstroCLIMB_HF/', split='train')\n", "dataset_test = load_dataset(path='../data/AstroCLIMB_HF/', split='test')" ] }, { "cell_type": "code", "execution_count": null, "id": "b8fbacfe-8d70-4aac-a8d0-6b0a78aeaec3", "metadata": {}, "outputs": [], "source": [ "dataset_train" ] }, { "cell_type": "code", "execution_count": null, "id": "6fb1171e-b885-4d30-ba6c-9cff96c1bb3d", "metadata": {}, "outputs": [], "source": [ "dataset_test" ] }, { "cell_type": "code", "execution_count": null, "id": "b4e3d4d8-0f82-4928-86cf-352c70236e25", "metadata": {}, "outputs": [], "source": [ "# load DOI look up dicts\n", "import json" ] }, { "cell_type": "code", "execution_count": null, "id": "f5e3a32d-b75a-4555-9a09-4193eb142ead", "metadata": {}, "outputs": [], "source": [ "with open('../data/AstroCLIMB_HF/doi_lookup_test.json', 'r') as f:\n", " doi_lookup_test = json.load(f)\n", "with open('../data/AstroCLIMB_HF/doi_lookup_train.json', 'r') as f:\n", " doi_lookup_train = json.load(f)" ] }, { "cell_type": "code", "execution_count": null, "id": "35730d63-a5c5-4a6d-acae-c137c5fab5e8", "metadata": {}, "outputs": [], "source": [ "len(doi_lookup_test),len(doi_lookup_train)" ] }, { "cell_type": "code", "execution_count": null, "id": "a99dbe8b-705d-42cf-b287-c524999a8ca3", "metadata": {}, "outputs": [], "source": [ "# extract 1000 pairs of fig+fig same figure " ] }, { "cell_type": "code", "execution_count": null, "id": "582b38a3-9e9f-4c74-859f-c4422abb65db", "metadata": {}, "outputs": [], "source": [ "num_pairs = 1000" ] }, { "cell_type": "code", "execution_count": null, "id": "f73d1c73-d33b-451e-9ced-a285d3bbc6fc", "metadata": {}, "outputs": [], "source": [ "split = 'test'\n", "save_path = f'../data/Kaggle/{num_pairs}_{split}_img_img_same_paper.csv'\n", "\n", "test_pairs = generate_same_paper_img_img_for_kaggle(ds=dataset_test,\n", " doi_lookup=doi_lookup_test,\n", " num_pairs=num_pairs,\n", " max_same_doi=2,\n", " max_attempts=num_pairs*100, seed=845,\n", " save_path=save_path)" ] }, { "cell_type": "code", "execution_count": null, "id": "0597cdb0-3d82-4a29-b95c-78fd0ed46019", "metadata": {}, "outputs": [], "source": [ "split = 'train'\n", "save_path = f'../data/Kaggle/{num_pairs}_{split}_img_img_same_paper.csv'\n", "\n", "train_pairs = generate_same_paper_img_img_for_kaggle(ds=dataset_train,\n", " doi_lookup=doi_lookup_train,\n", " num_pairs=num_pairs,\n", " max_same_doi=1,\n", " max_attempts=num_pairs*100, seed=845,\n", " save_path=save_path)" ] }, { "cell_type": "code", "execution_count": null, "id": "d5ab34f7-d875-4763-b358-10e1fb450f8e", "metadata": {}, "outputs": [], "source": [ "# quick tests\n", "test_pairs" ] }, { "cell_type": "code", "execution_count": null, "id": "6198cf90-6946-4ee9-aacb-94160e96a269", "metadata": {}, "outputs": [], "source": [ "# test load the csv" ] }, { "cell_type": "code", "execution_count": null, "id": "21dcb5c2-3e98-4221-9ab6-2dec6b233622", "metadata": {}, "outputs": [], "source": [ "from datasets import Dataset" ] }, { "cell_type": "code", "execution_count": null, "id": "57f33e0c-b0c0-4d02-af80-f39dfbe8c7ee", "metadata": {}, "outputs": [], "source": [ "# reload csv\n", "reloaded_csv = Dataset.from_csv(save_path)" ] }, { "cell_type": "code", "execution_count": null, "id": "4d7fccfc-d31f-4df5-95a6-82468d743d8a", "metadata": {}, "outputs": [], "source": [ "reloaded_csv" ] }, { "cell_type": "code", "execution_count": null, "id": "15372649-7551-490b-93df-5b1043b4a99d", "metadata": {}, "outputs": [], "source": [ "convert_str_to_PIL(reloaded_csv[0]['obj_1'])" ] }, { "cell_type": "code", "execution_count": null, "id": "6aa1d5a0-b4df-4df1-897a-5005118ffba5", "metadata": {}, "outputs": [], "source": [ "convert_str_to_PIL(reloaded_csv[0]['obj_2'])" ] }, { "cell_type": "code", "execution_count": null, "id": "a6f7283e-b766-4e86-b869-97e7dc43273d", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "py3.11 (WASP2026)", "language": "python", "name": "py3.11_wasp26" }, "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.11.6" } }, "nbformat": 4, "nbformat_minor": 5 }