{"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 # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\nimport sys","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-06-21T15:53:39.696487Z","iopub.execute_input":"2021-06-21T15:53:39.696855Z","iopub.status.idle":"2021-06-21T15:53:39.701139Z","shell.execute_reply.started":"2021-06-21T15:53:39.69682Z","shell.execute_reply":"2021-06-21T15:53:39.700166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from fastai.vision import *\nfrom fastai.vision.all import *\nfrom fastai.vision.core import *\nfrom fastai.vision.data import *","metadata":{"execution":{"iopub.status.busy":"2021-06-21T15:53:39.702696Z","iopub.execute_input":"2021-06-21T15:53:39.703255Z","iopub.status.idle":"2021-06-21T15:53:39.714572Z","shell.execute_reply.started":"2021-06-21T15:53:39.703217Z","shell.execute_reply":"2021-06-21T15:53:39.713642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nimport fastai\nprint(torch.__version__)\nprint(torch.cuda.is_available())\nprint(fastai.__version__)","metadata":{"execution":{"iopub.status.busy":"2021-06-21T15:53:39.715797Z","iopub.execute_input":"2021-06-21T15:53:39.717501Z","iopub.status.idle":"2021-06-21T15:53:39.731519Z","shell.execute_reply.started":"2021-06-21T15:53:39.717464Z","shell.execute_reply":"2021-06-21T15:53:39.730541Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = Path('../input/plant-pathology-2021-fgvc8')","metadata":{"execution":{"iopub.status.busy":"2021-06-21T15:53:39.733078Z","iopub.execute_input":"2021-06-21T15:53:39.733635Z","iopub.status.idle":"2021-06-21T15:53:39.740906Z","shell.execute_reply.started":"2021-06-21T15:53:39.7336Z","shell.execute_reply":"2021-06-21T15:53:39.740079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df= pd.read_csv(path/'train.csv')\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T15:53:39.743584Z","iopub.execute_input":"2021-06-21T15:53:39.743926Z","iopub.status.idle":"2021-06-21T15:53:39.776792Z","shell.execute_reply.started":"2021-06-21T15:53:39.743899Z","shell.execute_reply":"2021-06-21T15:53:39.775804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_x(x): return path/'test_images'/x['image']\ndef get_y(y): return y['labels']","metadata":{"execution":{"iopub.status.busy":"2021-06-21T15:53:39.77876Z","iopub.execute_input":"2021-06-21T15:53:39.779094Z","iopub.status.idle":"2021-06-21T15:53:39.783486Z","shell.execute_reply.started":"2021-06-21T15:53:39.779059Z","shell.execute_reply":"2021-06-21T15:53:39.782409Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"m = '../input/mylearner/learnerf1_0798.pkl'","metadata":{"execution":{"iopub.status.busy":"2021-06-21T16:01:31.625391Z","iopub.execute_input":"2021-06-21T16:01:31.625803Z","iopub.status.idle":"2021-06-21T16:01:31.629768Z","shell.execute_reply.started":"2021-06-21T16:01:31.625760Z","shell.execute_reply":"2021-06-21T16:01:31.628897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample = pd.read_csv(path/'sample_submission.csv')\nsample","metadata":{"execution":{"iopub.status.busy":"2021-06-21T15:53:39.79639Z","iopub.execute_input":"2021-06-21T15:53:39.796692Z","iopub.status.idle":"2021-06-21T15:53:39.818433Z","shell.execute_reply.started":"2021-06-21T15:53:39.796649Z","shell.execute_reply":"2021-06-21T15:53:39.817624Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = 0\nlearner = load_learner(m, cpu=False)\ntest_dl = learner.dls.test_dl(sample)\npreds, _ = learner.tta(dl=test_dl)\npredictions += preds\npredictions","metadata":{"execution":{"iopub.status.busy":"2021-06-21T15:53:39.821143Z","iopub.execute_input":"2021-06-21T15:53:39.822686Z","iopub.status.idle":"2021-06-21T15:53:44.184224Z","shell.execute_reply.started":"2021-06-21T15:53:39.822627Z","shell.execute_reply":"2021-06-21T15:53:44.183311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vocab = learner.dls.vocab\npreds_dec = [vocab[i] for i in predictions.argmax(1)]\npreds_dec","metadata":{"execution":{"iopub.status.busy":"2021-06-21T15:53:44.185666Z","iopub.execute_input":"2021-06-21T15:53:44.186077Z","iopub.status.idle":"2021-06-21T15:53:44.193072Z","shell.execute_reply.started":"2021-06-21T15:53:44.186035Z","shell.execute_reply":"2021-06-21T15:53:44.192001Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample['labels'] = preds_dec\nsample.to_csv('submission.csv',index=False)\nsample","metadata":{"execution":{"iopub.status.busy":"2021-06-21T15:53:44.195019Z","iopub.execute_input":"2021-06-21T15:53:44.195365Z","iopub.status.idle":"2021-06-21T15:53:44.213738Z","shell.execute_reply.started":"2021-06-21T15:53:44.195328Z","shell.execute_reply":"2021-06-21T15:53:44.213004Z"},"trusted":true},"execution_count":null,"outputs":[]}]}