{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":20270,"databundleVersionId":1222630,"sourceType":"competition"}],"dockerImageVersionId":30646,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport cv2\nimport time\nimport pandas as pd\nimport numpy as np\nimport gc\n\nfrom joblib import delayed, Parallel","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-02-26T16:10:42.932895Z","iopub.execute_input":"2024-02-26T16:10:42.933392Z","iopub.status.idle":"2024-02-26T16:10:43.699907Z","shell.execute_reply.started":"2024-02-26T16:10:42.933352Z","shell.execute_reply":"2024-02-26T16:10:43.698522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"N = 16\nH = 512\nW = 512\nC = cv2.COLOR_BGR2RGB\n\nTEST_IMG_PATH = '../input/siim-isic-melanoma-classification/jpeg/test/'\nTRAIN_IMG_PATH = '../input/siim-isic-melanoma-classification/jpeg/train/'\n\ntest_df = pd.read_csv('../input/siim-isic-melanoma-classification/test.csv')\ntrain_df = pd.read_csv('../input/siim-isic-melanoma-classification/train.csv')\n\ndef save_to_zip(out_path):\n    # ZIP & rm -rf (remove) folder\n    if 'test' in out_path:\n        !zip -rq /kaggle/working/test.zip test\n        !rm -rf test\n    if 'train' in out_path:\n        !zip -rq /kaggle/working/train.zip train\n        !rm -rf train\n\ndef save(image_name, in_path, out_path):\n    # Resize image to (512, 512) and save\n    input_read_path = in_path + image_name\n    image = cv2.imread(input_read_path + '.jpg')\n    image = cv2.resize(cv2.cvtColor(image, C), (H, W))\n    output_write_path = out_path + image_name + '.jpg'\n    cv2.imwrite(output_write_path, image)\n    del image\n    gc.collect()\n\nos.makedirs('test', exist_ok=True)\nos.makedirs('train', exist_ok=True)\n\ntest_ids = np.array_split(np.array(test_df.image_name), N)\ntrain_ids = np.array_split(np.array(train_df.image_name), N)\n\nstarttime = time.time()\n\n# Save resized test images to the 'test' folder with multithreading\nParallel(n_jobs=N)(delayed(save)(image_name, TEST_IMG_PATH, 'test/') for ids in test_ids for image_name in ids)\n\n# Save resized train images to the 'train' folder with multithreading\nParallel(n_jobs=N)(delayed(save)(image_name, TRAIN_IMG_PATH, 'train/') for ids in train_ids for image_name in ids)\n\n# Save test images to ZIP\nsave_to_zip(\"test\")\n\n# Save train images to ZIP\nsave_to_zip(\"train\")\n\nendtime = time.time()\nprint(\"Time taken:\", endtime - starttime)\n","metadata":{"execution":{"iopub.status.busy":"2024-02-26T16:10:43.702587Z","iopub.execute_input":"2024-02-26T16:10:43.703237Z","iopub.status.idle":"2024-02-26T17:37:44.490835Z","shell.execute_reply.started":"2024-02-26T16:10:43.703193Z","shell.execute_reply":"2024-02-26T17:37:44.488127Z"},"trusted":true},"execution_count":null,"outputs":[]}]}