This Python script implements an image classification model using a Support Vector Machine (SVM) with a Convolutional Neural Network (CNN). The model is trained to distinguish between images of cats and dogs. The project is part of Prodigy Infotech's third task.
-
Importing Important Modules:
- Pandas: Data manipulation and analysis.
- NumPy: Numerical operations.
- TensorFlow: Neural network construction and training.
-
Preprocessing the Training Data:
- Data augmentation is applied using TensorFlow's ImageDataGenerator to prevent overfitting.
- Training and test sets are generated from the provided dataset.
-
Creating the Model:
- The CNN model is built using TensorFlow's Keras API.
- Layers include convolutional layers, pooling layers, flattening layers, fully connected layers, and an output layer.
-
Training the CNN:
- The model is compiled with the Adam optimizer and hinge loss function.
- Training involves fitting the model to the training set and validating it on the test set for multiple epochs.
-
Plotting Training and Validation Metrics:
- Code is provided to plot training and validation loss, as well as training and validation accuracy over epochs.
-
Saving the Trained Model:
- The trained CNN model is saved as a .h5 file for future use or deployment.
-
Testing the Model on a Sample Image:
- A sample image from the test set is loaded, preprocessed, and used to make predictions.
- The result is displayed alongside the image.
This project serves as a tutorial on image classification using SVM with CNN. Feel free to modify the code or address any bugs. For questions or improvements, please contact the author.
Advait Dongre