{"cells":[{"metadata":{},"cell_type":"markdown","source":"This is my first Kaggle Competition and I have summarized some pointers below for the fellow kaggle newbies:\n\nI have a setup of two notebooks for the current competition: Train Notebook & the other one is an Inference Notebook.\nI train a Model in a notebook similar to this one. Later, i use an inference notebook for predicting on the test set for submission.\n\nThe Current Notebook is the train Notebook which demonstrates the following functionality:\n- Read Input Images\n- Train the Model with the Images\n- Export the Model for use in the Inference Notebook"},{"metadata":{},"cell_type":"markdown","source":"****First steps:****\n1. If Data is not seen in the panel on the right,Click Add Data >> Competition Data>> Cassava Classification Data \n2. You should be able to see the Cassava Data in the input folder\n3. Turn the internet on \n4. Turn the GPU on by selectng The three dots on the right >> Accelerator >> GPU\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"#imports, setting the seed\nimport random\nrandom.seed(42)\nimport pandas as pd\nfrom fastai.vision.all import *","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# reading csv from input data\n# Training with 10k input files for the trial submission\nbase_path=\"/kaggle/input/cassava-leaf-disease-classification\"\ndf_train = pd.read_csv(base_path+\"/train.csv\")[:10000]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#creating the data loader\ndls = ImageDataLoaders.from_df(df_train, path=base_path+\"/train_images\", valid_pct=0.2,\n                               seed=42, fn_col=\"image_id\", label_col=\"label\",bs=64,item_tfms=Resize(256))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#training the model\nlearn = cnn_learner(dls, resnet18, metrics=error_rate, model_dir=\"/kaggle/working/\")\nlearn.fine_tune(1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#saving the model\nlearn.export( Path(\"/kaggle/working/super_beginner_trained_model.pkl\"))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"****Final Step:****\n- The notebook needs to be saved by using \"Save Version\"\n- This takes some time\n- The notebook will be compiled and can the output can be imported in an inference notebook "},{"metadata":{},"cell_type":"markdown","source":"****Steps to be followed in the Inference Notebook:****\n+ Import the trained Model using\n>> \"Add Data\" in the right panel >> Notebook output files >> Your work >> notebook name >> ADD\n* Use the following code to import the saved model\n>> model_path = \"../input/Notebook_Name/Model_Name.pkl\" \n>> learn = load_learner(model_path)\n\n\nExtra Inference Notebook Steps for the submission to be successful:\n*  check the format of the submission file (dont forget the index==False):\n>> submissions_df.to_csv(\"submission.csv\", index = False)\n\n* Put the internet off"}],"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}