Spaces:
Sleeping
Sleeping
File size: 2,143 Bytes
c0f15ab 51ec7f5 e62cc45 c0f15ab b1ba841 c0f15ab 7d71559 c0f15ab 7d71559 51ec7f5 e62cc45 c0f15ab e62cc45 c0f15ab e62cc45 51ec7f5 72a21b5 0322f6b c0f15ab |
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 65 66 67 68 |
# examples = [["Examples/img1.png"], ["Examples/img2.png"],["Examples/img3.png"], ["Examples/img4.png"]]
# import gradio as gr
# import tensorflow as tf
# import numpy as np
# from tensorflow.keras.models import load_model
# HEIGHT, WIDTH = 224, 224
# IMG_SIZE = 224
# model = load_model('Models/best_model1.h5')
# def classify_image(inp):
# NUM_CLASSES = 2
# labels = ['Cat', 'Dog']
# inp = tf.image.resize(inp, [IMG_SIZE, IMG_SIZE])
# inp = inp.numpy().reshape((-1, IMG_SIZE, IMG_SIZE, 3))
# inp = tf.keras.applications.vgg16.preprocess_input(inp)
# prediction = model.predict(inp).flatten()
# return {labels[i]: float(prediction[i]) for i in range(NUM_CLASSES)} # Fixed: return floats
# image = gr.Image(height=HEIGHT, width=WIDTH, label='Input')
# label = gr.Label(num_top_classes=2)
# examples = [["Examples/img1.png"], ["Examples/img2.png"],["Examples/img3.png"], ["Examples/img4.png"]]
# gr.Interface(
# fn=classify_image,
# inputs=image,
# outputs=label,
# title='Smart Pet Classifier',
# examples=examples
# ).launch(debug=False)
import gradio as gr
import tensorflow as tf
import numpy as np
from tensorflow.keras.models import load_model
HEIGHT, WIDTH = 224, 224
IMG_SIZE = 224
model = load_model('Models/best_model1.h5')
def classify_image(inp):
labels = ['Cat', 'Dog']
inp = tf.image.resize(inp, [IMG_SIZE, IMG_SIZE])
inp = inp.numpy().reshape((-1, IMG_SIZE, IMG_SIZE, 3))
inp = tf.keras.applications.vgg16.preprocess_input(inp)
prediction = model.predict(inp).flatten()
if len(prediction) == 1:
dog_prob = float(prediction[0])
return {labels[0]: 1 - dog_prob, labels[1]: dog_prob}
else:
return {labels[i]: float(prediction[i]) for i in range(len(labels))}
image = gr.Image(height=HEIGHT, width=WIDTH, label='Input')
label = gr.Label(num_top_classes=2)
examples = [["Examples/img1.png"], ["Examples/img2.png"],["Examples/img3.png"], ["Examples/img4.png"]]
gr.Interface(
fn=classify_image,
inputs=image,
outputs=label,
title='Smart Pet Classifier',
# examples=examples
).launch(debug=False) |