The dataset for this project is taken from here :- https://www.kaggle.com/datasets/kaustubhb999/tomatoleaf/discussion
This script is a TensorFlow implementation for a tomato disease classification task using a convolutional neural network (CNN). Here's a breakdown of its functionality:
- The script mounts Google Drive where the training data is stored.
- It lists the directories in the training data path, which represent different classes of tomato diseases.
- It defines a list of valid image extensions and removes corrupted images from the dataset based on these extensions.
- It creates a TensorFlow dataset from the directory containing the training images, with image resizing to 228x228 pixels.
- Although not explicitly shown in the provided script, it includes commented-out code for data augmentation using ImageDataGenerator. Data augmentation techniques such as rescaling, shearing, zooming, and horizontal flipping are applied.
- The script constructs a CNN model using TensorFlow's Keras API. It defines a sequential model consisting of convolutional layers, max-pooling layers, flattening layers, dense layers, and dropout layers for regularization.
- The model is compiled with the Adam optimizer and sparse categorical cross-entropy loss function.
- The model is trained using the fit method on the training dataset for a specified number of epochs, with validation data provided to monitor the model's performance.
- The trained model is evaluated on the test dataset to compute its accuracy and loss.
- The script saves the trained model to Google Drive and later loads it for making predictions on new images.
- It demonstrates making predictions on new tomato images using the trained model. The input images are preprocessed and fed into the model to obtain predictions of the tomato diseases.
*Based on the predicted class index, the script provides explanations for each class, suggesting preventive measures and precautions for the identified diseases.
- The script includes code for visualizing the input images along with their predicted classes.