Automated Menu Review with Ingredient Identification
Overview:
This implements a Convolutional Neural Network (CNN) for classifying cuisine images into seven different categories. It utilizes TensorFlow and OpenCV libraries for image processing and model development. The CNN architecture consists of multiple convolutional layers followed by batch normalization, max-pooling, dropout, and dense layers. The model is trained on a dataset containing images of various cuisines, and its performance is evaluated using classification metrics.
Features:
- Loading images from folders with specified extensions.
- Preprocessing images by resizing and ensuring minimum dimensions.
- Splitting data into training and testing sets.
- Defining a CNN model architecture using TensorFlow's Keras API.
- Compiling the model with appropriate loss function and optimizer.
- Training the model with specified epochs and batch size.
- Evaluating the model's performance on test data using accuracy metrics.
- Saving the trained model to a file and loading it for future use.
- Predicting cuisine class probabilities for a given image.
- Displaying prediction results including predicted cuisine, food name, ingredients, and additional metadata from a CSV file.
Installation: Ensure you have the following libraries installed:
- NumPy
- Matplotlib
- OpenCV (cv2)
- scikit-learn
- TensorFlow
You can install these libraries using pip:
pip install numpy matplotlib opencv-python scikit-learn tensorflow
Usage:
- Import the necessary libraries:
import numpy as np
import matplotlib.pyplot as plt
import cv2
import os
from sklearn.model_selection import train_test_split
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, Dense, Dropout, Flatten, BatchNormalization, MaxPooling2D
from sklearn.metrics import classification_report
import csv-
Define the function
load_images_from_folderto load images from a folder. -
Define folder paths for each cuisine category and load images from those folders.
-
Preprocess images and labels.
-
Split data into training and testing sets.
-
Define the CNN model architecture using
Sequentialmodel. -
Compile the model with appropriate loss function and optimizer.
-
Train the model using the training data.
-
Evaluate the model's performance on test data using
evaluatemethod. -
Print classification report.
-
Plot training history.
-
Load and preprocess an image for prediction.
-
Predict cuisine class probabilities for the image.
-
Display the predicted cuisine and additional information.
Dataset: The dataset used in this code contains images of various cuisines categorized into seven classes:
- Chettinadu cuisine
- Kongu Nadu cuisine
- Mudaliar cuisine
- Nanjil cuisine
- Pandiya nadu cuisine
- Tamil Sahibu cuisine
- Thanjavur cuisine
Ensure your dataset structure follows the folder hierarchy mentioned in the code for proper execution.