{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":13836,"databundleVersionId":1718836,"sourceType":"competition"}],"dockerImageVersionId":30626,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport json\nimport shutil\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-12-22T09:37:00.543699Z","iopub.execute_input":"2023-12-22T09:37:00.544140Z","iopub.status.idle":"2023-12-22T09:37:00.550100Z","shell.execute_reply.started":"2023-12-22T09:37:00.544108Z","shell.execute_reply":"2023-12-22T09:37:00.548844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/cassava-leaf-disease-classification/train.csv')\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2023-12-22T09:37:00.578864Z","iopub.execute_input":"2023-12-22T09:37:00.579277Z","iopub.status.idle":"2023-12-22T09:37:00.609997Z","shell.execute_reply.started":"2023-12-22T09:37:00.579246Z","shell.execute_reply":"2023-12-22T09:37:00.608715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f = open('/kaggle/input/cassava-leaf-disease-classification/label_num_to_disease_map.json')\nmapping = json.load(f)\nmapping","metadata":{"execution":{"iopub.status.busy":"2023-12-22T09:37:00.611919Z","iopub.execute_input":"2023-12-22T09:37:00.612275Z","iopub.status.idle":"2023-12-22T09:37:00.619840Z","shell.execute_reply.started":"2023-12-22T09:37:00.612243Z","shell.execute_reply":"2023-12-22T09:37:00.618834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i, row in df.iterrows():\n    label = row.label\n    id = row.image_id\n\n    source_dir = f\"/kaggle/input/cassava-leaf-disease-classification/train_images/{id}\"\n    destination_dir = f\"/kaggle/working/data/\"\n\n    # Map label to disease category\n    disease_mapping = {\n        0: 'Cassava___bacterial_blight',\n        1: 'Cassava___brown_streak_disease',\n        2: 'Cassava___green_mottle',\n        3: 'Cassava___mosaic_disease',\n        4: 'Cassava___healthy'\n    }\n\n    # Get the disease category based on the label\n    category = disease_mapping.get(label, 'Unknown')\n\n    # Create the destination directory if it doesn't exist\n    category_dir = os.path.join(destination_dir, category)\n    os.makedirs(category_dir, exist_ok=True)\n\n    # Copy the image to the destination directory\n    shutil.copyfile(source_dir, os.path.join(category_dir, id))","metadata":{"execution":{"iopub.status.busy":"2023-12-22T09:37:00.626126Z","iopub.execute_input":"2023-12-22T09:37:00.626493Z","iopub.status.idle":"2023-12-22T09:40:39.973329Z","shell.execute_reply.started":"2023-12-22T09:37:00.626463Z","shell.execute_reply":"2023-12-22T09:40:39.972406Z"},"trusted":true},"execution_count":null,"outputs":[]}]}