{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport tensorflow as tf\nimport os\nimport concurrent.futures\nimport time\nimport cv2","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"PATH = '../input/plant-pathology-2021-fgvc8/train_images'\nnamelist = os.listdir(PATH)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"IMSIZE = 256\ndef read_img(image, name):\n    img = cv2.imread(image)\n    img = cv2.resize(img, (IMSIZE, IMSIZE))\n    return img, name\ndef prepare_dataset(namelist, path):\n    start = time.time()\n    names = namelist\n    namelist = [os.path.join(path, ele) for ele in namelist]\n    with concurrent.futures.ThreadPoolExecutor(max_workers = 16) as executor:\n        i = 0\n        for value, name in executor.map(read_img, namelist, names):\n            i+=1\n            print(\"\\rFetching: [{}/{}]\".format(i, len(namelist)), end=\"\", flush=True)\n            cv2.imwrite(name, value)\n    print(\"\\nExecution time: \",time.time() - start, \"s\")\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(\"Reading & Writing...\")\n!mkdir ./train\nwith tf.device('/cpu:0'):\n    path = '../input/plant-pathology-2021-fgvc8/train_images'\n    prepare_dataset(namelist, path)\nprint(\"Finished...\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","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}