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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
metrics:
|
| 6 |
+
- accuracy
|
| 7 |
+
base_model:
|
| 8 |
+
- google/efficientnet-b0
|
| 9 |
+
pipeline_tag: image-classification
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# Model Card for Food Vision Model
|
| 13 |
+
|
| 14 |
+
This model is an image classification model trained to identify different types of food from images. It was developed as part of a Food Vision project, likely utilizing transfer learning on a pre-trained convolutional neural network.
|
| 15 |
+
|
| 16 |
+
## Model Details
|
| 17 |
+
|
| 18 |
+
### Model Description
|
| 19 |
+
|
| 20 |
+
This model is a deep learning model for classifying food images into one of 101 categories from the Food101 dataset. It was trained using TensorFlow and likely employs a transfer learning approach, leveraging the features learned by a model pre-trained on a large dataset like ImageNet. The training process included the use of mixed precision for potentially faster training and reduced memory usage.
|
| 21 |
+
|
| 22 |
+
* **Developed by:** Based on the notebook, this seems to be a personal project or tutorial. You should replace this with the actual developer's name or organization.
|
| 23 |
+
|
| 24 |
+
* **Model type:** Image Classification (likely Transfer Learning with a CNN backbone)
|
| 25 |
+
|
| 26 |
+
* **Language(s) (NLP):** N/A (Image Classification)
|
| 27 |
+
|
| 28 |
+
* **License:** MIT
|
| 29 |
+
|
| 30 |
+
* **Finetuned from model:** \[More Information Needed - Specify the base model used for transfer learning, e.g., EfficientNet, ResNet]
|
| 31 |
+
|
| 32 |
+
### Uses
|
| 33 |
+
|
| 34 |
+
This model is intended for classifying images of food into 101 distinct categories. Potential use cases include:
|
| 35 |
+
|
| 36 |
+
* Food recognition in mobile applications.
|
| 37 |
+
|
| 38 |
+
* Organizing food images in databases.
|
| 39 |
+
|
| 40 |
+
* Assisting in dietary tracking or recipe suggestions based on images.
|
| 41 |
+
|
| 42 |
+
## Limitations
|
| 43 |
+
|
| 44 |
+
* **Dataset Bias:** The model is trained on the Food101 dataset. Its performance may degrade on food images that are significantly different in style, presentation, or origin from those in the training data.
|
| 45 |
+
|
| 46 |
+
* **Image Quality:** Performance can be affected by image quality, lighting conditions, occlusions, and variations in food presentation.
|
| 47 |
+
|
| 48 |
+
* **Specificity:** While it classifies into 101 categories, it may not distinguish between very similar dishes or variations within a category.
|
| 49 |
+
|
| 50 |
+
## Evaluation
|
| 51 |
+
|
| 52 |
+
The model's performance was evaluated using standard classification metrics on a validation set from the Food101 dataset.
|
| 53 |
+
|
| 54 |
+
#### Testing Data
|
| 55 |
+
|
| 56 |
+
The model was evaluated on the validation split of the Food101 dataset.
|
| 57 |
+
|
| 58 |
+
* **Food101 Dataset:** A dataset of 101 food categories, with 101,000 images. 750 training images and 250 testing images per class.
|
| 59 |
+
|
| 60 |
+
* **Source:** [TensorFlow Datasets](https://www.tensorflow.org/datasets/catalog/food101)
|
| 61 |
+
|
| 62 |
+
#### Factors
|
| 63 |
+
|
| 64 |
+
Evaluation was performed on the overall validation dataset. Further analysis could involve disaggregating performance by individual food categories to identify classes where the model performs better or worse.
|
| 65 |
+
|
| 66 |
+
#### Metrics
|
| 67 |
+
|
| 68 |
+
The primary evaluation metric used is Accuracy. A confusion matrix was also generated to visualize per-class performance.
|
| 69 |
+
|
| 70 |
+
* **Accuracy:** The proportion of correctly classified images out of the total number of images evaluated.
|
| 71 |
+
$\text{Accuracy} = \frac{\text{Number of correct predictions}}{\text{Total number of predictions}}$
|
| 72 |
+
|
| 73 |
+
* **Confusion Matrix:** A table that visualizes the performance of a classification model. Each row represents the instances in an actual class, while each column represents the instances in a predicted class.
|
| 74 |
+
|
| 75 |
+
### Results
|
| 76 |
+
|
| 77 |
+
70-80% Fluctualting accuracy on validation data
|
| 78 |
+
|
| 79 |
+
#### Summary
|
| 80 |
+
|
| 81 |
+
Transfer learning helped the model achieve greater accuracy, though the model struggled with food closely related to each other indicating more data was needed. The Dataset used alot but more data is still needed to differentiate between closely looking food.
|
| 82 |
+
|
| 83 |
+
## Environmental Impact
|
| 84 |
+
|
| 85 |
+
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 86 |
+
|
| 87 |
+
* **Hardware Type:** Tesla T4
|
| 88 |
+
|
| 89 |
+
* **Hours used:** 1 hour estimate(max)
|
| 90 |
+
|
| 91 |
+
* **Cloud Provider:** Google Cloud
|
| 92 |
+
|
| 93 |
+
* **Compute Region:** us-central
|
| 94 |
+
|
| 95 |
+
* **Carbon Emitted:** 80 grams of CO2eq (estimated)
|
| 96 |
+
|
| 97 |
+
## Technical Specifications
|
| 98 |
+
|
| 99 |
+
### Model Architecture and Objective
|
| 100 |
+
|
| 101 |
+
The model is likely a fine-tuned convolutional neural network (CNN) classifier. The notebook mentions using mixed precision training, which suggests a modern CNN architecture compatible with `float16` data types. The objective is to minimize the classification loss (e.g., categorical cross-entropy) to accurately predict the food category given an image.
|
| 102 |
+
|
| 103 |
+
### Compute Infrastructure
|
| 104 |
+
|
| 105 |
+
The model was trained using a Tesla T4 GPU on Google Cloud in the us-central region. The estimated carbon emissions for 1 hour of training time on this setup are 80 grams of CO2eq. The environment was intended to support mixed precision training.
|
| 106 |
+
|
| 107 |
+
### Software
|
| 108 |
+
|
| 109 |
+
* TensorFlow
|
| 110 |
+
|
| 111 |
+
* TensorFlow Datasets
|
| 112 |
+
|
| 113 |
+
* NumPy
|
| 114 |
+
|
| 115 |
+
* Matplotlib
|
| 116 |
+
|
| 117 |
+
* Scikit-learn
|
| 118 |
+
|
| 119 |
+
* Helper functions from `helper_functions.py` (likely for plotting, data handling)
|
| 120 |
+
|
| 121 |
+
## Usage
|
| 122 |
+
|
| 123 |
+
Here's an example of how to use the model for inference on a new image. This assumes the model has been saved in a TensorFlow SavedModel format.
|
| 124 |
+
|
| 125 |
+
First, make sure you have TensorFlow installed:
|
| 126 |
+
|
| 127 |
+
```bash
|
| 128 |
+
pip install tensorflow
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
Then, you can load the model and make a prediction:
|
| 132 |
+
```python
|
| 133 |
+
import tensorflow as tf
|
| 134 |
+
import matplotlib.pyplot as plt
|
| 135 |
+
import numpy as np
|
| 136 |
+
|
| 137 |
+
# Assume the model is saved in a directory named 'food_vision_model'
|
| 138 |
+
loaded_model = tf.keras.models.load_model('food_vision_model')
|
| 139 |
+
|
| 140 |
+
# Define the class names (replace with the actual class names from your training)
|
| 141 |
+
class_names = ['apple_pie', 'baby_back_ribs', 'baklava', 'beef_carpaccio', 'beef_tartare', 'beet_salad', 'beignets', 'bibimbap', 'bread_pudding', 'breakfast_burrito', 'bruschetta', 'buffalo_wings', 'caesar_salad', 'cannoli', 'caprese_salad', 'carrot_cake', 'cheesecake', 'cheese_plate', 'chicken_curry', 'chicken_quesadilla', 'chicken_wings', 'chocolate_cake', 'chocolate_mousse', 'churros', 'clam_chowder', 'club_sandwich', 'crab_cakes', 'creme_brulee', 'croque_madame', 'cup_cakes', 'deviled_eggs', 'donuts', 'dumplings', 'edamame', 'eggs_benedict', 'escargots', 'falafel', 'filet_mignon', 'fish_and_chips', 'foie_gras', 'french_fries', 'french_onion_soup', 'french_toast', 'fried_calamari', 'fried_chicken', 'frozen_yogurt', 'garlic_bread', 'gnocchi', 'greek_salad', 'grilled_cheese_sandwich', 'grilled_salmon', 'guacamole', 'gyros', 'hamburger', 'hot_dog', 'ice_cream', 'lasagna', 'lobster_bisque', 'lobster_roll_sandwich', 'macaroni_and_cheese', 'macarons', 'miso_soup', 'mussels', 'nachos', 'omelette', 'onion_rings', 'oysters', 'pad_thai', 'paella', 'pancakes', 'panna_cotta', 'peking_duck', 'pho', 'pizza', 'pork_chop', 'poutine', 'prime_rib', 'pulled_pork_sandwich', 'ramen', 'ravioli', 'red_velvet_cake', 'risotto', 'samosas', 'sashimi', 'scallops', 'shrimp_scampi', 'smores', 'spaghetti_bolognese', 'spaghetti_carbonara', 'spring_rolls', 'steak', 'strawberry_shortcake', 'sushi', 'tacos', 'takoyaki', 'tiramisu', 'tuna_tartare', 'waffles'] # Example class names
|
| 142 |
+
|
| 143 |
+
# Create a function to load and prepare images (from your notebook)
|
| 144 |
+
def load_prep_image(filepath, img_shape=224, scale=True):
|
| 145 |
+
"""
|
| 146 |
+
Reads in an image and preprocesses it for model prediction
|
| 147 |
+
|
| 148 |
+
Args:
|
| 149 |
+
filepath (str): path to target image
|
| 150 |
+
img_shape (int): shape to resize image to. Default = 224
|
| 151 |
+
scale (bool): Condition to scale image. Default = True
|
| 152 |
+
|
| 153 |
+
Returns:
|
| 154 |
+
Image Tensor of shape (img_shape, img_shape, 3)
|
| 155 |
+
"""
|
| 156 |
+
image = tf.io.read_file(filepath)
|
| 157 |
+
image_tensor = tf.io.decode_image(image, channels=3)
|
| 158 |
+
image_tensor = tf.image.resize(image_tensor, [img_shape, img_shape])
|
| 159 |
+
if scale:
|
| 160 |
+
# Scale image tensor to be between 0 and 1
|
| 161 |
+
scaled_image_tensor = image_tensor / 255.
|
| 162 |
+
return scaled_image_tensor
|
| 163 |
+
else:
|
| 164 |
+
return image_tensor
|
| 165 |
+
|
| 166 |
+
# Load and preprocess a sample image
|
| 167 |
+
# Replace 'path/to/your/image.jpg' with the actual path to your image
|
| 168 |
+
sample_image_path = 'path/to/your/image.jpg'
|
| 169 |
+
prepared_image = load_prep_image(sample_image_path)
|
| 170 |
+
|
| 171 |
+
# Add a batch dimension to the image
|
| 172 |
+
prepared_image = tf.expand_dims(prepared_image, axis=0)
|
| 173 |
+
|
| 174 |
+
# Make a prediction
|
| 175 |
+
predictions = loaded_model.predict(prepared_image)
|
| 176 |
+
|
| 177 |
+
# Get the predicted class index
|
| 178 |
+
predicted_class_index = np.argmax(predictions)
|
| 179 |
+
|
| 180 |
+
# Get the predicted class name
|
| 181 |
+
predicted_class_name = class_names[predicted_class_index]
|
| 182 |
+
|
| 183 |
+
# Print the prediction
|
| 184 |
+
print(f"The predicted food item is: {predicted_class_name}")
|
| 185 |
+
|
| 186 |
+
# Optional: Display the image
|
| 187 |
+
# img = plt.imread(sample_image_path)
|
| 188 |
+
# plt.imshow(img)
|
| 189 |
+
# plt.title(f"Prediction: {predicted_class_name}")
|
| 190 |
+
# plt.axis('off')
|
| 191 |
+
# plt.show()
|
| 192 |
+
```
|