{"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 numpy as np\nimport pandas as pd\nimport os\nimport fastai\nfrom fastai.vision.all import *\nfrom pathlib import Path","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = Path('../input/plant-pathology-2021-fgvc8')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.DataFrame(columns=['image', 'labels'])\ntest","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_x(r): return path/'train_images'/r['image']\ndef get_y(r): return r['labels'].split(' ')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pathlib\nplt = platform.system()\nif plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn_inf = load_learner('../input/pp2021model/export2.pkl')\nlearn_inf.metrics = partial(accuracy_multi, thresh=0.45)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = Path('../input/plant-pathology-2021-fgvc8/test_images/')\nwith learn_inf.no_bar(), learn_inf.no_logging():\n    for filename in os.listdir(path):\n            if filename.endswith('.jpg'):\n                image = Image.open('../input/plant-pathology-2021-fgvc8/test_images/'+str(filename))\n                image = np.asarray(image)\n                prediction = learn_inf.predict(image)\n                df = pd.DataFrame([[filename, ' '.join(prediction[0])]],\n                                    columns=['image', 'labels'])\n                test = test.append(df)\n        ","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.to_csv(r'./submission.csv', index = False)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}