Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,65 +1,27 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import tensorflow as tf
|
3 |
import numpy as np
|
4 |
from tensorflow.keras.models import load_model
|
5 |
-
import tensorflow_addons as tfa
|
6 |
-
import os
|
7 |
-
import numpy as np
|
8 |
-
|
9 |
-
|
10 |
-
HEIGHT,WIDTH=224,224
|
11 |
-
IMG_SIZE=224
|
12 |
-
model=load_model('Models/best_model1.h5')
|
13 |
-
|
14 |
-
# def classify_image(inp):
|
15 |
-
# np.random.seed(143)
|
16 |
-
# inp = inp.reshape((-1, HEIGHT,WIDTH, 3))
|
17 |
-
# inp = tf.keras.applications.nasnet.preprocess_input(inp)
|
18 |
-
# prediction = model.predict(inp)
|
19 |
-
# ###label = dict((v,k) for k,v in labels.items())
|
20 |
-
# predicted_class_indices=np.argmax(prediction,axis=1)
|
21 |
-
# result = {}
|
22 |
-
# for i in range(len(predicted_class_indices)):
|
23 |
-
# if predicted_class_indices[i] < NUM_CLASSES:
|
24 |
-
# result[labels[predicted_class_indices[i]]]= float(predicted_class_indices[i])
|
25 |
-
# return result
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
# NUM_CLASSES = 2
|
31 |
-
# #inp = inp.reshape((-1, HEIGHT, WIDTH, 3))
|
32 |
-
# #inp = tf.keras.applications.nasnet.preprocess_input(inp)
|
33 |
-
# prediction = model.predict(inp)
|
34 |
-
# predicted_class_indices = np.argmax(prediction, axis=1)
|
35 |
-
|
36 |
-
# label_order = ["Cat","Dog"]
|
37 |
-
|
38 |
-
# result = {label: float(f"{prediction[0][labels[label]]:.6f}") for label in label_order}
|
39 |
-
|
40 |
-
# return result
|
41 |
|
42 |
def classify_image(inp):
|
43 |
-
NUM_CLASSES=2
|
44 |
-
|
45 |
-
labels = ['Cat','Dog']
|
46 |
inp = tf.image.resize(inp, [IMG_SIZE, IMG_SIZE])
|
47 |
-
inp = inp.numpy()
|
48 |
-
inp = inp.reshape((-1, IMG_SIZE, IMG_SIZE, 3))
|
49 |
inp = tf.keras.applications.vgg16.preprocess_input(inp)
|
50 |
prediction = model.predict(inp).flatten()
|
51 |
-
return {labels[i]:
|
52 |
|
53 |
-
image = gr.Image(height=HEIGHT,width=WIDTH,label='Input')
|
54 |
label = gr.Label(num_top_classes=2)
|
55 |
|
56 |
-
examples = [
|
57 |
-
["Examples/img1.png"],
|
58 |
-
["Examples/img2.png"],
|
59 |
-
["Examples/img3.png"],
|
60 |
-
["Examples/img4.png"]
|
61 |
-
]
|
62 |
-
|
63 |
|
64 |
gr.Interface(
|
65 |
fn=classify_image,
|
@@ -67,4 +29,4 @@ gr.Interface(
|
|
67 |
outputs=label,
|
68 |
title='Smart Pet Classifier',
|
69 |
examples=examples
|
70 |
-
).launch(debug=False)
|
|
|
1 |
+
# examples = [["Examples/img1.png"], ["Examples/img2.png"],["Examples/img3.png"], ["Examples/img4.png"]]
|
2 |
+
|
3 |
import gradio as gr
|
4 |
import tensorflow as tf
|
5 |
import numpy as np
|
6 |
from tensorflow.keras.models import load_model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
HEIGHT, WIDTH = 224, 224
|
9 |
+
IMG_SIZE = 224
|
10 |
+
model = load_model('Models/best_model1.h5')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
def classify_image(inp):
|
13 |
+
NUM_CLASSES = 2
|
14 |
+
labels = ['Cat', 'Dog']
|
|
|
15 |
inp = tf.image.resize(inp, [IMG_SIZE, IMG_SIZE])
|
16 |
+
inp = inp.numpy().reshape((-1, IMG_SIZE, IMG_SIZE, 3))
|
|
|
17 |
inp = tf.keras.applications.vgg16.preprocess_input(inp)
|
18 |
prediction = model.predict(inp).flatten()
|
19 |
+
return {labels[i]: float(prediction[i]) for i in range(NUM_CLASSES)} # Fixed: return floats
|
20 |
|
21 |
+
image = gr.Image(height=HEIGHT, width=WIDTH, label='Input')
|
22 |
label = gr.Label(num_top_classes=2)
|
23 |
|
24 |
+
examples = [["Examples/img1.png"], ["Examples/img2.png"],["Examples/img3.png"], ["Examples/img4.png"]]
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
gr.Interface(
|
27 |
fn=classify_image,
|
|
|
29 |
outputs=label,
|
30 |
title='Smart Pet Classifier',
|
31 |
examples=examples
|
32 |
+
).launch(debug=False)
|