{"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":"# 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\n# import os\n# for 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","execution":{"iopub.status.busy":"2022-03-27T13:49:58.783385Z","iopub.execute_input":"2022-03-27T13:49:58.784144Z","iopub.status.idle":"2022-03-27T13:49:58.808451Z","shell.execute_reply.started":"2022-03-27T13:49:58.784045Z","shell.execute_reply":"2022-03-27T13:49:58.807763Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Crop Dataset Logic","metadata":{}},{"cell_type":"code","source":"from itertools import product\n\ndef crops(image):\n    \"\"\"Given a PIL Image of shape 2000, 2000. Crop it into quadrants and return.\"\"\"\n    w, h = image.size\n    d = 2000 # num of splits per width and height\n    cropped_images = []\n\n    # Crop image into 4 equal parts\n    grid = product(range(0, h-h%d, d), range(0, w-w%d, d))\n    for i, j in grid:\n        box = (j, i, j+d, i+d)\n        cropped_images.append(image.crop(box))\n    \n    return cropped_images\n","metadata":{"execution":{"iopub.status.busy":"2022-03-27T19:58:16.052123Z","iopub.execute_input":"2022-03-27T19:58:16.052979Z","iopub.status.idle":"2022-03-27T19:58:16.060935Z","shell.execute_reply.started":"2022-03-27T19:58:16.052893Z","shell.execute_reply":"2022-03-27T19:58:16.059741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! mkdir -p train test","metadata":{"execution":{"iopub.status.busy":"2022-03-27T19:56:26.926797Z","iopub.execute_input":"2022-03-27T19:56:26.927126Z","iopub.status.idle":"2022-03-27T19:56:27.722838Z","shell.execute_reply.started":"2022-03-27T19:56:26.927092Z","shell.execute_reply":"2022-03-27T19:56:27.721671Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from PIL import Image\nfrom tqdm import tqdm\nimport os\n\nIMAGE_DIR = '../input/ultra-mnist/train/'\n\n\nfor filename in tqdm(os.listdir(IMAGE_DIR)):\n    _crops = crops(Image.open(f'{IMAGE_DIR}/{filename}'))\n    for index, _crop in enumerate(_crops):\n        _crop.save(f'train/{filename[:-5]}_{index}.jpeg')","metadata":{"execution":{"iopub.status.busy":"2022-03-27T20:00:16.553881Z","iopub.execute_input":"2022-03-27T20:00:16.55591Z","iopub.status.idle":"2022-03-27T20:00:19.551963Z","shell.execute_reply.started":"2022-03-27T20:00:16.555803Z","shell.execute_reply":"2022-03-27T20:00:19.54991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! pwd && ls ./","metadata":{"execution":{"iopub.status.busy":"2022-03-28T06:18:08.095343Z","iopub.execute_input":"2022-03-28T06:18:08.095955Z","iopub.status.idle":"2022-03-28T06:18:08.857873Z","shell.execute_reply.started":"2022-03-28T06:18:08.095909Z","shell.execute_reply":"2022-03-28T06:18:08.856646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# %%capture\n# !pip install colabcode","metadata":{"execution":{"iopub.status.busy":"2022-03-27T15:19:20.397205Z","iopub.execute_input":"2022-03-27T15:19:20.397467Z","iopub.status.idle":"2022-03-27T15:19:54.83201Z","shell.execute_reply.started":"2022-03-27T15:19:20.39744Z","shell.execute_reply":"2022-03-27T15:19:54.831123Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ! ngrok authtoken 22V09woIHTaBLAilQSMOZHonMqB_7Ee3wcWPfVgD9fyoLpnGv","metadata":{"execution":{"iopub.status.busy":"2022-03-27T15:19:54.833887Z","iopub.execute_input":"2022-03-27T15:19:54.834177Z","iopub.status.idle":"2022-03-27T15:19:58.906403Z","shell.execute_reply.started":"2022-03-27T15:19:54.834141Z","shell.execute_reply":"2022-03-27T15:19:58.905588Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# from colabcode import ColabCode\n# ColabCode()","metadata":{"execution":{"iopub.status.busy":"2022-03-27T15:19:58.908079Z","iopub.execute_input":"2022-03-27T15:19:58.908383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}