File size: 2,782 Bytes
d34e7d4 0e4f1c2 844a594 5209e5a 844a594 635d259 844a594 635d259 844a594 635d259 844a594 0e4f1c2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
---
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}},
}
``` |