{"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_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import shutil\nimport numpy as np\nimport pandas as pd\nimport os\n\nimport cv2\nfrom tqdm import tqdm\n\nfrom joblib import Parallel, delayed","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-03-20T10:47:12.353043Z","iopub.execute_input":"2022-03-20T10:47:12.353585Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv(\"../input/happy-whale-and-dolphin/train.csv\")","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"NEW_SIZE = (128, 128) # (height, width)\nINTERPOLATION = cv2.INTER_CUBIC","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def load_and_write(path, image, output_path):\n    img = cv2.imread(path)\n    img = cv2.resize(img, NEW_SIZE[::-1], interpolation=INTERPOLATION)\n    cv2.imwrite(os.path.join(output_path , image), img)\n    \ndef create_resized_images(image_path, image_output_path):\n    image_list = os.listdir(image_path)\n    Parallel(n_jobs=20)(\n        delayed(load_and_write)(\n            os.path.join(image_path, image),\n            image,\n            image_output_path\n        ) for image in tqdm(image_list)\n    )","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def resize_images(input_folder, output_folder):\n    os.makedirs(output_folder)\n    create_resized_images(input_folder, output_folder)\n    shutil.make_archive(f\"{output_folder}_zip\", 'zip', output_folder)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_path = \"../input/happy-whale-and-dolphin/train_images\"\ntrain_image_output_path = f\"/kaggle/working/train_images_{NEW_SIZE[0]}\"\n\nresize_images(train_image_path, train_image_output_path)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_image_path = \"../input/happy-whale-and-dolphin/test_images\"\ntest_image_output_path = f\"/kaggle/working/test_images_{NEW_SIZE[0]}\"\n\nresize_images(test_image_path, test_image_output_path)","metadata":{},"execution_count":null,"outputs":[]}]}