{"cells":[{"metadata":{"trusted":true},"cell_type":"code","source":"import numpy as np \nimport pandas as pd\nfrom pathlib import Path\nfrom fastai import *\nfrom fastai.vision import *\nimport torchvision\nimport torch","execution_count":2,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"data_root_path = Path(\"../input\")","execution_count":5,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df = pd.read_csv(data_root_path/\"train_labels.csv\")\ntest_df = pd.read_csv(data_root_path/\"sample_submission.csv\")\ntrain_df.id = train_df.id + '.tif'\ntest_df.id = test_df.id + '.tif'","execution_count":6,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"transforms = get_transforms(\n    do_flip=True, \n    flip_vert=True, \n    max_rotate=15.0, \n    max_lighting=0.2, \n    max_warp=0.2\n)\n\ntrain_imgs = ImageList.from_df(train_df, path=data_root_path, folder='train')\ntest_imgs = ImageList.from_df(test_df, path=data_root_path, folder='test')\n\ntrain_imgs = (train_imgs\n    .split_by_rand_pct(0.01)\n    .label_from_df()\n    .add_test(test_imgs)\n    .transform(transforms, size=128)\n    .databunch(path='.', bs=64, device= torch.device('cuda:0'))\n    .normalize(imagenet_stats))","execution_count":7,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"learn = cnn_learner(train_imgs, torchvision.models.densenet169, metrics=[error_rate, accuracy])","execution_count":8,"outputs":[{"output_type":"stream","text":"Downloading: \"https://download.pytorch.org/models/densenet169-b2777c0a.pth\" to /tmp/.torch/models/densenet169-b2777c0a.pth\n57365526it [00:01, 35410826.23it/s]\n","name":"stderr"}]},{"metadata":{"trusted":false},"cell_type":"code","source":"learn.lr_find()\nlearn.recorder.plot()","execution_count":null,"outputs":[]},{"metadata":{"trusted":false},"cell_type":"code","source":"lr = 3e-02\nlearn.fit_one_cycle(10, slice(lr))","execution_count":null,"outputs":[]},{"metadata":{"trusted":false},"cell_type":"code","source":"interp = ClassificationInterpretation.from_learner(learn)\ninterp.plot_top_losses(9, figsize=(7,6))","execution_count":null,"outputs":[]},{"metadata":{"trusted":false},"cell_type":"code","source":"preds,_ = learn.get_preds(ds_type=DatasetType.Test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":false},"cell_type":"code","source":"test_df.label = preds.numpy()[:, 0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":false},"cell_type":"code","source":"test_df['id'] = test_df['id'].str.replace('.tif','')","execution_count":null,"outputs":[]},{"metadata":{"trusted":false},"cell_type":"code","source":"test_df.to_csv('submission.csv', index=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":false},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.6.7"}},"nbformat":4,"nbformat_minor":1}