|
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", |
|
} |
|
|
|
|
|
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=["03_cat.jpg", "05_dog.jpg"]).launch() |
|
|