yuragoithf commited on
Commit
15f8afb
·
1 Parent(s): 30ff8c5

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -28
app.py CHANGED
@@ -5,41 +5,42 @@ 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
- model = tf.keras.models.load_model("./modelV2Lmixed.keras")
 
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(fn=classify_image,
43
- inputs=gr.Image(shape=(32, 32)),
44
- outputs=gr.Label(num_top_classes=3),
45
- examples=["03_cat.jpg", "05_dog.jpg"]).launch()
 
 
 
 
 
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()