{"cells":[{"metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.execute_input":"2020-11-28T12:25:26.931393Z","iopub.status.busy":"2020-11-28T12:25:26.930307Z","iopub.status.idle":"2020-11-28T12:25:59.179092Z","shell.execute_reply":"2020-11-28T12:25:59.178203Z"},"papermill":{"duration":32.26246,"end_time":"2020-11-28T12:25:59.179224","exception":false,"start_time":"2020-11-28T12:25:26.916764","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"!pip install lycon -q\n!mkdir \"train_images\"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport lycon\nfrom pathlib import Path\nfrom joblib import Parallel, delayed\nfrom tqdm.notebook import tqdm","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"IMAGE_SIZE = 384","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def resize_and_save(image_path, target_image_size, target_path):\n    \"\"\"\n        1. read image from `image_path`\n        2. resize the image to `target_image_size` * `target_image_size`\n        3. save the image at `target_path`\n    \"\"\"\n    image = lycon.load(image_path)\n    image = lycon.resize(image=image, height=target_image_size, width=target_image_size)\n    image_name = image_path.split(\"/\")[-1]\n    lycon.save(path=f\"{target_path}/{image_name}\", image=image)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"%%time\nsomething = Parallel(n_jobs=8, backend=\"multiprocessing\")(\n    delayed(resize_and_save)(str(image_path), IMAGE_SIZE, \"train_images\") for image_path in tqdm(Path(\"../input/cassava-leaf-disease-classification/train_images/\").iterdir())\n)","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}