{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nfrom PIL import Image\nimport os\n\n# read the CSV file into a Pandas DataFrame\ndf = pd.read_csv('/kaggle/input/dog-breed-identification/labels.csv')\n\n# create a dictionary mapping image names to dog breeds\nname_to_breed = dict(zip(df['id'], df['breed']))\n\n# create a new folder to save the labeled images\noutput_folder = '/kaggle/working/labeled_images/'\nif not os.path.exists(output_folder):\n    os.makedirs(output_folder)\n\n# iterate through the images in the folder\ninput_folder = '/kaggle/input/dog-breed-identification/train/'\nfor filename in os.listdir(input_folder):\n    if filename.endswith('.jpg'):\n        # get the dog breed label for the image\n        dog_breed = name_to_breed[filename.split('.')[0]]\n        # open the image file\n        img = Image.open(os.path.join(input_folder, filename))\n        # save the image file with the dog breed label in the filename\n        output_filename = f\"{dog_breed}_{filename}\"\n        img.save(os.path.join(output_folder, output_filename))\n","metadata":{"execution":{"iopub.status.busy":"2023-03-08T23:29:21.156535Z","iopub.execute_input":"2023-03-08T23:29:21.156871Z","iopub.status.idle":"2023-03-08T23:30:49.741149Z","shell.execute_reply.started":"2023-03-08T23:29:21.156842Z","shell.execute_reply":"2023-03-08T23:30:49.740170Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from IPython.display import FileLink\nimport shutil\n\n# create a ZIP archive of the output folder\nshutil.make_archive('labeled_images', 'zip', '/kaggle/working/labeled_images')\n\n# create a download link for the ZIP archive\nFileLink('labeled_images.zip')\n","metadata":{"execution":{"iopub.status.busy":"2023-03-08T23:35:54.584300Z","iopub.execute_input":"2023-03-08T23:35:54.585379Z","iopub.status.idle":"2023-03-08T23:36:09.312551Z","shell.execute_reply.started":"2023-03-08T23:35:54.585332Z","shell.execute_reply":"2023-03-08T23:36:09.311125Z"},"trusted":true},"execution_count":null,"outputs":[]}]}