{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import torch\nimport torchvision\ntorch.cuda.empty_cache()\nfrom torchvision import models\nfrom torch import nn\npath = '../input'\ndevice = torch.device(\"cuda:0\")\n\nmodel1 = torch.load(\"../input/a-simple-fastai-ensemble-training-kernel-0-60/model1.pth\")\nmodel2 = torch.load(\"../input/a-simple-fastai-ensemble-training-kernel-0-60/model2.pth\")\nmodel3 = torch.load(\"../input/a-simple-fastai-ensemble-training-kernel-0-60/model3.pth\")\nmodel4 = torch.load(\"../input/a-simple-fastai-ensemble-training-kernel-0-60/model4.pth\")\n\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from fastai.vision import *\ndff = pd.read_csv(\"../input/aptos2019-blindness-detection/test.csv\")\nsrc = (ImageList.from_df(dff, path='../input/aptos2019-blindness-detection', folder='test_images', suffix='.png')\n               .split_none()\n               .label_empty())\niB = ImageDataBunch.create_from_ll(src,size=299,bs=32,\n                                  ds_tfms=get_transforms(do_flip=True,\n                                      max_warp=0,\n                                      max_rotate=0,\n                                      max_lighting=0,\n                                      p_affine=0.2,\n                                      xtra_tfms=[crop_pad()]))\nlabels1,labels2,labels3,labels4 = [],[],[],[]\npredictor1 = Learner(data=iB,model=model1,model_dir='/tmp/models')\npreds1 = predictor1.get_preds(ds_type=DatasetType.Fix)\npredictor2 = Learner(data=iB,model=model2,model_dir='/tmp/models')\npreds2 = predictor2.get_preds(ds_type=DatasetType.Fix)\npredictor4 = Learner(data=iB,model=model4,model_dir='/tmp/models')\npreds4 = predictor4.get_preds(ds_type=DatasetType.Fix)\nlabels1,labels2,labels3,labels4 = [],[],[],[]\nprint(\"Predicting from model1....\")\nfor pr in preds1[0]:\n    p = pr.tolist()\n    labels1.append(np.argmax(p))\nprint(\"Predicting from model2....\")\nfor pr in preds2[0]:\n    p = pr.tolist()\n    labels2.append(np.argmax(p))\nprint(\"Predicting from model4....\")\nfor pr in preds4[0]:\n    p = pr.tolist()\n    labels4.append(np.argmax(p))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"finalPreds=[]\nfor i in range(len(labels1)):\n    pp = (0.3*labels1[i]+0.5*labels2[i]+0.2*labels4[i])/1\n    pp = np.floor(pp)\n    finalPreds.append(int(pp))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dff = pd.read_csv(\"../input/aptos2019-blindness-detection/test.csv\")\nids=  list(dff[\"id_code\"])\nsubmit = pd.DataFrame(data={'id_code':ids,'diagnosis':finalPreds})\nsubmit.to_csv('./submission.csv',index=False)","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.4","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}