Sa-m commited on
Commit
6b42335
·
verified ·
1 Parent(s): 963fd73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -12
app.py CHANGED
@@ -1,3 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import tensorflow as tf
3
  import numpy as np
@@ -6,7 +58,8 @@ import os
6
  # Configuration
7
  HEIGHT, WIDTH = 224, 224
8
  NUM_CLASSES = 6
9
- LABELS = [ "McDonalds","Burger King","Subway", "Starbucks", "KFC","Other"]
 
10
  from tensorflow_addons.metrics import F1Score
11
  from keras.utils import custom_object_scope
12
 
@@ -15,19 +68,15 @@ with custom_object_scope({'Addons>F1Score': F1Score}):
15
 
16
 
17
  def classify_image(inp):
18
- np.random.seed(143)
19
-
20
- # Ensure input is resized to expected shape
21
  inp = tf.image.resize(inp, [HEIGHT, WIDTH])
22
- inp = tf.cast(inp, tf.float32) # ensure correct dtype for preprocessing
23
  inp = tf.keras.applications.nasnet.preprocess_input(inp)
24
- inp = tf.expand_dims(inp, axis=0) # make batch dimension
25
-
26
- # Prediction
27
- prediction = model.predict(inp)
28
-
29
- return {LABELS[i]: float(f"{prediction[0][i]:.6f}") for i in range(NUM_CLASSES)}
30
 
 
 
 
31
 
32
  example_list = [
33
  ["Examples/Untitled.png"],
@@ -36,6 +85,7 @@ example_list = [
36
  ["Examples/Untitled5.png"]
37
  ]
38
 
 
39
  iface = gr.Interface(
40
  fn=classify_image,
41
  inputs=gr.Image(
@@ -51,4 +101,5 @@ iface = gr.Interface(
51
  )
52
 
53
  if __name__ == "__main__":
54
- iface.launch(debug=False,share=True)
 
 
1
+ # import gradio as gr
2
+ # import tensorflow as tf
3
+ # import numpy as np
4
+ # import os
5
+
6
+ # # Configuration
7
+ # HEIGHT, WIDTH = 224, 224
8
+ # NUM_CLASSES = 6
9
+ # LABELS = [ "McDonalds","Burger King","Subway", "Starbucks", "KFC","Other"]
10
+ # from tensorflow_addons.metrics import F1Score
11
+ # from keras.utils import custom_object_scope
12
+
13
+ # with custom_object_scope({'Addons>F1Score': F1Score}):
14
+ # model = tf.keras.models.load_model('best_model.h5')
15
+
16
+
17
+ # def classify_image(inp):
18
+ # np.random.seed(143)
19
+
20
+ # # Ensure input is resized to expected shape
21
+ # inp = tf.image.resize(inp, [HEIGHT, WIDTH])
22
+ # inp = tf.cast(inp, tf.float32) # ensure correct dtype for preprocessing
23
+ # inp = tf.keras.applications.nasnet.preprocess_input(inp)
24
+ # inp = tf.expand_dims(inp, axis=0) # make batch dimension
25
+
26
+ # # Prediction
27
+ # prediction = model.predict(inp)
28
+
29
+ # return {LABELS[i]: float(f"{prediction[0][i]:.6f}") for i in range(NUM_CLASSES)}
30
+
31
+
32
+
33
+
34
+ # iface = gr.Interface(
35
+ # fn=classify_image,
36
+ # inputs=gr.Image(
37
+ # label="Input Image",
38
+ # source="upload",
39
+ # type="numpy",
40
+ # height=HEIGHT,
41
+ # width=WIDTH
42
+ # ),
43
+ # outputs=gr.Label(num_top_classes=4),
44
+ # title="Brand Logo Detection",
45
+ # examples=example_list
46
+ # )
47
+
48
+ # if __name__ == "__main__":
49
+ # iface.launch(debug=False,share=True)
50
+
51
+
52
+
53
  import gradio as gr
54
  import tensorflow as tf
55
  import numpy as np
 
58
  # Configuration
59
  HEIGHT, WIDTH = 224, 224
60
  NUM_CLASSES = 6
61
+ LABELS = ["McDonalds", "Burger King", "Subway", "Starbucks", "KFC", "Other"]
62
+
63
  from tensorflow_addons.metrics import F1Score
64
  from keras.utils import custom_object_scope
65
 
 
68
 
69
 
70
  def classify_image(inp):
71
+ # Resize & preprocess
 
 
72
  inp = tf.image.resize(inp, [HEIGHT, WIDTH])
73
+ inp = tf.cast(inp, tf.float32)
74
  inp = tf.keras.applications.nasnet.preprocess_input(inp)
75
+ inp = tf.expand_dims(inp, axis=0)
 
 
 
 
 
76
 
77
+ # Predict
78
+ prediction = model.predict(inp)[0]
79
+ return {LABELS[i]: float(f"{prediction[i]:.6f}") for i in range(NUM_CLASSES)}
80
 
81
  example_list = [
82
  ["Examples/Untitled.png"],
 
85
  ["Examples/Untitled5.png"]
86
  ]
87
 
88
+
89
  iface = gr.Interface(
90
  fn=classify_image,
91
  inputs=gr.Image(
 
101
  )
102
 
103
  if __name__ == "__main__":
104
+ iface.launch(debug=False, share=True)
105
+