{"cells":[{"metadata":{"trusted":true,"_uuid":"909d92d47c72f549abd51fe6849b192e42cad074"},"cell_type":"code","source":"#Allows you to save your models somewhere without\n# copying all the data over.\n# Trust me on this.\n\n!mkdir input\n!cp /kaggle/input/train_labels.csv input\n!cp /kaggle/input/sample_submission.csv input\n!ln -s /kaggle/input/train/ input/train\n!ln -s /kaggle/input/test/ input/test","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"from fastai.vision import *","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8a8e79785191a71a45c3450ed68d356481cd3eda"},"cell_type":"code","source":"db = (ImageItemList.from_csv(csv_name='train_labels.csv', path='input', folder='train', suffix='.tif')\n        .random_split_by_pct()\n        .label_from_df()\n        .transform(get_transforms(flip_vert=True), size=64)\n        .add_test_folder('test')\n        .databunch(bs=32)\n        .normalize(imagenet_stats))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6337f942c780e5abf617e478b79c1da57b434736"},"cell_type":"code","source":"db.show_batch(4, figsize=(12,12), ds_type=DatasetType.Test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"38f5eb99984bcfe40bc7ef4a6a63a826aadbb274","scrolled":true},"cell_type":"code","source":"learn = create_cnn(db, models.resnet34, metrics=[error_rate])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e164deb12ced023d7316978cfbbf36142465867c"},"cell_type":"code","source":"lr_find(learn)\nlearn.recorder.plot()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"01a53e35875b21171e8bcdf8bb11e57147ce6698","scrolled":true},"cell_type":"code","source":"learn.fit_one_cycle(3, 1e-02)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e1f785d3d9895c99353671e081a1bfa683a345d4"},"cell_type":"code","source":"interp = ClassificationInterpretation.from_learner(learn)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7fd66d30bda1b78cb3d805ba0084266272ee7be2"},"cell_type":"code","source":"interp.plot_confusion_matrix()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"aa1d604bf0042ebc6bf1b61dec64968d7d0adb58"},"cell_type":"code","source":"interp.plot_top_losses(4)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e964780be7d73dce8368134af8baf25a6820af96"},"cell_type":"code","source":"probs, _ = learn.get_preds(DatasetType.Test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b894944fa1cf9b9faea4514167d8080911c278b8"},"cell_type":"code","source":"preds = probs[:,1]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7698760c90a0d36196cb00211fd934d84d7a2f9d"},"cell_type":"code","source":"test_df = pd.read_csv('./input/sample_submission.csv')\ntest_df['id'] = [i.stem for i in db.test_ds.items]\ntest_df['label'] = preds","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9d17c11e7e0eb8b22ffc032f64cb2a6a27d6c2aa"},"cell_type":"code","source":"test_df.to_csv('submission.csv', index=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"17e12d021cd8c148479716a95112c01aef58d4b8"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}