{"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_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport os,cv2,random,time,shutil,csv\nimport tensorflow as tf\nfrom matplotlib import pyplot as plt\nimport seaborn as sns\nfrom matplotlib import image as mpimg\nfrom tqdm import tqdm\nimport json,os,cv2\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras.models import Model\nfrom tensorflow.keras.layers import BatchNormalization,Dense,GlobalAveragePooling2D,Lambda,Dropout,InputLayer,Input\nfrom tensorflow.keras.utils import to_categorical,plot_model\nfrom tensorflow.keras.preprocessing.image import load_img\nimport warnings\nwarnings.filterwarnings(action='ignore')","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:34.369217Z","iopub.execute_input":"2022-07-18T19:54:34.369707Z","iopub.status.idle":"2022-07-18T19:54:41.215879Z","shell.execute_reply.started":"2022-07-18T19:54:34.369597Z","shell.execute_reply":"2022-07-18T19:54:41.214918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dir='../input/paddy-disease-classification/train_images'\ntest_dir='../input/paddy-disease-classification/test_images'","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:41.218494Z","iopub.execute_input":"2022-07-18T19:54:41.220544Z","iopub.status.idle":"2022-07-18T19:54:41.225518Z","shell.execute_reply.started":"2022-07-18T19:54:41.220504Z","shell.execute_reply":"2022-07-18T19:54:41.223810Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_df=pd.read_csv('../input/paddy-disease-classification/sample_submission.csv')\nlabels_dataframe=pd.read_csv('../input/paddy-disease-classification/train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:41.226683Z","iopub.execute_input":"2022-07-18T19:54:41.227049Z","iopub.status.idle":"2022-07-18T19:54:41.270344Z","shell.execute_reply.started":"2022-07-18T19:54:41.227011Z","shell.execute_reply":"2022-07-18T19:54:41.269495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_dataframe","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:41.272063Z","iopub.execute_input":"2022-07-18T19:54:41.272326Z","iopub.status.idle":"2022-07-18T19:54:41.294739Z","shell.execute_reply.started":"2022-07-18T19:54:41.272303Z","shell.execute_reply":"2022-07-18T19:54:41.293660Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_dataframe.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:41.298229Z","iopub.execute_input":"2022-07-18T19:54:41.298862Z","iopub.status.idle":"2022-07-18T19:54:41.307321Z","shell.execute_reply.started":"2022-07-18T19:54:41.298837Z","shell.execute_reply":"2022-07-18T19:54:41.306258Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_dataframe.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:41.308798Z","iopub.execute_input":"2022-07-18T19:54:41.309257Z","iopub.status.idle":"2022-07-18T19:54:41.321843Z","shell.execute_reply.started":"2022-07-18T19:54:41.309221Z","shell.execute_reply":"2022-07-18T19:54:41.320945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_dataframe['label'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:41.323358Z","iopub.execute_input":"2022-07-18T19:54:41.323691Z","iopub.status.idle":"2022-07-18T19:54:41.337175Z","shell.execute_reply.started":"2022-07-18T19:54:41.323658Z","shell.execute_reply":"2022-07-18T19:54:41.336171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(labels_dataframe['label'])\nplt.xticks(rotation=50)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:41.338746Z","iopub.execute_input":"2022-07-18T19:54:41.339093Z","iopub.status.idle":"2022-07-18T19:54:41.576716Z","shell.execute_reply.started":"2022-07-18T19:54:41.339061Z","shell.execute_reply":"2022-07-18T19:54:41.575855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"No of dog's images in train directory\",len(os.listdir(train_dir)))\nprint(\"No of dog's images in test directory\",len(os.listdir(test_dir)))","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:41.579069Z","iopub.execute_input":"2022-07-18T19:54:41.579632Z","iopub.status.idle":"2022-07-18T19:54:41.826525Z","shell.execute_reply.started":"2022-07-18T19:54:41.579597Z","shell.execute_reply":"2022-07-18T19:54:41.825608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"diseases_types=sorted(list(set(labels_dataframe['label'])))\nn_classes=len(diseases_types)\nprint(n_classes)\nprint(diseases_types)","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:41.829613Z","iopub.execute_input":"2022-07-18T19:54:41.829909Z","iopub.status.idle":"2022-07-18T19:54:41.840005Z","shell.execute_reply.started":"2022-07-18T19:54:41.829882Z","shell.execute_reply":"2022-07-18T19:54:41.838869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classes_to_num=dict(zip(diseases_types,range(n_classes)))\nclasses_to_num","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:41.841594Z","iopub.execute_input":"2022-07-18T19:54:41.842026Z","iopub.status.idle":"2022-07-18T19:54:41.850140Z","shell.execute_reply.started":"2022-07-18T19:54:41.841987Z","shell.execute_reply":"2022-07-18T19:54:41.848948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(train_dir+'/'+labels_dataframe['label']+'/'+labels_dataframe['image_id'])[0]","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:41.851902Z","iopub.execute_input":"2022-07-18T19:54:41.852315Z","iopub.status.idle":"2022-07-18T19:54:41.867668Z","shell.execute_reply.started":"2022-07-18T19:54:41.852278Z","shell.execute_reply":"2022-07-18T19:54:41.866823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cv2.imread((train_dir+'/'+labels_dataframe['label']+'/'+labels_dataframe['image_id'])[1]).shape","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:41.870440Z","iopub.execute_input":"2022-07-18T19:54:41.870682Z","iopub.status.idle":"2022-07-18T19:54:41.908995Z","shell.execute_reply.started":"2022-07-18T19:54:41.870660Z","shell.execute_reply":"2022-07-18T19:54:41.908033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(cv2.imread((train_dir+'/'+labels_dataframe['label']+'/'+labels_dataframe['image_id'])[6660]))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:41.915082Z","iopub.execute_input":"2022-07-18T19:54:41.915327Z","iopub.status.idle":"2022-07-18T19:54:42.139184Z","shell.execute_reply.started":"2022-07-18T19:54:41.915305Z","shell.execute_reply":"2022-07-18T19:54:42.138295Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_dataframe['file_name']=train_dir+'/'+labels_dataframe['label']+'/'+labels_dataframe['image_id']\nlabels_dataframe","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:42.140448Z","iopub.execute_input":"2022-07-18T19:54:42.140874Z","iopub.status.idle":"2022-07-18T19:54:42.163614Z","shell.execute_reply.started":"2022-07-18T19:54:42.140837Z","shell.execute_reply":"2022-07-18T19:54:42.162684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_dataframe['file_name'][0]","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:42.164796Z","iopub.execute_input":"2022-07-18T19:54:42.165640Z","iopub.status.idle":"2022-07-18T19:54:42.172514Z","shell.execute_reply.started":"2022-07-18T19:54:42.165593Z","shell.execute_reply":"2022-07-18T19:54:42.171469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(cv2.imread(labels_dataframe['file_name'][265]))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:42.174177Z","iopub.execute_input":"2022-07-18T19:54:42.174590Z","iopub.status.idle":"2022-07-18T19:54:42.389796Z","shell.execute_reply.started":"2022-07-18T19:54:42.174554Z","shell.execute_reply":"2022-07-18T19:54:42.388878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_dataframe['label']=labels_dataframe['label'].map(classes_to_num)\nlabels_dataframe","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:42.391144Z","iopub.execute_input":"2022-07-18T19:54:42.392132Z","iopub.status.idle":"2022-07-18T19:54:42.409651Z","shell.execute_reply.started":"2022-07-18T19:54:42.392097Z","shell.execute_reply":"2022-07-18T19:54:42.408688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y=to_categorical(labels_dataframe['label'])\ny","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:42.411114Z","iopub.execute_input":"2022-07-18T19:54:42.411529Z","iopub.status.idle":"2022-07-18T19:54:42.419957Z","shell.execute_reply.started":"2022-07-18T19:54:42.411492Z","shell.execute_reply":"2022-07-18T19:54:42.418961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:42.421555Z","iopub.execute_input":"2022-07-18T19:54:42.422290Z","iopub.status.idle":"2022-07-18T19:54:42.429245Z","shell.execute_reply.started":"2022-07-18T19:54:42.422217Z","shell.execute_reply":"2022-07-18T19:54:42.428152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import keras","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:42.430887Z","iopub.execute_input":"2022-07-18T19:54:42.431573Z","iopub.status.idle":"2022-07-18T19:54:42.437590Z","shell.execute_reply.started":"2022-07-18T19:54:42.431534Z","shell.execute_reply":"2022-07-18T19:54:42.436636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow import keras\nfrom tensorflow.keras.applications.inception_resnet_v2 import InceptionResNetV2,preprocess_input as resnet_preprocess\nfrom tensorflow.keras.applications.inception_v3 import InceptionV3,preprocess_input as inception_preprocess\nfrom tensorflow.keras.applications.xception import Xception , preprocess_input as xception_preprocess\nfrom tensorflow.keras.applications.resnet50 import ResNet50,preprocess_input as resnet50_preprocess\nfrom tensorflow.keras.layers import concatenate","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:54:42.439185Z","iopub.execute_input":"2022-07-18T19:54:42.439634Z","iopub.status.idle":"2022-07-18T19:54:42.449888Z","shell.execute_reply.started":"2022-07-18T19:54:42.439507Z","shell.execute_reply":"2022-07-18T19:54:42.448953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_shape=(640,480,3)\ninput_layer=Input(shape=(input_shape))","metadata":{"execution":{"iopub.status.busy":"2022-07-18T21:12:48.838233Z","iopub.execute_input":"2022-07-18T21:12:48.838668Z","iopub.status.idle":"2022-07-18T21:12:48.849492Z","shell.execute_reply.started":"2022-07-18T21:12:48.838621Z","shell.execute_reply":"2022-07-18T21:12:48.845087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_dataframe","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:55:00.756014Z","iopub.execute_input":"2022-07-18T19:55:00.756619Z","iopub.status.idle":"2022-07-18T19:55:00.773618Z","shell.execute_reply.started":"2022-07-18T19:55:00.756592Z","shell.execute_reply":"2022-07-18T19:55:00.772692Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_dataframe['variety'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:55:00.775110Z","iopub.execute_input":"2022-07-18T19:55:00.775699Z","iopub.status.idle":"2022-07-18T19:55:00.785268Z","shell.execute_reply.started":"2022-07-18T19:55:00.775664Z","shell.execute_reply":"2022-07-18T19:55:00.784321Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_dataframe=labels_dataframe.drop(columns=['image_id','variety','age'],axis=1)\nlabels_dataframe","metadata":{"execution":{"iopub.status.busy":"2022-07-18T19:55:00.786710Z","iopub.execute_input":"2022-07-18T19:55:00.787076Z","iopub.status.idle":"2022-07-18T19:55:00.805363Z","shell.execute_reply.started":"2022-07-18T19:55:00.787043Z","shell.execute_reply":"2022-07-18T19:55:00.804268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.callbacks import EarlyStopping,ModelCheckpoint,ReduceLROnPlateau\nearlystop=EarlyStopping(monitor='val_loss',patience=20,restore_best_weights=True)\ncheckpoint=ModelCheckpoint('kaggle/working/checkpoint',monitor='val_loss',mode='min',save_best_only=True)\nlr=ReduceLROnPlateau(monitor='val_loss',factor=0.5,patience=3,min_lr=1e-3)\nmy_callbacks=[earlystop,checkpoint,lr]","metadata":{"execution":{"iopub.status.busy":"2022-07-18T21:15:41.830612Z","iopub.execute_input":"2022-07-18T21:15:41.831038Z","iopub.status.idle":"2022-07-18T21:15:41.837656Z","shell.execute_reply.started":"2022-07-18T21:15:41.830979Z","shell.execute_reply":"2022-07-18T21:15:41.836632Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.optimizers import Adam","metadata":{"execution":{"iopub.status.busy":"2022-07-18T21:17:44.485595Z","iopub.execute_input":"2022-07-18T21:17:44.486184Z","iopub.status.idle":"2022-07-18T21:17:44.491473Z","shell.execute_reply.started":"2022-07-18T21:17:44.486150Z","shell.execute_reply":"2022-07-18T21:17:44.490416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"diseases_types","metadata":{"execution":{"iopub.status.busy":"2022-07-18T21:36:34.635095Z","iopub.execute_input":"2022-07-18T21:36:34.635756Z","iopub.status.idle":"2022-07-18T21:36:34.642597Z","shell.execute_reply.started":"2022-07-18T21:36:34.635713Z","shell.execute_reply":"2022-07-18T21:36:34.641713Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data= tf.keras.utils.image_dataset_from_directory(\"/kaggle/input/paddy-disease-classification/train_images/\",\n                                                        labels='inferred',\n                                                        label_mode='categorical',\n                                                        class_names=diseases_types,\n                                                        color_mode='rgb',\n                                                        image_size=(640,480),\n                                                        shuffle=True,\n                                                        validation_split=0.2,\n                                                        subset='training',\n                                                        seed=42)\n\nval_data= tf.keras.utils.image_dataset_from_directory(\"/kaggle/input/paddy-disease-classification/train_images/\",\n                                                        labels='inferred',\n                                                        label_mode='categorical',\n                                                        class_names=diseases_types,   \n                                                        color_mode='rgb',\n                                                        image_size=(640,480),\n                                                        shuffle=True,\n                                                        validation_split=0.2,\n                                                        subset='validation',\n                                                        seed=42)","metadata":{"execution":{"iopub.status.busy":"2022-07-18T21:37:36.586662Z","iopub.execute_input":"2022-07-18T21:37:36.587027Z","iopub.status.idle":"2022-07-18T21:37:38.133598Z","shell.execute_reply.started":"2022-07-18T21:37:36.586996Z","shell.execute_reply":"2022-07-18T21:37:38.132550Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data","metadata":{"execution":{"iopub.status.busy":"2022-07-18T21:37:50.204473Z","iopub.execute_input":"2022-07-18T21:37:50.204823Z","iopub.status.idle":"2022-07-18T21:37:50.213158Z","shell.execute_reply.started":"2022-07-18T21:37:50.204794Z","shell.execute_reply":"2022-07-18T21:37:50.211942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_data","metadata":{"execution":{"iopub.status.busy":"2022-07-18T21:38:01.195199Z","iopub.execute_input":"2022-07-18T21:38:01.195761Z","iopub.status.idle":"2022-07-18T21:38:01.202128Z","shell.execute_reply.started":"2022-07-18T21:38:01.195726Z","shell.execute_reply":"2022-07-18T21:38:01.201149Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_augmentation=tf.keras.Sequential([\n    tf.keras.layers.RandomRotation(0.45),\n    tf.keras.layers.RandomFlip('horizontal')\n])","metadata":{"execution":{"iopub.status.busy":"2022-07-18T21:38:26.612597Z","iopub.execute_input":"2022-07-18T21:38:26.612940Z","iopub.status.idle":"2022-07-18T21:38:26.626669Z","shell.execute_reply.started":"2022-07-18T21:38:26.612911Z","shell.execute_reply":"2022-07-18T21:38:26.625778Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model=tf.keras.applications.EfficientNetB2(include_top=False, pooling='avg', weights='imagenet', input_shape=(640,480,3))","metadata":{"execution":{"iopub.status.busy":"2022-07-18T21:38:51.182754Z","iopub.execute_input":"2022-07-18T21:38:51.183128Z","iopub.status.idle":"2022-07-18T21:38:54.674629Z","shell.execute_reply.started":"2022-07-18T21:38:51.183098Z","shell.execute_reply":"2022-07-18T21:38:54.673603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model","metadata":{"execution":{"iopub.status.busy":"2022-07-18T21:38:58.881757Z","iopub.execute_input":"2022-07-18T21:38:58.882124Z","iopub.status.idle":"2022-07-18T21:38:58.888958Z","shell.execute_reply.started":"2022-07-18T21:38:58.882093Z","shell.execute_reply":"2022-07-18T21:38:58.887903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_batch, label_batch= next(iter(train_data))\nfeature_batch=base_model(image_batch)\nfeature_batch.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-18T21:39:21.152756Z","iopub.execute_input":"2022-07-18T21:39:21.153129Z","iopub.status.idle":"2022-07-18T21:39:22.736937Z","shell.execute_reply.started":"2022-07-18T21:39:21.153098Z","shell.execute_reply":"2022-07-18T21:39:22.735943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# applying model","metadata":{}},{"cell_type":"code","source":"inputs=tf.keras.Input(shape=(640,480,3))\nx=data_augmentation(inputs)\nx=base_model(x, training=False)\nx=tf.keras.layers.Dense(512,activation='relu')(x)\nx=tf.keras.layers.Dropout(0.4)(x)\nx=tf.keras.layers.Dense(128,activation='relu')(x)\nx=tf.keras.layers.Dropout(0.4)(x)\noutput=tf.keras.layers.Dense(10, activation='softmax')(x)\nmodel=tf.keras.Model(inputs,output)","metadata":{"execution":{"iopub.status.busy":"2022-07-18T21:40:13.221793Z","iopub.execute_input":"2022-07-18T21:40:13.222165Z","iopub.status.idle":"2022-07-18T21:40:14.176263Z","shell.execute_reply.started":"2022-07-18T21:40:13.222132Z","shell.execute_reply":"2022-07-18T21:40:14.175311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2022-07-18T21:40:20.402111Z","iopub.execute_input":"2022-07-18T21:40:20.402539Z","iopub.status.idle":"2022-07-18T21:40:20.437462Z","shell.execute_reply.started":"2022-07-18T21:40:20.402500Z","shell.execute_reply":"2022-07-18T21:40:20.436573Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_model(model)","metadata":{"execution":{"iopub.status.busy":"2022-07-18T21:40:28.872293Z","iopub.execute_input":"2022-07-18T21:40:28.873031Z","iopub.status.idle":"2022-07-18T21:40:29.159689Z","shell.execute_reply.started":"2022-07-18T21:40:28.872970Z","shell.execute_reply":"2022-07-18T21:40:29.158625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for layer in base_model.layers:\n    layer.trainable=False","metadata":{"execution":{"iopub.status.busy":"2022-07-18T21:41:08.083055Z","iopub.execute_input":"2022-07-18T21:41:08.083824Z","iopub.status.idle":"2022-07-18T21:41:08.101938Z","shell.execute_reply.started":"2022-07-18T21:41:08.083785Z","shell.execute_reply":"2022-07-18T21:41:08.100979Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Fine tuning","metadata":{}},{"cell_type":"code","source":"for layer1 in base_model.layers[280:]:\n    layer1.trainable=True","metadata":{"execution":{"iopub.status.busy":"2022-07-18T21:56:23.970654Z","iopub.execute_input":"2022-07-18T21:56:23.971029Z","iopub.status.idle":"2022-07-18T21:56:23.979024Z","shell.execute_reply.started":"2022-07-18T21:56:23.970990Z","shell.execute_reply":"2022-07-18T21:56:23.977987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(loss=tf.keras.losses.CategoricalCrossentropy(), optimizer=tf.keras.optimizers.Adam(learning_rate=0.00001), metrics=['accuracy'])\ncallback2=tf.keras.callbacks.EarlyStopping(monitor='accuracy', patience=3, restore_best_weights=True)\nhistory_tuned=model.fit(train_data, validation_data=val_data, epochs=5, callbacks=[callback2] )","metadata":{"execution":{"iopub.status.busy":"2022-07-18T22:09:08.063960Z","iopub.execute_input":"2022-07-18T22:09:08.064706Z","iopub.status.idle":"2022-07-18T22:24:04.098884Z","shell.execute_reply.started":"2022-07-18T22:09:08.064670Z","shell.execute_reply":"2022-07-18T22:24:04.097678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# test data","metadata":{}},{"cell_type":"code","source":"test_data=tf.keras.utils.image_dataset_from_directory(\"/kaggle/input/paddy-disease-classification/test_images/\",\n                                                        labels=None,\n                                                        label_mode=None,\n                                                        color_mode='rgb',\n                                                        image_size=(640,480),\n                                                        shuffle=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-18T22:24:22.624172Z","iopub.execute_input":"2022-07-18T22:24:22.624556Z","iopub.status.idle":"2022-07-18T22:24:24.947435Z","shell.execute_reply.started":"2022-07-18T22:24:22.624523Z","shell.execute_reply":"2022-07-18T22:24:24.946384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predict=tf.argmax(model.predict(test_data),axis=-1)\npredict","metadata":{"execution":{"iopub.status.busy":"2022-07-18T22:24:38.343004Z","iopub.execute_input":"2022-07-18T22:24:38.343697Z","iopub.status.idle":"2022-07-18T22:25:14.557998Z","shell.execute_reply.started":"2022-07-18T22:24:38.343662Z","shell.execute_reply":"2022-07-18T22:25:14.556948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions=[]\nfor i in predict:\n    predictions.append(diseases_types[i])","metadata":{"execution":{"iopub.status.busy":"2022-07-18T22:25:38.752946Z","iopub.execute_input":"2022-07-18T22:25:38.753575Z","iopub.status.idle":"2022-07-18T22:25:39.887570Z","shell.execute_reply.started":"2022-07-18T22:25:38.753539Z","shell.execute_reply":"2022-07-18T22:25:39.886603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions[:10]","metadata":{"execution":{"iopub.status.busy":"2022-07-18T22:25:55.213322Z","iopub.execute_input":"2022-07-18T22:25:55.213688Z","iopub.status.idle":"2022-07-18T22:25:55.222015Z","shell.execute_reply.started":"2022-07-18T22:25:55.213658Z","shell.execute_reply":"2022-07-18T22:25:55.220889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission=pd.read_csv(\"/kaggle/input/paddy-disease-classification/sample_submission.csv\").drop('label',axis=1)\nsample_submission","metadata":{"execution":{"iopub.status.busy":"2022-07-18T22:26:06.882831Z","iopub.execute_input":"2022-07-18T22:26:06.883558Z","iopub.status.idle":"2022-07-18T22:26:06.906885Z","shell.execute_reply.started":"2022-07-18T22:26:06.883524Z","shell.execute_reply":"2022-07-18T22:26:06.905958Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final=pd.DataFrame({'image_id': sample_submission.image_id, 'label': predictions})\nfinal.to_csv('submission.csv', index=None)","metadata":{"execution":{"iopub.status.busy":"2022-07-18T22:26:17.843646Z","iopub.execute_input":"2022-07-18T22:26:17.844015Z","iopub.status.idle":"2022-07-18T22:26:17.862580Z","shell.execute_reply.started":"2022-07-18T22:26:17.843976Z","shell.execute_reply":"2022-07-18T22:26:17.861671Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}