{"cells":[{"metadata":{},"cell_type":"raw","source":"# Experimento utilizando transfer learning\nForam carregadas redes resnet18 e squeezenet1_0 que foram treinadas no Colab"},{"metadata":{"trusted":true},"cell_type":"code","source":"path = '../input/cassava-leaf-disease-classification/'","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import numpy as np\nfrom time import sleep\nimport pandas as pd\nfrom fastai.vision.all import *\nfrom fastai.callback.tracker import SaveModelCallback\ndf = pd.read_csv(path + 'train.csv')\ndf_train = df.sample(int(0.7*len(df)))\ndf_test = df[~df.image_id.isin(df_train.image_id)] \ncaminho = path + \"train_images/\"\ndls = ImageDataLoaders.from_df(df, path=caminho, item_tfms=Resize(224))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"!mkdir /kaggle/working/models\n#!cp ../input/bestmodel/best_model.pth /kaggle/working/models/best_model.pth\n#!cp ../input/squeezeme1/best_model_squeeze.pth /kaggle/working/models/best_model_squeeze.pth\n!cp ../input/modelovgn11/modelo.pth /kaggle/working/models/modelvgn11.pth\n!ls /kaggle/working/models/\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#learn = cnn_learner(dls, resnet18, metrics=[error_rate], pretrained=False, path='./')\nlearn = cnn_learner(dls, models.vgg11_bn , metrics=[error_rate,accuracy], pretrained=False,path='./')\n#save_callback = SaveModelCallback(fname='best_model0', with_opt=True, monitor='valid_loss', reset_on_fit=False) \n\nlearn.load('modelvgn11') \nlearn.unfreeze()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"img = dls.train_ds[0][0]\nlearn.predict(img)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"submission_df = pd.read_csv(path + 'sample_submission.csv')\ncaminho = path + 'test_images'\ntest_data_path = submission_df['image_id'].apply(lambda x: caminho + '/' + 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.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}