veronhii commited on
Commit
259984c
·
1 Parent(s): b2d5c37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -1,11 +1,14 @@
1
  import gradio as gr
2
  import tensorflow as tf
3
- import numpy as input
4
 
5
  num_classes = 200
6
  IMG_HEIGHT = 256
7
  IMG_WIDTH = 256
8
 
 
 
 
9
  def normalize_image(img):
10
  img = tf.cast(img, tf.float32)/255.
11
  img = tf.image.resize(img, (IMG_HEIGHT, IMG_WIDTH), method='bilinear')
@@ -18,10 +21,15 @@ def predict_fn(img):
18
  x = np.array(img_data)
19
  x = np.expand_dims(x, axis=0)
20
  temp = model.predict(x)
21
- return temp
 
 
 
 
 
22
 
23
 
24
  model = tf.keras.models.load_model("model.h5")
25
 
26
- interface = gr.Interface(predict_fn, gr.inputs.Image(type='pil'), outputs='label', examples=path,)
27
  interface.launch()
 
1
  import gradio as gr
2
  import tensorflow as tf
3
+ import numpy as np
4
 
5
  num_classes = 200
6
  IMG_HEIGHT = 256
7
  IMG_WIDTH = 256
8
 
9
+ with open(output_path, 'r') as file:
10
+ CLASS_LABEL = [x.strip() for x in file.readlines()]
11
+
12
  def normalize_image(img):
13
  img = tf.cast(img, tf.float32)/255.
14
  img = tf.image.resize(img, (IMG_HEIGHT, IMG_WIDTH), method='bilinear')
 
21
  x = np.array(img_data)
22
  x = np.expand_dims(x, axis=0)
23
  temp = model.predict(x)
24
+
25
+ idx = np.argsort(np.squeeze(temp))[::-1]
26
+ top3_value = np.asarray([temp[0][i]] for i in idx[0:3])
27
+ top3_idx = idx[0:3]
28
+
29
+ return {CLASS_LABEL[i]:str(v) for i, v in zip(top3_idx,top3_value)}
30
 
31
 
32
  model = tf.keras.models.load_model("model.h5")
33
 
34
+ interface = gr.Interface(predict_fn, gr.inputs.Image(type='pil'), outputs='label')
35
  interface.launch()