Spaces:
Sleeping
Sleeping
Commit
·
284eba0
1
Parent(s):
ee61100
Upload 2 files
Browse files- app.py +51 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
import numpy as np
|
4 |
+
import gdown
|
5 |
+
from PIL import Image
|
6 |
+
|
7 |
+
|
8 |
+
|
9 |
+
input_shape = (32, 32, 3)
|
10 |
+
resized_shape = (224, 224, 3)
|
11 |
+
num_classes = 10
|
12 |
+
labels = {
|
13 |
+
0: "plane",
|
14 |
+
1: "car",
|
15 |
+
2: "bird",
|
16 |
+
3: "cat",
|
17 |
+
4: "deer",
|
18 |
+
5: "dog",
|
19 |
+
6: "frog",
|
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 |
+
def load_model():
|
32 |
+
model = tf.keras.models.load_model("./modelV2Lmixed.keras")
|
33 |
+
return model
|
34 |
+
|
35 |
+
|
36 |
+
def classify_image(image, model):
|
37 |
+
image = tf.cast(image, tf.float32)
|
38 |
+
image = tf.image.resize(image, [32, 32])
|
39 |
+
image = np.expand_dims(image, axis=0)
|
40 |
+
prediction = model.predict(image)
|
41 |
+
confidences = {labels[i]: float(prediction[i]) for i in range(10)}
|
42 |
+
return confidences
|
43 |
+
|
44 |
+
|
45 |
+
model = load_model()
|
46 |
+
|
47 |
+
|
48 |
+
gr.Interface(fn=classify_image,
|
49 |
+
inputs=gr.Image(shape=(32, 32)),
|
50 |
+
outputs=gr.Label(num_top_classes=3),
|
51 |
+
examples=["banana.jpg", "car.jpg"]).launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow
|
2 |
+
gdown
|
3 |
+
gradio
|