Spaces:
Running
Running
File size: 1,298 Bytes
6b42335 159fb0f 0e3827e 28ef308 0e3827e 28ef308 6b42335 873b8a1 96d2d57 52af948 e22f878 74a719c 6b42335 b0e91bc 6b42335 5b3415e 6b42335 28ef308 6b42335 b0e91bc 963fd73 6b42335 28ef308 6a269e3 963fd73 28ef308 963fd73 28ef308 6b42335 |
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 |
import gradio as gr
import tensorflow as tf
import numpy as np
import os
# Configuration
HEIGHT, WIDTH = 224, 224
NUM_CLASSES = 6
LABELS = ["McDonalds", "Burger King", "Subway", "Starbucks", "KFC", "Other"]
from tensorflow_addons.metrics import F1Score
from keras.utils import custom_object_scope
with custom_object_scope({'Addons>F1Score': F1Score}):
model = tf.keras.models.load_model('best_model.h5')
def classify_image(inp):
# Resize & preprocess
inp = tf.image.resize(inp, [HEIGHT, WIDTH])
inp = tf.cast(inp, tf.float32)
inp = tf.keras.applications.nasnet.preprocess_input(inp)
inp = tf.expand_dims(inp, axis=0)
# Predict
prediction = model.predict(inp)[0]
return {LABELS[i]: float(f"{prediction[i]:.6f}") for i in range(NUM_CLASSES)}
example_list = [
["Examples/Untitled.png"],
["Examples/Untitled2.png"],
["Examples/Untitled3.png"],
["Examples/Untitled5.png"]
]
iface = gr.Interface(
fn=classify_image,
inputs=gr.Image(
label="Input Image",
sources="upload",
type="numpy",
height=HEIGHT,
width=WIDTH
),
outputs=gr.Label(num_top_classes=4),
title="Brand Logo Detection",
examples=example_list
)
if __name__ == "__main__":
iface.launch(debug=False, share=True)
|