yuragoithf
commited on
Commit
·
15f8afb
1
Parent(s):
30ff8c5
Upload app.py
Browse files
app.py
CHANGED
@@ -5,41 +5,42 @@ import gdown
|
|
5 |
from PIL import Image
|
6 |
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
7: "horse",
|
21 |
-
8: "ship",
|
22 |
-
9: "truck",
|
23 |
-
}
|
24 |
|
25 |
# a file
|
26 |
url = "https://drive.google.com/uc?id=12700bE-pomYKoVQ214VrpBoJ7akXcTpL"
|
27 |
output = "modelV2Lmixed.keras"
|
28 |
gdown.download(url, output, quiet=False)
|
29 |
|
30 |
-
|
|
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
-
def classify_image(image, model):
|
34 |
-
image = tf.cast(image, tf.float32)
|
35 |
-
image = tf.image.resize(image, [32, 32])
|
36 |
-
image = np.expand_dims(image, axis=0)
|
37 |
-
prediction = model.predict(image)
|
38 |
-
#confidences = {labels[i]: float(prediction[i]) for i in range(10)}
|
39 |
-
return prediction
|
40 |
|
|
|
41 |
|
42 |
-
gr.Interface(
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
5 |
from PIL import Image
|
6 |
|
7 |
|
8 |
+
labels = [
|
9 |
+
"plane",
|
10 |
+
"car",
|
11 |
+
"bird",
|
12 |
+
"cat",
|
13 |
+
"deer",
|
14 |
+
"dog",
|
15 |
+
"frog",
|
16 |
+
"horse",
|
17 |
+
"ship",
|
18 |
+
"truck",
|
19 |
+
]
|
|
|
|
|
|
|
|
|
20 |
|
21 |
# a file
|
22 |
url = "https://drive.google.com/uc?id=12700bE-pomYKoVQ214VrpBoJ7akXcTpL"
|
23 |
output = "modelV2Lmixed.keras"
|
24 |
gdown.download(url, output, quiet=False)
|
25 |
|
26 |
+
inception_net = tf.keras.models.load_model("./modelV2Lmixed.keras")
|
27 |
+
|
28 |
|
29 |
+
def classify_image(inp):
|
30 |
+
inp = inp.reshape((-1, 224, 224, 3))
|
31 |
+
inp = tf.keras.applications.efficientnet.preprocess_input(inp)
|
32 |
+
prediction = inception_net.predict(inp).flatten()
|
33 |
+
confidences = {labels[i]: float(prediction[i]) for i in range(10)}
|
34 |
+
return confidences
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
+
import gradio as gr
|
38 |
|
39 |
+
gr.Interface(
|
40 |
+
fn=classify_image,
|
41 |
+
inputs=gr.inputs.Image(shape=(32, 32)),
|
42 |
+
outputs=gr.outputs.Label(num_top_classes=3),
|
43 |
+
examples=["03_cat.jpg", "05_dog.jpg"],
|
44 |
+
theme="default",
|
45 |
+
css=".footer{display:none !important}",
|
46 |
+
).launch()
|