{"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":"# inspiration: https://www.kaggle.com/odins0n/updated-ultramnist-image-resizer-512x512?scriptVersionId=90198749","metadata":{"execution":{"iopub.status.busy":"2022-03-16T09:13:26.351144Z","iopub.execute_input":"2022-03-16T09:13:26.351890Z","iopub.status.idle":"2022-03-16T09:13:26.369596Z","shell.execute_reply.started":"2022-03-16T09:13:26.351793Z","shell.execute_reply":"2022-03-16T09:13:26.368961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from PIL import Image\nimport shutil\nfrom pathlib import Path\n\n\nTARGET_SIZE = (250,)*2\nFILTER = Image.LANCZOS\nTRAIN_DIR = Path(\"../input/ultra-mnist/train/\")\nTEST_DIR = Path(\"../input/ultra-mnist/test/\")\nTARGET_TRAIN = Path(\"train/\")\nTARGET_TEST = Path(\"test/\")\n\n\nTARGET_TRAIN.mkdir(exist_ok=True)\nTARGET_TEST.mkdir(exist_ok=True)\ntrain_images = TRAIN_DIR.glob(\"**/*.jpeg\")\ntest_images = TEST_DIR.glob(\"**/*.jpeg\")\n\n\nfor path in train_images:\n    im = Image.open(path)\n    im_resized = im.resize(size=TARGET_SIZE, resample=FILTER)\n    im_resized.save(TARGET_TRAIN/path.name)\n\nassert len(list(TRAIN_DIR.glob(\"**/*.jpeg\"))) == len(list(TARGET_TRAIN.glob(\"**/*.jpeg\")))\nprint(\"Train Images done!!! \")\n\n\nfor path in test_images:\n    im = Image.open(path)\n    im_resized = im.resize(size=TARGET_SIZE, resample=FILTER)\n    im_resized.save(TARGET_TEST/path.name)\n    \nassert len(list(TEST_DIR.glob(\"**/*.jpeg\"))) == len(list(TARGET_TEST.glob(\"**/*.jpeg\")))\nprint(\"Test Images done!!! \")\n\nsource = [\n    \"../input/ultra-mnist/sample_submission.csv\",\n    \"../input/ultra-mnist/train.csv\",\n]\ndestination = \"./\"\nfor files in source:\n    shutil.copy2(files, destination)\nprint(\"DONE!!! \")","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-03-15T21:50:26.137792Z","iopub.execute_input":"2022-03-15T21:50:26.138136Z","iopub.status.idle":"2022-03-15T21:51:14.487877Z","shell.execute_reply.started":"2022-03-15T21:50:26.138103Z","shell.execute_reply":"2022-03-15T21:51:14.486602Z"},"trusted":true},"execution_count":null,"outputs":[]}]}