{"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 os\nimport cv2\nimport glob\nfrom joblib import Parallel, delayed\nfrom tqdm import tqdm_notebook as tqdm","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-03-15T16:56:38.639924Z","iopub.execute_input":"2022-03-15T16:56:38.640669Z","iopub.status.idle":"2022-03-15T16:56:38.644698Z","shell.execute_reply.started":"2022-03-15T16:56:38.640634Z","shell.execute_reply":"2022-03-15T16:56:38.643872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class CFG:\n    train_path = '../input/ultra-mnist/train/'\n    test_path = '../input/ultra-mnist/test/'\n    train_out_path = 'train_img/'\n    test_out_path = 'test_img/'\n    size = 512\n    ","metadata":{"execution":{"iopub.status.busy":"2022-03-10T13:56:48.529393Z","iopub.execute_input":"2022-03-10T13:56:48.529649Z","iopub.status.idle":"2022-03-10T13:56:48.536885Z","shell.execute_reply.started":"2022-03-10T13:56:48.529621Z","shell.execute_reply":"2022-03-10T13:56:48.535912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def convert_images(filename, outdir):\n    image = cv2.imread(filename)\n    img = cv2.resize(image, (CFG.size, CFG.size))\n    cv2.imwrite(outdir + filename.split('/')[-1][:-5] + '.jpeg', img)","metadata":{"execution":{"iopub.status.busy":"2022-03-10T13:56:48.538294Z","iopub.execute_input":"2022-03-10T13:56:48.538631Z","iopub.status.idle":"2022-03-10T13:56:48.548258Z","shell.execute_reply.started":"2022-03-10T13:56:48.538588Z","shell.execute_reply":"2022-03-10T13:56:48.547207Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# create the lists for training and test files\ntrain_list = glob.glob(os.path.join(CFG.train_path,  '*.jpeg'))\ntest_list = glob.glob(os.path.join(CFG.test_path,  '*.jpeg'))","metadata":{"execution":{"iopub.status.busy":"2022-03-10T13:56:48.551091Z","iopub.execute_input":"2022-03-10T13:56:48.551442Z","iopub.status.idle":"2022-03-10T13:56:50.106832Z","shell.execute_reply.started":"2022-03-10T13:56:48.551397Z","shell.execute_reply":"2022-03-10T13:56:50.105899Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"if not os.path.exists(CFG.train_out_path):\n    os.makedirs(CFG.train_out_path)\nif not os.path.exists(CFG.test_out_path):\n    os.makedirs(CFG.test_out_path)","metadata":{"execution":{"iopub.status.busy":"2022-03-10T13:56:50.108517Z","iopub.execute_input":"2022-03-10T13:56:50.108837Z","iopub.status.idle":"2022-03-10T13:56:50.113761Z","shell.execute_reply.started":"2022-03-10T13:56:50.108794Z","shell.execute_reply":"2022-03-10T13:56:50.113159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# process the train images\nres1 = Parallel(n_jobs=8, backend='threading')(delayed(\n    convert_images)(i, CFG.train_out_path) for i in tqdm(train_list, total=len(train_list)))","metadata":{"execution":{"iopub.status.busy":"2022-03-10T13:57:50.093085Z","iopub.execute_input":"2022-03-10T13:57:50.093936Z","iopub.status.idle":"2022-03-10T13:57:52.768716Z","shell.execute_reply.started":"2022-03-10T13:57:50.093889Z","shell.execute_reply":"2022-03-10T13:57:52.767776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# process the test images\nres2 = Parallel(n_jobs=8, backend='threading')(delayed(\n    convert_images)(i, CFG.test_out_path) for i in tqdm(test_list, total=len(test_list)))","metadata":{"execution":{"iopub.status.busy":"2022-03-10T13:57:53.672361Z","iopub.execute_input":"2022-03-10T13:57:53.672853Z","iopub.status.idle":"2022-03-10T13:57:56.344766Z","shell.execute_reply.started":"2022-03-10T13:57:53.672821Z","shell.execute_reply":"2022-03-10T13:57:56.343814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!zip -r rescaled.zip ./train_img/ ./test_img/","metadata":{"execution":{"iopub.status.busy":"2022-03-10T13:58:09.609582Z","iopub.execute_input":"2022-03-10T13:58:09.610717Z","iopub.status.idle":"2022-03-10T13:58:10.515644Z","shell.execute_reply.started":"2022-03-10T13:58:09.610668Z","shell.execute_reply":"2022-03-10T13:58:10.514472Z"},"trusted":true},"execution_count":null,"outputs":[]}]}