{"cells":[{"metadata":{},"cell_type":"markdown","source":"## Resizing images to 20% of orignal size","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"#### Since the orignal train size is ~48GB, I'm doing 20% so as to reduce it to ~10GB in order to fit to kaggle kernel for training\n#### You can adjust the ratio as per your need in the 2nd cell\n#### Feel free to provide your feedback and better ways of doing this","execution_count":null},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport os\nimport cv2\nimport matplotlib.pyplot as plt\nfrom pathlib import Path\nimport time","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"x_size = 0.2\ny_size = 0.2","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"os.getcwd()\nos.listdir('../input/landmark-recognition-2020/')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train = pd.read_csv('../input/landmark-recognition-2020/train.csv')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Resizing the images and saving them in the folders as per their category\n#### I'm doing it just for the 1st subfolder due to computation constraints on kaggle kernel, you can edit line 5 in the below cell","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"start = time.time()\n\nfor d1 in os.listdir('../input/landmark-recognition-2020/train/'):\n    print(\"d1:\", d1)\n    for d2 in os.listdir('../input/landmark-recognition-2020/train/'+d1+'/')[0]:\n        print(\"d2:\",d2)\n        for d3 in os.listdir('../input/landmark-recognition-2020/train/'+d1+'/'+d2+'/'):\n            print(\"d3:\",d3)\n            for i in os.listdir('../input/landmark-recognition-2020/train/'+d1+'/'+d2+'/'+d3+'/'):\n                img = cv2.imread('../input/landmark-recognition-2020/train/'+d1+'/'+d2+'/'+d3+'/'+i)\n                small = cv2.resize(img, (0,0), fx=x_size, fy=y_size)\n                target = str(train[train['id'] == i.replace('.jpg','')].landmark_id.values[0])\n                \n                Path(str(target)).mkdir(parents=True, exist_ok=True)\n                cv2.imwrite(os.path.join(target,i), small)\n        \nend = time.time()\nprint(end - start)","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}