{"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 *\n\nimport dill","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-05-26T06:24:15.433171Z","iopub.execute_input":"2021-05-26T06:24:15.433522Z","iopub.status.idle":"2021-05-26T06:24:18.110552Z","shell.execute_reply.started":"2021-05-26T06:24:15.433446Z","shell.execute_reply":"2021-05-26T06:24:18.109728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fastai.__version__, torch.__version__","metadata":{"execution":{"iopub.status.busy":"2021-05-26T06:24:18.114179Z","iopub.execute_input":"2021-05-26T06:24:18.114446Z","iopub.status.idle":"2021-05-26T06:24:18.124792Z","shell.execute_reply.started":"2021-05-26T06:24:18.114421Z","shell.execute_reply":"2021-05-26T06:24:18.123938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"models = [\n    '../input/fgvc8hotel/export_res50_HQAdam.pkl', #v3\n    '../input/fgvc8hotel/export_dn161_Fa_CE_bs32.pkl', #v7\n    '../input/fgvc8hotel/export_dn161_Fa_FL_bs32.pkl', #v8\n    '../input/fgvc8hotel/export_res101_Fall_HQAdam.pkl', #v5\n    '../input/fgvc8hotel/export_res101_Fall_5it_4.pkl', #v11\n    '../input/hotel-train-fastai-densnet161/export_dn161_kaggle_notebook.pkl' # kaggle v2\n]","metadata":{"execution":{"iopub.status.busy":"2021-05-26T06:26:49.718303Z","iopub.execute_input":"2021-05-26T06:26:49.718621Z","iopub.status.idle":"2021-05-26T06:26:49.723904Z","shell.execute_reply.started":"2021-05-26T06:26:49.718593Z","shell.execute_reply":"2021-05-26T06:26:49.722867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_path = '../input/hotel-id-2021-fgvc8/test_images/' ","metadata":{"execution":{"iopub.status.busy":"2021-05-26T06:26:51.276302Z","iopub.execute_input":"2021-05-26T06:26:51.276646Z","iopub.status.idle":"2021-05-26T06:26:51.280707Z","shell.execute_reply.started":"2021-05-26T06:26:51.276606Z","shell.execute_reply":"2021-05-26T06:26:51.279736Z"},"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']\n#test['image'] = 'hotel-id-2021-fgvc8/test_images/' + test['image']\ntest","metadata":{"execution":{"iopub.status.busy":"2021-05-26T06:26:51.629792Z","iopub.execute_input":"2021-05-26T06:26:51.630144Z","iopub.status.idle":"2021-05-26T06:26:51.644429Z","shell.execute_reply.started":"2021-05-26T06:26:51.630115Z","shell.execute_reply":"2021-05-26T06:26:51.643338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"probs = None\nfor model in models:\n    learn = load_learner(fname = Path(model), cpu=False, pickle_module=dill)\n    test_dl = learn.dls.test_dl(test)\n    probs_temp, _ = learn.tta(dl=test_dl, n=4)\n    \n    if probs == None:\n        probs = probs_temp\n    else:\n        probs += probs_temp\n","metadata":{"execution":{"iopub.status.busy":"2021-05-26T06:26:52.420508Z","iopub.execute_input":"2021-05-26T06:26:52.420846Z","iopub.status.idle":"2021-05-26T06:27:30.430106Z","shell.execute_reply.started":"2021-05-26T06:26:52.420817Z","shell.execute_reply":"2021-05-26T06:27:30.428966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds_idx = probs.topk(5)[1]","metadata":{"execution":{"iopub.status.busy":"2021-05-26T06:27:35.583462Z","iopub.execute_input":"2021-05-26T06:27:35.583810Z","iopub.status.idle":"2021-05-26T06:27:35.589577Z","shell.execute_reply.started":"2021-05-26T06:27:35.583775Z","shell.execute_reply":"2021-05-26T06:27:35.588568Z"},"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":{"execution":{"iopub.status.busy":"2021-05-26T06:27:36.232310Z","iopub.execute_input":"2021-05-26T06:27:36.232647Z","iopub.status.idle":"2021-05-26T06:27:36.240704Z","shell.execute_reply.started":"2021-05-26T06:27:36.232619Z","shell.execute_reply":"2021-05-26T06:27:36.239573Z"},"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":{"execution":{"iopub.status.busy":"2021-05-26T06:27:37.062578Z","iopub.execute_input":"2021-05-26T06:27:37.062935Z","iopub.status.idle":"2021-05-26T06:27:37.299249Z","shell.execute_reply.started":"2021-05-26T06:27:37.062902Z","shell.execute_reply":"2021-05-26T06:27:37.298272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}