Spaces:
Sleeping
Sleeping
File size: 2,358 Bytes
fe6f0ef eeaa8d0 4b555a1 eeaa8d0 fe6f0ef 8d8e13c 5e00ad7 d5e2227 fe6f0ef d5e2227 fe6f0ef d5e2227 fe6f0ef 5e00ad7 fe6f0ef 5e00ad7 52994fc fe6f0ef ad7849a b8fb8cf ad7849a 0e4d3e5 ad7849a b8fb8cf fe6f0ef 5e00ad7 fe6f0ef 5e00ad7 fe6f0ef 5e00ad7 4b555a1 b8fb8cf fe6f0ef 4b555a1 0e4d3e5 5aab43b 0e4d3e5 fe6f0ef 5e00ad7 0e4d3e5 5e00ad7 87f72b7 fe6f0ef f973db1 |
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 |
import gradio as gr
import tensorflow as tf
from huggingface_hub import from_pretrained_keras
from tensorflow.keras import mixed_precision
# Load your trained models
#model1 = from_pretrained_keras("ml-debi/EfficientNetB0-Food101")
#model2 = from_pretrained_keras("ml-debi/EfficientNetB0-Food101")
model1 = from_pretrained_keras("ml-debi/EfficientNetV2S-Food101")
with open('classes.txt', 'r') as f:
classes = [line.strip() for line in f]
# Add information about the models
model1_info = """
### Model Information
Welcome to my Hugging Face space, where gastronomy meets technology! This space is dedicated to an image classifier that has been trained on the Food101 dataset.
At the core of this classifier lies the EfficientNetV2S base model, which has been fine-tuned to enhance its ability to identify a broad spectrum of food items with great accuracy.
While it may not be perfect, it’s a nice tool for culinary exploration. Enjoy your journey through the world of food! 🍽️
"""
#model2_info = """
#### Model 2 Information
#This model is based on the EfficientNetB0 architecture and was trained on augmented data, providing improved generalization.
#"""
examples = [["./examples/club_sandwich.jpg"], ["./examples/edamame.jpg"], ["./examples/eggs_benedict.jpg"]]
def preprocess(image):
print("before resize", image.shape)
image = tf.image.resize(image, [224, 224])
image = tf.expand_dims(image, axis=0)
print("After expanddims", image.shape)
return image
def predict(image):
# Choose the model based on the dropdown selection
#print("---model_selection---", model_selection) #
#model = model1 if model_selection == "EfficentNetB0 Fine Tune" else model2
#print(model.summary())
if mixed_precision.global_policy() == "mixed_float16":
mixed_precision.set_global_policy(policy="float32")
image = preprocess(image)
print(mixed_precision.global_policy())
prediction = model1.predict(image)[0]
print("model prediction", prediction)
confidences = {model1.config['id2label'][str(i)]: float(prediction[i]) for i in range(101)}
return confidences
iface = gr.Interface(
fn=predict,
inputs=[gr.Image()],
outputs=[gr.Label(num_top_classes=5)],
title="Food Vision Mini Project",
description=f"{model1_info}\n",
examples=examples
)
iface.launch()
|