{"cells":[{"metadata":{"trusted":true},"cell_type":"code","source":"#!mkdir /kaggle/working/cas/models\n#!cp -R /kaggle/input/cassava-leaf-disease-classification/* /kaggle/working\n%cd /kaggle/working","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#! conda install -y gdown","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import gdown\n\n#!mkdir models\n#https://drive.google.com/file/d/1-F8QqTazdt5YMIGyENIhJSW7uFwzU3JO/view?usp=sharing\nurl = 'https://drive.google.com/uc?export=download&id=1-F8QqTazdt5YMIGyENIhJSW7uFwzU3JO'\noutput = '/kaggle/working/models/modelo.pth'\n\n#gdown.download(url, output, quiet=False)\n!ls -la","execution_count":null,"outputs":[]},{"metadata":{"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\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nfrom fastai.vision.all import *\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\n\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"%cd /kaggle/working\n!pwd","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":true},"cell_type":"code","source":"df = pd.read_csv('./train.csv')\ndf_train = df.sample(int(0.7*len(df)))\ndf_test = df[~df.image_id.isin(df_train.image_id)]\ndf_train.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dls = ImageDataLoaders.from_df(df_train, path=\"./train_images/\", item_tfms=Resize(224))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"learn = cnn_learner(dls, resnet18, metrics=[error_rate,accuracy], pretrained=False, path='./')\nsave_callback = SaveModelCallback(fname='export', with_opt=True, monitor='valid_loss', reset_on_fit=False) \nlearn = learn.load('export')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"learn.lr_find()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"learn.fine_tune(1,6.309573450380412e-08,cbs=save_callback)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"learn.export(\"./export.pth\")\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"\npath = Path('../input/cassava-leaf-disease-classification')\nsubmission_df = pd.read_csv(path/'sample_submission.csv')\n\ntest_data_path = submission_df['image_id'].apply(lambda x: path/'test_images'/x)\ntst_dl = learn.dls.test_dl(test_data_path)\npredictions = learn.tta(dl = tst_dl, n=10)\n\nsubmission_df['label'] = np.argmax(predictions[0],axis=1)\nsubmission_df\n\nsubmission_df.to_csv('submission.csv',index=False)","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}