Instructions to use Hiratax/food-recognition-model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use Hiratax/food-recognition-model with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://Hiratax/food-recognition-model") - Notebooks
- Google Colab
- Kaggle
Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: keras
|
| 3 |
+
tags:
|
| 4 |
+
- image-classification
|
| 5 |
+
- food-recognition
|
| 6 |
+
- food-vision
|
| 7 |
+
- uecfood256
|
| 8 |
+
- tensorflow
|
| 9 |
+
datasets:
|
| 10 |
+
- uecfood256
|
| 11 |
+
pipeline_tag: image-classification
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# Food Recognition Model (UECFOOD256)
|
| 15 |
+
|
| 16 |
+
This model is a deep learning classifier capable of recognizing **256 different types of food**. It was trained using **TensorFlow/Keras** on the **UECFOOD256** dataset.
|
| 17 |
+
|
| 18 |
+
## Model Details
|
| 19 |
+
- **Model Architecture:** [INSERT BASE MODEL HERE, e.g., MobileNetV2 / EfficientNetB0] (Fine-tuned)
|
| 20 |
+
- **Dataset:** UECFOOD256 (256 food categories)
|
| 21 |
+
- **Framework:** TensorFlow / Keras
|
| 22 |
+
- **Task:** Image Classification (Multi-class)
|
| 23 |
+
|
| 24 |
+
## Intended Use
|
| 25 |
+
This model is designed to take an image of food as input and output the specific food category name. It is useful for:
|
| 26 |
+
- Calorie tracking apps
|
| 27 |
+
- Dietary monitoring
|
| 28 |
+
- Food logging automation
|
| 29 |
+
|
| 30 |
+
## How to Use
|
| 31 |
+
|
| 32 |
+
You can load this model directly in Python using the `huggingface_hub` library.
|
| 33 |
+
|
| 34 |
+
**Important:** This model requires a `class_names.txt` file (included in the repo) to map the model's integer predictions back to readable food names.
|
| 35 |
+
|
| 36 |
+
### Inference Code
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
import numpy as np
|
| 40 |
+
from huggingface_hub import from_pretrained_keras, hf_hub_download
|
| 41 |
+
from keras.preprocessing import image
|
| 42 |
+
import tensorflow as tf
|
| 43 |
+
|
| 44 |
+
# 1. Define the Repo ID
|
| 45 |
+
repo_id = "Hiratax/food-recognition-model"
|
| 46 |
+
|
| 47 |
+
# 2. Load the Model
|
| 48 |
+
print("Loading model...")
|
| 49 |
+
model = from_pretrained_keras(repo_id)
|
| 50 |
+
|
| 51 |
+
# 3. Load the Class Names Mapping
|
| 52 |
+
class_names_path = hf_hub_download(repo_id=repo_id, filename="class_names.txt")
|
| 53 |
+
with open(class_names_path, 'r') as f:
|
| 54 |
+
class_names = [line.strip() for line in f.readlines()]
|
| 55 |
+
|
| 56 |
+
# 4. Prediction Function
|
| 57 |
+
def predict_food(img_path):
|
| 58 |
+
# Resize image to 224x224 (Standard for this model)
|
| 59 |
+
img = image.load_img(img_path, target_size=(224, 224))
|
| 60 |
+
img_array = image.img_to_array(img)
|
| 61 |
+
img_batch = np.expand_dims(img_array, axis=0)
|
| 62 |
+
|
| 63 |
+
# Predict
|
| 64 |
+
predictions = model.predict(img_batch)
|
| 65 |
+
predicted_index = np.argmax(predictions[0])
|
| 66 |
+
confidence = np.max(predictions[0])
|
| 67 |
+
|
| 68 |
+
return class_names[predicted_index], confidence
|
| 69 |
+
|
| 70 |
+
# 5. Run on an image
|
| 71 |
+
# food, conf = predict_food("my_sushi.jpg")
|
| 72 |
+
# print(f"Prediction: {food} ({conf:.2f})")
|