{"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 pandas as pd\nimport numpy as np\nimport fastai\nfrom fastai.vision.all import *\nimport dill","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","papermill":{"duration":2.729458,"end_time":"2021-05-17T18:02:06.020362","exception":false,"start_time":"2021-05-17T18:02:03.290904","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-05-23T10:40:27.909209Z","iopub.execute_input":"2021-05-23T10:40:27.909573Z","iopub.status.idle":"2021-05-23T10:40:27.915356Z","shell.execute_reply.started":"2021-05-23T10:40:27.909539Z","shell.execute_reply":"2021-05-23T10:40:27.914384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fastai.__version__, torch.__version__","metadata":{"papermill":{"duration":0.019217,"end_time":"2021-05-17T18:02:06.048395","exception":false,"start_time":"2021-05-17T18:02:06.029178","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-05-23T10:40:27.920357Z","iopub.execute_input":"2021-05-23T10:40:27.920668Z","iopub.status.idle":"2021-05-23T10:40:27.928495Z","shell.execute_reply.started":"2021-05-23T10:40:27.920639Z","shell.execute_reply":"2021-05-23T10:40:27.927641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.read_csv('../input/hotel-id-2021-fgvc8/sample_submission.csv')\n\ntest = submission.copy()\n\ntest['image'] = '../input/hotel-id-2021-fgvc8/test_images/' + test['image']\ntest","metadata":{"papermill":{"duration":0.040143,"end_time":"2021-05-17T18:02:06.120698","exception":false,"start_time":"2021-05-17T18:02:06.080555","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-05-23T10:40:27.930885Z","iopub.execute_input":"2021-05-23T10:40:27.931149Z","iopub.status.idle":"2021-05-23T10:40:27.950642Z","shell.execute_reply.started":"2021-05-23T10:40:27.931122Z","shell.execute_reply":"2021-05-23T10:40:27.94974Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn = load_learner(fname = Path('../input/hotel-train-fastai-densnet161/export_dn161_kaggle_notebook.pkl'), cpu=False, pickle_module=dill) #.to_fp32()","metadata":{"papermill":{"duration":7.075333,"end_time":"2021-05-17T18:02:13.205231","exception":false,"start_time":"2021-05-17T18:02:06.129898","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-05-23T10:40:27.952494Z","iopub.execute_input":"2021-05-23T10:40:27.952765Z","iopub.status.idle":"2021-05-23T10:40:28.924114Z","shell.execute_reply.started":"2021-05-23T10:40:27.952739Z","shell.execute_reply":"2021-05-23T10:40:28.923154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_dl = learn.dls.test_dl(test)","metadata":{"papermill":{"duration":0.025872,"end_time":"2021-05-17T18:02:13.240731","exception":false,"start_time":"2021-05-17T18:02:13.214859","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-05-23T10:40:28.925569Z","iopub.execute_input":"2021-05-23T10:40:28.926182Z","iopub.status.idle":"2021-05-23T10:40:28.954399Z","shell.execute_reply.started":"2021-05-23T10:40:28.926143Z","shell.execute_reply":"2021-05-23T10:40:28.953475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#test_dl.after_batch #item","metadata":{"papermill":{"duration":0.015463,"end_time":"2021-05-17T18:02:13.265504","exception":false,"start_time":"2021-05-17T18:02:13.250041","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-05-23T10:40:28.959635Z","iopub.execute_input":"2021-05-23T10:40:28.961709Z","iopub.status.idle":"2021-05-23T10:40:28.966748Z","shell.execute_reply.started":"2021-05-23T10:40:28.961669Z","shell.execute_reply":"2021-05-23T10:40:28.965773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_dl.show_batch() ","metadata":{"papermill":{"duration":1.554848,"end_time":"2021-05-17T18:02:14.82984","exception":false,"start_time":"2021-05-17T18:02:13.274992","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-05-23T10:40:28.970821Z","iopub.execute_input":"2021-05-23T10:40:28.973154Z","iopub.status.idle":"2021-05-23T10:40:29.826703Z","shell.execute_reply.started":"2021-05-23T10:40:28.973112Z","shell.execute_reply":"2021-05-23T10:40:29.825791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"probs, _ = learn.tta(dl=test_dl)","metadata":{"papermill":{"duration":4.251918,"end_time":"2021-05-17T18:02:19.094703","exception":false,"start_time":"2021-05-17T18:02:14.842785","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-05-23T10:40:29.830979Z","iopub.execute_input":"2021-05-23T10:40:29.833183Z","iopub.status.idle":"2021-05-23T10:40:32.743657Z","shell.execute_reply.started":"2021-05-23T10:40:29.833139Z","shell.execute_reply":"2021-05-23T10:40:32.742856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds_idx = probs.topk(5)[1]","metadata":{"papermill":{"duration":0.022867,"end_time":"2021-05-17T18:02:19.131695","exception":false,"start_time":"2021-05-17T18:02:19.108828","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-05-23T10:40:32.745344Z","iopub.execute_input":"2021-05-23T10:40:32.745725Z","iopub.status.idle":"2021-05-23T10:40:32.750256Z","shell.execute_reply.started":"2021-05-23T10:40:32.745687Z","shell.execute_reply":"2021-05-23T10:40:32.749426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds = [' '.join(map(str, learn.dls.vocab[pred])) for pred in preds_idx]\npreds[:5]","metadata":{"papermill":{"duration":0.023538,"end_time":"2021-05-17T18:02:19.201682","exception":false,"start_time":"2021-05-17T18:02:19.178144","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-05-23T10:40:32.763108Z","iopub.execute_input":"2021-05-23T10:40:32.763452Z","iopub.status.idle":"2021-05-23T10:40:32.775608Z","shell.execute_reply.started":"2021-05-23T10:40:32.763415Z","shell.execute_reply":"2021-05-23T10:40:32.774841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission['hotel_id'] = preds\n\nsubmission.to_csv('submission.csv', index = False)\n\nsubmission.head()","metadata":{"papermill":{"duration":0.143011,"end_time":"2021-05-17T18:02:19.35862","exception":false,"start_time":"2021-05-17T18:02:19.215609","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-05-23T10:40:32.778911Z","iopub.execute_input":"2021-05-23T10:40:32.779258Z","iopub.status.idle":"2021-05-23T10:40:32.794257Z","shell.execute_reply.started":"2021-05-23T10:40:32.779231Z","shell.execute_reply":"2021-05-23T10:40:32.793474Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"papermill":{"duration":0.014386,"end_time":"2021-05-17T18:02:19.387501","exception":false,"start_time":"2021-05-17T18:02:19.373115","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]}]}