Spaces:
Sleeping
Sleeping
Matej
commited on
Commit
·
0e4d3e5
1
Parent(s):
14d29bb
update my_app.py
Browse files
my_app.py
CHANGED
@@ -4,17 +4,12 @@ from huggingface_hub import from_pretrained_keras
|
|
4 |
from tensorflow.keras import mixed_precision
|
5 |
|
6 |
# Load your trained models
|
7 |
-
|
8 |
#model2 = from_pretrained_keras("ml-debi/EfficientNetB0-Food101")
|
9 |
|
10 |
-
# Try different keras model
|
11 |
-
model1 = from_pretrained_keras("NikiTricky/resnet50-food101")
|
12 |
-
|
13 |
with open('classes.txt', 'r') as f:
|
14 |
classes = [line.strip() for line in f]
|
15 |
|
16 |
-
print("Class names: ", classes)
|
17 |
-
|
18 |
# Add information about the models
|
19 |
model1_info = """
|
20 |
### Model 1 Information
|
@@ -31,9 +26,8 @@ This model is based on the EfficientNetB0 architecture and was trained on the Fo
|
|
31 |
def preprocess(image):
|
32 |
print("before resize", image.shape)
|
33 |
image = tf.image.resize(image, [224, 224])
|
34 |
-
|
35 |
image = tf.expand_dims(image, axis=0)
|
36 |
-
|
37 |
print("After expanddims", image.shape)
|
38 |
return image
|
39 |
|
@@ -48,17 +42,16 @@ def predict(image):
|
|
48 |
|
49 |
image = preprocess(image)
|
50 |
print(mixed_precision.global_policy())
|
51 |
-
prediction = model1.predict(image)
|
52 |
print("model prediction", prediction)
|
53 |
-
|
54 |
-
|
55 |
-
return predicted_class, confidence
|
56 |
|
57 |
iface = gr.Interface(
|
58 |
fn=predict,
|
59 |
inputs=[gr.Image()],
|
60 |
-
outputs=[gr.
|
61 |
-
title="
|
62 |
description=f"{model1_info}\n",
|
63 |
)
|
64 |
|
|
|
4 |
from tensorflow.keras import mixed_precision
|
5 |
|
6 |
# Load your trained models
|
7 |
+
model1 = from_pretrained_keras("ml-debi/EfficientNetB0-Food101")
|
8 |
#model2 = from_pretrained_keras("ml-debi/EfficientNetB0-Food101")
|
9 |
|
|
|
|
|
|
|
10 |
with open('classes.txt', 'r') as f:
|
11 |
classes = [line.strip() for line in f]
|
12 |
|
|
|
|
|
13 |
# Add information about the models
|
14 |
model1_info = """
|
15 |
### Model 1 Information
|
|
|
26 |
def preprocess(image):
|
27 |
print("before resize", image.shape)
|
28 |
image = tf.image.resize(image, [224, 224])
|
29 |
+
|
30 |
image = tf.expand_dims(image, axis=0)
|
|
|
31 |
print("After expanddims", image.shape)
|
32 |
return image
|
33 |
|
|
|
42 |
|
43 |
image = preprocess(image)
|
44 |
print(mixed_precision.global_policy())
|
45 |
+
prediction = model1.predict(image)[0]
|
46 |
print("model prediction", prediction)
|
47 |
+
confidences = {model1.config['id2label'][str(i)]: float(prediction[i]) for i in range(101)}
|
48 |
+
return confidences
|
|
|
49 |
|
50 |
iface = gr.Interface(
|
51 |
fn=predict,
|
52 |
inputs=[gr.Image()],
|
53 |
+
outputs=[gr.Label(num_top_classes=5)],
|
54 |
+
title="Food Vision Mini Project",
|
55 |
description=f"{model1_info}\n",
|
56 |
)
|
57 |
|