{"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":14774,"databundleVersionId":875431,"sourceType":"competition"},{"sourceId":418031,"sourceType":"datasetVersion","datasetId":131128},{"sourceId":2812287,"sourceType":"datasetVersion","datasetId":1719146},{"sourceId":2819730,"sourceType":"datasetVersion","datasetId":1723812},{"sourceId":2823796,"sourceType":"datasetVersion","datasetId":1727005},{"sourceId":5579252,"sourceType":"datasetVersion","datasetId":3211156}],"dockerImageVersionId":30635,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport os\nimport requests\nimport shutil","metadata":{"execution":{"iopub.status.busy":"2024-01-15T06:52:52.959408Z","iopub.execute_input":"2024-01-15T06:52:52.959820Z","iopub.status.idle":"2024-01-15T06:52:53.647189Z","shell.execute_reply.started":"2024-01-15T06:52:52.959786Z","shell.execute_reply":"2024-01-15T06:52:53.646292Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Path to the CSV file containing image addresses and labels\ncsv_file_path = '/kaggle/input/trywithoutindex/train_df_withoutINDEX.csv'\n\n# Output directory to save the downloaded images within Kaggle\noutput_directory_kaggle = \"/kaggle/working/EYES3\"\n\n# Create the output directory within Kaggle if it doesn't exist\nos.makedirs(output_directory_kaggle, exist_ok=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-15T06:56:30.017843Z","iopub.execute_input":"2024-01-15T06:56:30.018405Z","iopub.status.idle":"2024-01-15T06:56:30.024959Z","shell.execute_reply.started":"2024-01-15T06:56:30.018364Z","shell.execute_reply":"2024-01-15T06:56:30.023684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Read the CSV file into a DataFrame\ndf = pd.read_csv(csv_file_path)\n\n# Filter rows where the label is '3'\ndf_label_3 = df[df['diagnosis'] == 3]  # Replace 'label_column' with the actual column name","metadata":{"execution":{"iopub.status.busy":"2024-01-15T06:56:57.905938Z","iopub.execute_input":"2024-01-15T06:56:57.906493Z","iopub.status.idle":"2024-01-15T06:56:58.083910Z","shell.execute_reply.started":"2024-01-15T06:56:57.906449Z","shell.execute_reply":"2024-01-15T06:56:58.082465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_label_3.shape","metadata":{"execution":{"iopub.status.busy":"2024-01-15T06:57:13.114270Z","iopub.execute_input":"2024-01-15T06:57:13.114713Z","iopub.status.idle":"2024-01-15T06:57:13.123068Z","shell.execute_reply.started":"2024-01-15T06:57:13.114682Z","shell.execute_reply":"2024-01-15T06:57:13.122019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_label_3.head(10)","metadata":{"execution":{"iopub.status.busy":"2024-01-15T06:57:50.531756Z","iopub.execute_input":"2024-01-15T06:57:50.532171Z","iopub.status.idle":"2024-01-15T06:57:50.549800Z","shell.execute_reply.started":"2024-01-15T06:57:50.532138Z","shell.execute_reply":"2024-01-15T06:57:50.548221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Loop through each row in the filtered DataFrame\nfor index, row in df_label_3.iterrows():\n    image_relative_path = row['id_code']  # Replace 'image_address_column' with the actual column name\n    label = row['diagnosis']  # Replace 'label_column' with the actual column name\n\n    # Construct the full image path within Kaggle's environment\n    full_image_path_kaggle = image_relative_path\n\n    # Download the image\n    with open(full_image_path_kaggle, 'rb') as file:\n        image_content = file.read()\n\n    # Save the image to the output directory within Kaggle\n    image_filename = f\"{label}_{index}.jpg\"\n    image_filepath = os.path.join(output_directory_kaggle, image_filename)\n\n    with open(image_filepath, 'wb') as file:\n        file.write(image_content)","metadata":{"execution":{"iopub.status.busy":"2024-01-15T06:59:02.546464Z","iopub.execute_input":"2024-01-15T06:59:02.547046Z","iopub.status.idle":"2024-01-15T06:59:16.076126Z","shell.execute_reply.started":"2024-01-15T06:59:02.547001Z","shell.execute_reply":"2024-01-15T06:59:16.074997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Zip the contents of the output directory within Kaggle\nshutil.make_archive(\"/kaggle/working/EYES3_archive\", 'zip', output_directory_kaggle)","metadata":{"execution":{"iopub.status.busy":"2024-01-15T07:03:17.719461Z","iopub.execute_input":"2024-01-15T07:03:17.719942Z","iopub.status.idle":"2024-01-15T07:03:26.591458Z","shell.execute_reply.started":"2024-01-15T07:03:17.719905Z","shell.execute_reply":"2024-01-15T07:03:26.590292Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}