{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.7.10","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":13032,"databundleVersionId":862545,"sourceType":"competition"}],"dockerImageVersionId":30120,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\"\"\"\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\"\"\"\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport gc\nimport sys\nimport jsonimport glob\nimport random\nfrom pathlib import Path\n\nimport cv2\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\n\nimport itertools\nfrom tqdm import tqdm\n\nfrom imgaug import augmenters as iaa\nfrom sklearn.model_selection import StratifiedKFold, KFold","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nfrom skimage import io\nfrom skimage.filters import gaussian\nimport zipfile\nfrom io import BytesIO\nimport os\n\n# Function to downsample and blur the image\ndef downsample_and_blur(img, skip, sigma=1):\n    downscaled_img = img[::skip, ::skip]\n    blurred_img = gaussian(downscaled_img, sigma=sigma, preserve_range=True)\n    return blurred_img.astype(np.uint8)\n\n# Directory where test images are located\ninput_directory = \"/kaggle/input/imaterialist-fashion-2019-FGVC6/test/\"\n\n# List all files in the directory\nfiles = os.listdir(input_directory)\n\n# Process images and save into a zip file\nzip_buffer = BytesIO()\nwith zipfile.ZipFile(zip_buffer, 'a', compression=zipfile.ZIP_DEFLATED) as zip_file:\n    skip = 7\n    sigma = 0.5\n    for img_index, filename in enumerate(files):\n        # Read image\n        img_path = os.path.join(input_directory, filename)\n        img = io.imread(img_path)\n        # Save original image\n        original_filename = f\"img{img_index + 1}.jpg\"\n        io.imsave(original_filename, img)\n        zip_file.write(original_filename)\n        # Process image\n        blurred_img = downsample_and_blur(img, skip, sigma)\n        # Save processed image\n        processed_filename = f\"img{img_index + 1}_processed.jpg\"\n        io.imsave(processed_filename, blurred_img)\n        zip_file.write(processed_filename)\n\n# Save the zip file\noutput_zip_filename = '/kaggle/working/processed_images.zip'\nwith open(output_zip_filename, 'wb') as f:\n    f.write(zip_buffer.getvalue())\n","metadata":{"execution":{"iopub.status.busy":"2024-04-24T18:50:29.491352Z","iopub.execute_input":"2024-04-24T18:50:29.491727Z","iopub.status.idle":"2024-04-24T19:15:02.508793Z","shell.execute_reply.started":"2024-04-24T18:50:29.491689Z","shell.execute_reply":"2024-04-24T19:15:02.507263Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"working progress","metadata":{}},{"cell_type":"code","source":"# Directory where the processed images are located\ndirectory = '/kaggle/working/'\n\n# List all files in the directory\nfiles = os.listdir(directory)\n\n# Download each file\nfor filename in files:\n    files.download(os.path.join(directory, filename))","metadata":{"execution":{"iopub.status.busy":"2024-04-24T19:17:32.158744Z","iopub.execute_input":"2024-04-24T19:17:32.159133Z","iopub.status.idle":"2024-04-24T19:17:32.183465Z","shell.execute_reply.started":"2024-04-24T19:17:32.159097Z","shell.execute_reply":"2024-04-24T19:17:32.182069Z"},"trusted":true},"execution_count":null,"outputs":[]}]}