{"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 tensorflow as tf\nfrom tensorflow.keras import models,layers","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-08-07T05:16:52.674104Z","iopub.execute_input":"2022-08-07T05:16:52.674567Z","iopub.status.idle":"2022-08-07T05:16:57.380662Z","shell.execute_reply.started":"2022-08-07T05:16:52.674474Z","shell.execute_reply":"2022-08-07T05:16:57.379654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('../input/paddy-disease-classification/train.csv')\nsub = pd.read_csv('../input/paddy-disease-classification/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-08-07T05:16:57.382705Z","iopub.execute_input":"2022-08-07T05:16:57.383329Z","iopub.status.idle":"2022-08-07T05:16:57.416340Z","shell.execute_reply.started":"2022-08-07T05:16:57.383292Z","shell.execute_reply":"2022-08-07T05:16:57.415314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"diseases_types = sorted(list(set(train['label'])))\ndiseases_types","metadata":{"execution":{"iopub.status.busy":"2022-08-07T05:16:57.417925Z","iopub.execute_input":"2022-08-07T05:16:57.418281Z","iopub.status.idle":"2022-08-07T05:16:57.434227Z","shell.execute_reply.started":"2022-08-07T05:16:57.418247Z","shell.execute_reply":"2022-08-07T05:16:57.433064Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data= tf.keras.preprocessing.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=(680,480),\n                                                        shuffle=True,\n                                                        validation_split=0.2,\n                                                        subset='training',\n                                                        seed=42)\n\nval_data= tf.keras.preprocessing.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=(680,480),\n                                                        shuffle=True,\n                                                        validation_split=0.2,\n                                                        subset='validation',\n                                                        seed=42)","metadata":{"execution":{"iopub.status.busy":"2022-08-07T05:16:57.438280Z","iopub.execute_input":"2022-08-07T05:16:57.438551Z","iopub.status.idle":"2022-08-07T05:17:04.484663Z","shell.execute_reply.started":"2022-08-07T05:16:57.438527Z","shell.execute_reply":"2022-08-07T05:17:04.483622Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data","metadata":{"execution":{"iopub.status.busy":"2022-08-07T05:17:04.486205Z","iopub.execute_input":"2022-08-07T05:17:04.486827Z","iopub.status.idle":"2022-08-07T05:17:04.496995Z","shell.execute_reply.started":"2022-08-07T05:17:04.486789Z","shell.execute_reply":"2022-08-07T05:17:04.495756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"resnet_model=models.Sequential()\n\npretrained_model=tf.keras.applications.ResNet50(include_top=False,input_shape=(680,480,3),pooling='avg',classes=10,weights='imagenet')\n    \nfor layer in pretrained_model.layers:\n    layer.trainable=False\n    \n    \nresnet_model.add(pretrained_model)\nresnet_model.add(layers.Flatten())\nresnet_model.add(layers.Dense(512,activation='relu'))\nresnet_model.add(layers.Dense(99,activation='relu'))\nresnet_model.add(layers.Dense(10,activation='softmax'))","metadata":{"execution":{"iopub.status.busy":"2022-08-07T05:17:04.499095Z","iopub.execute_input":"2022-08-07T05:17:04.499583Z","iopub.status.idle":"2022-08-07T05:17:07.208772Z","shell.execute_reply.started":"2022-08-07T05:17:04.499535Z","shell.execute_reply":"2022-08-07T05:17:07.207685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.keras.utils.plot_model(resnet_model)","metadata":{"execution":{"iopub.status.busy":"2022-08-07T05:17:26.786751Z","iopub.execute_input":"2022-08-07T05:17:26.787117Z","iopub.status.idle":"2022-08-07T05:17:27.623695Z","shell.execute_reply.started":"2022-08-07T05:17:26.787086Z","shell.execute_reply":"2022-08-07T05:17:27.622476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_data","metadata":{"execution":{"iopub.status.busy":"2022-08-07T05:17:29.900547Z","iopub.execute_input":"2022-08-07T05:17:29.901762Z","iopub.status.idle":"2022-08-07T05:17:29.910736Z","shell.execute_reply.started":"2022-08-07T05:17:29.901712Z","shell.execute_reply":"2022-08-07T05:17:29.909839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"resnet_model.compile(optimizer='adam',loss='categorical_crossentropy',metrics=['accuracy'])\nresnet_model.fit(train_data,validation_data=val_data,epochs=25)","metadata":{"execution":{"iopub.status.busy":"2022-08-07T05:17:31.277983Z","iopub.execute_input":"2022-08-07T05:17:31.278879Z","iopub.status.idle":"2022-08-07T06:30:24.186355Z","shell.execute_reply.started":"2022-08-07T05:17:31.278833Z","shell.execute_reply":"2022-08-07T06:30:24.185458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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=(680,480),\n                                                        shuffle=False)","metadata":{"execution":{"iopub.status.busy":"2022-08-07T06:30:24.188710Z","iopub.execute_input":"2022-08-07T06:30:24.189056Z","iopub.status.idle":"2022-08-07T06:30:26.662563Z","shell.execute_reply.started":"2022-08-07T06:30:24.189021Z","shell.execute_reply":"2022-08-07T06:30:26.661469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predict=tf.argmax(resnet_model.predict(test_data),axis=-1)\npredict","metadata":{"execution":{"iopub.status.busy":"2022-08-07T06:30:26.664336Z","iopub.execute_input":"2022-08-07T06:30:26.664706Z","iopub.status.idle":"2022-08-07T06:31:02.018762Z","shell.execute_reply.started":"2022-08-07T06:30:26.664668Z","shell.execute_reply":"2022-08-07T06:31:02.017774Z"},"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-08-07T06:31:02.021660Z","iopub.execute_input":"2022-08-07T06:31:02.022447Z","iopub.status.idle":"2022-08-07T06:31:03.265227Z","shell.execute_reply.started":"2022-08-07T06:31:02.022376Z","shell.execute_reply":"2022-08-07T06:31:03.264069Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub=sub.drop(columns='label',axis=1)\nsub","metadata":{"execution":{"iopub.status.busy":"2022-08-07T06:31:03.270387Z","iopub.execute_input":"2022-08-07T06:31:03.272879Z","iopub.status.idle":"2022-08-07T06:31:03.300362Z","shell.execute_reply.started":"2022-08-07T06:31:03.272840Z","shell.execute_reply":"2022-08-07T06:31:03.299522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub","metadata":{"execution":{"iopub.status.busy":"2022-08-07T06:31:03.304518Z","iopub.execute_input":"2022-08-07T06:31:03.306800Z","iopub.status.idle":"2022-08-07T06:31:03.323563Z","shell.execute_reply.started":"2022-08-07T06:31:03.306765Z","shell.execute_reply":"2022-08-07T06:31:03.322737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission=pd.DataFrame({'image_id':sub['image_id'],'label':predictions})","metadata":{"execution":{"iopub.status.busy":"2022-08-07T06:31:03.327977Z","iopub.execute_input":"2022-08-07T06:31:03.330326Z","iopub.status.idle":"2022-08-07T06:31:03.337801Z","shell.execute_reply.started":"2022-08-07T06:31:03.330292Z","shell.execute_reply":"2022-08-07T06:31:03.336802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('paddy_docto2.csv',index=None)","metadata":{"execution":{"iopub.status.busy":"2022-08-07T06:31:03.342728Z","iopub.execute_input":"2022-08-07T06:31:03.344981Z","iopub.status.idle":"2022-08-07T06:31:03.362058Z","shell.execute_reply.started":"2022-08-07T06:31:03.344945Z","shell.execute_reply":"2022-08-07T06:31:03.361247Z"},"trusted":true},"execution_count":null,"outputs":[]}]}