{ "cells": [ { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "import os\n", "import json\n", "train_dir = \"/home/bingxuan/VDA/data/INAT/all_data/train/\"\n", "test_dir = \"/home/bingxuan/VDA/data/INAT/all_data/test/\"\n", "working_dir = \"/home/bingxuan/VDA/data/INAT/subset_6\"\n", "\n", "configs_path = working_dir + \"/config.json\"\n", "with open(configs_path, \"r\") as f:\n", " configs = json.load(f)\n", " \n", "paths = configs[\"pairs\"]\n", "\n", "# for pair in paths:\n", "# path_1 = train_dir + pair[\"ground_truth_full_name\"]\n", "# if not os.path.exists(path_1):\n", "# print(f\"ERROR: {path_1} does not exist\")\n", "# print(f\"{path_1}: {len(os.listdir(path_1))}\")\n", " \n", "# path_4 = test_dir + pair[\"ground_truth_full_name\"]\n", "# if not os.path.exists(path_4):\n", "# print(f\"ERROR: {path_4} does not exist\")\n", "# print(f\"{path_4}: {len(os.listdir(path_4))}\")\n", " \n", "# path_2 = train_dir + pair[\"confusing_class_full_name\"]\n", "# if not os.path.exists(path_2):\n", "# print(f\"ERROR: {path_2} does not exist\")\n", "# print(f\"{path_2}: {len(os.listdir(path_2))}\")\n", " \n", "# path_3 = test_dir + pair[\"confusing_class_full_name\"]\n", "# if not os.path.exists(path_3):\n", "# print(f\"ERROR: {path_3} does not exist\")\n", "# print(f\"{path_3}: {len(os.listdir(path_3))}\")\n", " " ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "copied /home/bingxuan/VDA/data/INAT/all_data/train/04440_Animalia_Chordata_Aves_Piciformes_Picidae_Dryobates_minor to /home/bingxuan/VDA/data/INAT/subset_6/train/04440_Animalia_Chordata_Aves_Piciformes_Picidae_Dryobates_minor\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04455_Animalia_Chordata_Aves_Piciformes_Picidae_Melanerpes_lewis to /home/bingxuan/VDA/data/INAT/subset_6/train/04455_Animalia_Chordata_Aves_Piciformes_Picidae_Melanerpes_lewis\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04455_Animalia_Chordata_Aves_Piciformes_Picidae_Melanerpes_lewis to /home/bingxuan/VDA/data/INAT/subset_6/val/04455_Animalia_Chordata_Aves_Piciformes_Picidae_Melanerpes_lewis\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04440_Animalia_Chordata_Aves_Piciformes_Picidae_Dryobates_minor to /home/bingxuan/VDA/data/INAT/subset_6/val/04440_Animalia_Chordata_Aves_Piciformes_Picidae_Dryobates_minor\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04243_Animalia_Chordata_Aves_Passeriformes_Thraupidae_Tersina_viridis to /home/bingxuan/VDA/data/INAT/subset_6/train/04243_Animalia_Chordata_Aves_Passeriformes_Thraupidae_Tersina_viridis\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04373_Animalia_Chordata_Aves_Pelecaniformes_Ardeidae_Egretta_caerulea to /home/bingxuan/VDA/data/INAT/subset_6/train/04373_Animalia_Chordata_Aves_Pelecaniformes_Ardeidae_Egretta_caerulea\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04373_Animalia_Chordata_Aves_Pelecaniformes_Ardeidae_Egretta_caerulea to /home/bingxuan/VDA/data/INAT/subset_6/val/04373_Animalia_Chordata_Aves_Pelecaniformes_Ardeidae_Egretta_caerulea\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04243_Animalia_Chordata_Aves_Passeriformes_Thraupidae_Tersina_viridis to /home/bingxuan/VDA/data/INAT/subset_6/val/04243_Animalia_Chordata_Aves_Passeriformes_Thraupidae_Tersina_viridis\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04074_Animalia_Chordata_Aves_Passeriformes_Parulidae_Setophaga_fusca to /home/bingxuan/VDA/data/INAT/subset_6/train/04074_Animalia_Chordata_Aves_Passeriformes_Parulidae_Setophaga_fusca\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04074_Animalia_Chordata_Aves_Passeriformes_Parulidae_Setophaga_fusca to /home/bingxuan/VDA/data/INAT/subset_6/val/04074_Animalia_Chordata_Aves_Passeriformes_Parulidae_Setophaga_fusca\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04377_Animalia_Chordata_Aves_Pelecaniformes_Ardeidae_Egretta_sacra to /home/bingxuan/VDA/data/INAT/subset_6/train/04377_Animalia_Chordata_Aves_Pelecaniformes_Ardeidae_Egretta_sacra\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04377_Animalia_Chordata_Aves_Pelecaniformes_Ardeidae_Egretta_sacra to /home/bingxuan/VDA/data/INAT/subset_6/val/04377_Animalia_Chordata_Aves_Pelecaniformes_Ardeidae_Egretta_sacra\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04570_Animalia_Chordata_Aves_Suliformes_Phalacrocoracidae_Microcarbo_melanoleucos to /home/bingxuan/VDA/data/INAT/subset_6/train/04570_Animalia_Chordata_Aves_Suliformes_Phalacrocoracidae_Microcarbo_melanoleucos\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04570_Animalia_Chordata_Aves_Suliformes_Phalacrocoracidae_Microcarbo_melanoleucos to /home/bingxuan/VDA/data/INAT/subset_6/val/04570_Animalia_Chordata_Aves_Suliformes_Phalacrocoracidae_Microcarbo_melanoleucos\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04837_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Neotamias_minimus to /home/bingxuan/VDA/data/INAT/subset_6/train/04837_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Neotamias_minimus\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04836_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Neotamias_merriami to /home/bingxuan/VDA/data/INAT/subset_6/train/04836_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Neotamias_merriami\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04836_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Neotamias_merriami to /home/bingxuan/VDA/data/INAT/subset_6/val/04836_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Neotamias_merriami\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04837_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Neotamias_minimus to /home/bingxuan/VDA/data/INAT/subset_6/val/04837_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Neotamias_minimus\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04741_Animalia_Chordata_Mammalia_Diprotodontia_Phalangeridae_Trichosurus_vulpecula to /home/bingxuan/VDA/data/INAT/subset_6/train/04741_Animalia_Chordata_Mammalia_Diprotodontia_Phalangeridae_Trichosurus_vulpecula\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04716_Animalia_Chordata_Mammalia_Carnivora_Procyonidae_Bassariscus_astutus to /home/bingxuan/VDA/data/INAT/subset_6/train/04716_Animalia_Chordata_Mammalia_Carnivora_Procyonidae_Bassariscus_astutus\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04716_Animalia_Chordata_Mammalia_Carnivora_Procyonidae_Bassariscus_astutus to /home/bingxuan/VDA/data/INAT/subset_6/val/04716_Animalia_Chordata_Mammalia_Carnivora_Procyonidae_Bassariscus_astutus\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04741_Animalia_Chordata_Mammalia_Diprotodontia_Phalangeridae_Trichosurus_vulpecula to /home/bingxuan/VDA/data/INAT/subset_6/val/04741_Animalia_Chordata_Mammalia_Diprotodontia_Phalangeridae_Trichosurus_vulpecula\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04780_Animalia_Chordata_Mammalia_Primates_Cebidae_Callithrix_penicillata to /home/bingxuan/VDA/data/INAT/subset_6/train/04780_Animalia_Chordata_Mammalia_Primates_Cebidae_Callithrix_penicillata\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04780_Animalia_Chordata_Mammalia_Primates_Cebidae_Callithrix_penicillata to /home/bingxuan/VDA/data/INAT/subset_6/val/04780_Animalia_Chordata_Mammalia_Primates_Cebidae_Callithrix_penicillata\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04821_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Callospermophilus_lateralis to /home/bingxuan/VDA/data/INAT/subset_6/train/04821_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Callospermophilus_lateralis\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04821_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Callospermophilus_lateralis to /home/bingxuan/VDA/data/INAT/subset_6/val/04821_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Callospermophilus_lateralis\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04746_Animalia_Chordata_Mammalia_Eulipotyphla_Erinaceidae_Erinaceus_roumanicus to /home/bingxuan/VDA/data/INAT/subset_6/train/04746_Animalia_Chordata_Mammalia_Eulipotyphla_Erinaceidae_Erinaceus_roumanicus\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04811_Animalia_Chordata_Mammalia_Rodentia_Hystricidae_Hystrix_africaeaustralis to /home/bingxuan/VDA/data/INAT/subset_6/train/04811_Animalia_Chordata_Mammalia_Rodentia_Hystricidae_Hystrix_africaeaustralis\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04811_Animalia_Chordata_Mammalia_Rodentia_Hystricidae_Hystrix_africaeaustralis to /home/bingxuan/VDA/data/INAT/subset_6/val/04811_Animalia_Chordata_Mammalia_Rodentia_Hystricidae_Hystrix_africaeaustralis\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04746_Animalia_Chordata_Mammalia_Eulipotyphla_Erinaceidae_Erinaceus_roumanicus to /home/bingxuan/VDA/data/INAT/subset_6/val/04746_Animalia_Chordata_Mammalia_Eulipotyphla_Erinaceidae_Erinaceus_roumanicus\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04845_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Sciurus_granatensis to /home/bingxuan/VDA/data/INAT/subset_6/train/04845_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Sciurus_granatensis\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04845_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Sciurus_granatensis to /home/bingxuan/VDA/data/INAT/subset_6/val/04845_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Sciurus_granatensis\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04802_Animalia_Chordata_Mammalia_Rodentia_Cricetidae_Neotoma_fuscipes to /home/bingxuan/VDA/data/INAT/subset_6/train/04802_Animalia_Chordata_Mammalia_Rodentia_Cricetidae_Neotoma_fuscipes\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04794_Animalia_Chordata_Mammalia_Rodentia_Castoridae_Castor_canadensis to /home/bingxuan/VDA/data/INAT/subset_6/train/04794_Animalia_Chordata_Mammalia_Rodentia_Castoridae_Castor_canadensis\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04794_Animalia_Chordata_Mammalia_Rodentia_Castoridae_Castor_canadensis to /home/bingxuan/VDA/data/INAT/subset_6/val/04794_Animalia_Chordata_Mammalia_Rodentia_Castoridae_Castor_canadensis\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04802_Animalia_Chordata_Mammalia_Rodentia_Cricetidae_Neotoma_fuscipes to /home/bingxuan/VDA/data/INAT/subset_6/val/04802_Animalia_Chordata_Mammalia_Rodentia_Cricetidae_Neotoma_fuscipes\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04825_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Funambulus_palmarum to /home/bingxuan/VDA/data/INAT/subset_6/train/04825_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Funambulus_palmarum\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04857_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Xerospermophilus_tereticaudus to /home/bingxuan/VDA/data/INAT/subset_6/train/04857_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Xerospermophilus_tereticaudus\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04857_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Xerospermophilus_tereticaudus to /home/bingxuan/VDA/data/INAT/subset_6/val/04857_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Xerospermophilus_tereticaudus\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04825_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Funambulus_palmarum to /home/bingxuan/VDA/data/INAT/subset_6/val/04825_Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Funambulus_palmarum\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04791_Animalia_Chordata_Mammalia_Primates_Cercopithecidae_Trachypithecus_obscurus to /home/bingxuan/VDA/data/INAT/subset_6/train/04791_Animalia_Chordata_Mammalia_Primates_Cercopithecidae_Trachypithecus_obscurus\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04779_Animalia_Chordata_Mammalia_Primates_Atelidae_Ateles_geoffroyi to /home/bingxuan/VDA/data/INAT/subset_6/train/04779_Animalia_Chordata_Mammalia_Primates_Atelidae_Ateles_geoffroyi\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04779_Animalia_Chordata_Mammalia_Primates_Atelidae_Ateles_geoffroyi to /home/bingxuan/VDA/data/INAT/subset_6/val/04779_Animalia_Chordata_Mammalia_Primates_Atelidae_Ateles_geoffroyi\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04791_Animalia_Chordata_Mammalia_Primates_Cercopithecidae_Trachypithecus_obscurus to /home/bingxuan/VDA/data/INAT/subset_6/val/04791_Animalia_Chordata_Mammalia_Primates_Cercopithecidae_Trachypithecus_obscurus\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04696_Animalia_Chordata_Mammalia_Carnivora_Mustelidae_Martes_foina to /home/bingxuan/VDA/data/INAT/subset_6/train/04696_Animalia_Chordata_Mammalia_Carnivora_Mustelidae_Martes_foina\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04702_Animalia_Chordata_Mammalia_Carnivora_Mustelidae_Pekania_pennanti to /home/bingxuan/VDA/data/INAT/subset_6/train/04702_Animalia_Chordata_Mammalia_Carnivora_Mustelidae_Pekania_pennanti\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04702_Animalia_Chordata_Mammalia_Carnivora_Mustelidae_Pekania_pennanti to /home/bingxuan/VDA/data/INAT/subset_6/val/04702_Animalia_Chordata_Mammalia_Carnivora_Mustelidae_Pekania_pennanti\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04696_Animalia_Chordata_Mammalia_Carnivora_Mustelidae_Martes_foina to /home/bingxuan/VDA/data/INAT/subset_6/val/04696_Animalia_Chordata_Mammalia_Carnivora_Mustelidae_Martes_foina\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04667_Animalia_Chordata_Mammalia_Artiodactyla_Tayassuidae_Pecari_tajacu to /home/bingxuan/VDA/data/INAT/subset_6/train/04667_Animalia_Chordata_Mammalia_Artiodactyla_Tayassuidae_Pecari_tajacu\n", "copied /home/bingxuan/VDA/data/INAT/all_data/train/04731_Animalia_Chordata_Mammalia_Cingulata_Dasypodidae_Dasypus_novemcinctus to /home/bingxuan/VDA/data/INAT/subset_6/train/04731_Animalia_Chordata_Mammalia_Cingulata_Dasypodidae_Dasypus_novemcinctus\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04731_Animalia_Chordata_Mammalia_Cingulata_Dasypodidae_Dasypus_novemcinctus to /home/bingxuan/VDA/data/INAT/subset_6/val/04731_Animalia_Chordata_Mammalia_Cingulata_Dasypodidae_Dasypus_novemcinctus\n", "copied /home/bingxuan/VDA/data/INAT/all_data/test/04667_Animalia_Chordata_Mammalia_Artiodactyla_Tayassuidae_Pecari_tajacu to /home/bingxuan/VDA/data/INAT/subset_6/val/04667_Animalia_Chordata_Mammalia_Artiodactyla_Tayassuidae_Pecari_tajacu\n" ] } ], "source": [ "# cp train and test data to working dir\n", "import shutil\n", "\n", "for pair in paths:\n", " path_1 = train_dir + pair[\"ground_truth_full_name\"]\n", " path_2 = train_dir + pair[\"confusing_class_full_name\"]\n", " path_3 = test_dir + pair[\"confusing_class_full_name\"]\n", " path_4 = test_dir + pair[\"ground_truth_full_name\"]\n", " \n", " if not os.path.exists(working_dir + '/train/' + pair['ground_truth_full_name']):\n", " shutil.copytree(path_1, working_dir + '/train/' + pair['ground_truth_full_name'])\n", " print(f\"copied {path_1} to {working_dir + '/train/' + pair['ground_truth_full_name']}\")\n", " if not os.path.exists(working_dir + '/train/' + pair['confusing_class_full_name']):\n", " shutil.copytree(path_2, working_dir + '/train/' + pair['confusing_class_full_name'])\n", " print(f\"copied {path_2} to {working_dir + '/train/' + pair['confusing_class_full_name']}\")\n", " if not os.path.exists(working_dir + '/val/' + pair['confusing_class_full_name']): \n", " shutil.copytree(path_3, working_dir + '/val/' + pair['confusing_class_full_name'])\n", " print(f\"copied {path_3} to {working_dir + '/val/' + pair['confusing_class_full_name']}\")\n", " if not os.path.exists(working_dir + '/val/' + pair['ground_truth_full_name']):\n", " shutil.copytree(path_4, working_dir + '/val/' + pair['ground_truth_full_name'])\n", " print(f\"copied {path_4} to {working_dir + '/val/' + pair['ground_truth_full_name']}\")" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "# import random\n", "# import shutil\n", "\n", "# train_num_imgs = 70\n", "# val_num_imgs = 30\n", "\n", "# for pair in paths:\n", "# path_1 = home_dir + pair[\"ground_truth_full_name\"]\n", "# os.makedirs(working_dir + \"/train\" + pair[\"ground_truth_full_name\"], exist_ok=True)\n", "# os.makedirs(working_dir + \"/val\" + pair[\"ground_truth_full_name\"], exist_ok=True)\n", "# images = os.listdir(path_1)\n", "# random.shuffle(images)\n", "# for img in images[:train_num_imgs]:\n", "# shutil.copy(path_1 + \"/\" + img, working_dir + \"/train\" + pair[\"ground_truth_full_name\"] + \"/\" + img)\n", "# for img in images[train_num_imgs:train_num_imgs+val_num_imgs]:\n", "# shutil.copy(path_1 + \"/\" + img, working_dir + \"/val\" + pair[\"ground_truth_full_name\"] + \"/\" + img)\n", "\n", "# path_2 = home_dir + pair[\"confusing_class_full_name\"]\n", "# os.makedirs(working_dir + \"/train\" + pair[\"confusing_class_full_name\"], exist_ok=True)\n", "# os.makedirs(working_dir + \"/val\" + pair[\"confusing_class_full_name\"], exist_ok=True)\n", "# images = os.listdir(path_2)\n", "# random.shuffle(images)\n", "# for img in images[:train_num_imgs]:\n", "# shutil.copy(path_2 + \"/\" + img, working_dir + \"/train\" + pair[\"confusing_class_full_name\"] + \"/\" + img)\n", "# for img in images[train_num_imgs:train_num_imgs+val_num_imgs]:\n", "# shutil.copy(path_2 + \"/\" + img, working_dir + \"/val\" + pair[\"confusing_class_full_name\"] + \"/\" + img)" ] } ], "metadata": { "kernelspec": { "display_name": "visual_data_aug", "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.10.14" } }, "nbformat": 4, "nbformat_minor": 2 }