Professional Documents
Culture Documents
Tomato-Leaf-Disease-Classification - Ipynb - Colaboratory
Tomato-Leaf-Disease-Classification - Ipynb - Colaboratory
Tomato-Leaf-Disease-Classification - Ipynb - Colaboratory
!nvidia-smi
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
+-----------------------------------------------------------------------------+
import tensorflow as tf
import pandas as pd
from tensorflow.keras.utils import to_categorical
import random
import numpy as np
import os
import matplotlib.pyplot as plt
1 of 7 3/29/2022, 12:21 AM
Copy of tomato-leaf-disease-classification.ipynb - Colaboratory https://colab.research.google.com/drive/1nCXy9ZkIHWM6W5CmTOj...
# Import the InceptionV3 model and here we will be using imagenet weights
2 of 7 3/29/2022, 12:21 AM
Copy of tomato-leaf-disease-classification.ipynb - Colaboratory https://colab.research.google.com/drive/1nCXy9ZkIHWM6W5CmTOj...
Model: "model_1"
____________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
====================================================================================
input_2 (InputLayer) [(None, 224, 224, 3 0 []
)]
3 of 7 3/29/2022, 12:21 AM
Copy of tomato-leaf-disease-classification.ipynb - Colaboratory https://colab.research.google.com/drive/1nCXy9ZkIHWM6W5CmTOj...
# Using the Image Data Generator to import the images from the dataset
from tensorflow.keras.preprocessing.image import ImageDataGenerator
# Training Generator
training_set = train_datagen.flow_from_directory('/content/drive/MyDrive/Data/New Plant D
target_size = (224, 224),
batch_size = 32,
class_mode = 'categorical')
# Testing Generator
test_set = test_datagen.flow_from_directory('/content/drive/MyDrive/Data/New Plant Diseas
target_size = (224, 224),
batch_size = 32,
class_mode = 'categorical')
4 of 7 3/29/2022, 12:21 AM
Copy of tomato-leaf-disease-classification.ipynb - Colaboratory https://colab.research.google.com/drive/1nCXy9ZkIHWM6W5CmTOj...
validation_steps=len(test_set)
)
# Accuracy
plt.plot(r.history['accuracy'], label='train acc')
plt.plot(r.history['val_accuracy'], label='val acc')
plt.legend()
plt.show()
plt.savefig('AccVal_acc')
5 of 7 3/29/2022, 12:21 AM
Copy of tomato-leaf-disease-classification.ipynb - Colaboratory https://colab.research.google.com/drive/1nCXy9ZkIHWM6W5CmTOj...
import tensorflow as tf
model = tf.keras.models.load_model('model_inception.h5')
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()
open("tomato_model.tflite", "wb").write(tflite_model)
y_pred = model.predict(test_set)
y_pred
6 of 7 3/29/2022, 12:21 AM
Copy of tomato-leaf-disease-classification.ipynb - Colaboratory https://colab.research.google.com/drive/1nCXy9ZkIHWM6W5CmTOj...
import numpy as np
y_pred = np.argmax(y_pred, axis=1)
y_pred
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-21-ceed490457b5> in <module>()
1 import numpy as np
----> 2 y_pred = np.argmax(y_pred, axis=1)
3 y_pred
7 of 7 3/29/2022, 12:21 AM