{"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 albumentations as A\nfrom albumentations.core.composition import Compose, OneOf\nfrom albumentations.augmentations.transforms import CLAHE, GaussNoise, ISONoise\nfrom albumentations.pytorch import ToTensorV2\nimport matplotlib.pyplot as plt\nfrom torchvision import transforms as T\nfrom PIL import Image\nimport cv2\nimport os\nfrom tqdm import tqdm","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imgResize = A.SmallestMaxSize(max_size=384,p=cv2.INTER_CUBIC)\ndef resize_images(path_in:str, path_out:str, filenames:list):\n    if not os.path.isdir(path_out): os.mkdir(path_out)\n    for filename in tqdm(filenames):\n        image = cv2.imread(os.path.join(path_in, filename) )\n        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n        image_resized = imgResize(image=image)['image']\n        save_to = os.path.join(path_out, filename)\n        image_resized = cv2.cvtColor(image_resized, cv2.COLOR_RGB2BGR)\n        if not cv2.imwrite(filename=save_to, img=image_resized):\n            print(f'Failed to save image: {filename} to dir:{path_out}')","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"root_dir = '../input/plant-pathology-2021-fgvc8/train_images'\nout_dir = './resize-plant-384'\nresize_images(root_dir,out_dir,os.listdir(root_dir))","metadata":{},"execution_count":null,"outputs":[]}]}