Spaces:
Sleeping
Sleeping
File size: 1,099 Bytes
284eba0 |
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 |
import gradio as gr
import tensorflow as tf
import numpy as np
import gdown
from PIL import Image
input_shape = (32, 32, 3)
resized_shape = (224, 224, 3)
num_classes = 10
labels = {
0: "plane",
1: "car",
2: "bird",
3: "cat",
4: "deer",
5: "dog",
6: "frog",
7: "horse",
8: "ship",
9: "truck",
}
# a file
url = "https://drive.google.com/uc?id=12700bE-pomYKoVQ214VrpBoJ7akXcTpL"
output = "modelV2Lmixed.keras"
gdown.download(url, output, quiet=False)
def load_model():
model = tf.keras.models.load_model("./modelV2Lmixed.keras")
return model
def classify_image(image, model):
image = tf.cast(image, tf.float32)
image = tf.image.resize(image, [32, 32])
image = np.expand_dims(image, axis=0)
prediction = model.predict(image)
confidences = {labels[i]: float(prediction[i]) for i in range(10)}
return confidences
model = load_model()
gr.Interface(fn=classify_image,
inputs=gr.Image(shape=(32, 32)),
outputs=gr.Label(num_top_classes=3),
examples=["banana.jpg", "car.jpg"]).launch()
|