--- license: mit language: - en library_name: tf-keras --- # Food or Not Food Keras Model The Food or Not Food Keras model is a Convolutional Neural Network (CNN) designed to classify images as either containing food or not. The model accepts images of shape (224, 224, 3) and outputs a binary classification. Leveraging a pre-trained feature extractor Efficient-Net-V2, the model is trained on a diverse dataset of food and non-food images to ensure robust performance. It achieves high accuracy, making it suitable for applications in food recognition systems. This model can be easily integrated into various projects to automate the process of identifying food in images. **NOTE:** model is saved in 3 formats legacy keras, .h5 and .keras, you need to clone this model in order to use the model. ## Model Details **Model Name:** Food or Not Food **Model Type:** Convolutional Neural Network (CNN) **Input Shape:** (224, 224, 3) **Output Shape:** Binary classification (Food/Not Food) **Framework:** Keras ## Dataset The model was trained on a dataset comprising images labeled as 'food' and 'not food'. The dataset includes various categories to ensure the model generalizes well to different types of food and non-food images. ## Usage To use this model for predicting whether an image contains food or not, you can use the following code snippet: ```python import tensorflow as tf from tensorflow.keras.models import load_model import numpy as np from PIL import Image model = load_model('path_to_your_model.h5') def preprocess_image(image_path): img = Image.open(image_path) img = img.resize((224, 224)) img_array = np.array(img) img_array = np.expand_dims(img_array, axis=0) return img_array def predict_image(image_path): img_array = preprocess_image(image_path) prediction = model.predict(img_array) if prediction > 0.5: return "Food" else: return "Not Food" image_path = 'path_to_your_image.jpg' result = predict_image(image_path) print(result) ``` ## Performance The model achieved an accuracy of 98.7% on the validation set. It performs well in distinguishing between food and non-food items. ## Limitations The model may not perform well on images that are very different from the training dataset. It is also limited by the quality and variety of the training data. ## Training The model was trained using the following parameters: - **Optimizer:** Adam - **Loss Function:** Binary Crossentropy - **Epochs:** 40 - **Batch Size:** 32 ## Citation If you use this model in your research, please cite it as follows: ``` @misc{isthisfood, title={Food or Not Food: A Binary Classification Model}, author={rudrashah}, year={2024}, howpublished={\url{https://huggingface.co/rudrashah/is-this-food}}, } ```