zuzu
commited on
Commit
•
65357fb
1
Parent(s):
65ae605
dilating drawings to better match training data
Browse files- app.py +5 -4
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,24 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
import tensorflow as tf
|
3 |
import numpy as np
|
|
|
4 |
|
5 |
model = tf.keras.models.load_model("mymodel/mymodel")
|
6 |
|
7 |
def predict(img):
|
8 |
z = tf.keras.preprocessing.image.img_to_array(img)
|
|
|
|
|
9 |
z = np.expand_dims(z, axis=0)
|
10 |
-
print(z.shape, z)
|
11 |
y = model.predict(z)
|
12 |
ysoft = tf.nn.softmax(y)
|
13 |
ymax = np.argmax(ysoft)
|
14 |
-
return ymax
|
15 |
|
16 |
-
sp = gr.Sketchpad(shape=(140,100), image_mode="L", label='arabic numeral', invert_colors=False).style(height=200, width=280)
|
17 |
gr.Label()
|
18 |
gr.Interface(fn=predict,
|
19 |
inputs=sp,
|
20 |
outputs="label",
|
21 |
-
share=True,
|
22 |
live=True,
|
23 |
examples=[
|
24 |
["writer001_pass01_digit2.png"],
|
|
|
1 |
import gradio as gr
|
2 |
import tensorflow as tf
|
3 |
import numpy as np
|
4 |
+
import cv2
|
5 |
|
6 |
model = tf.keras.models.load_model("mymodel/mymodel")
|
7 |
|
8 |
def predict(img):
|
9 |
z = tf.keras.preprocessing.image.img_to_array(img)
|
10 |
+
kernel = np.ones((5,5),np.uint8)
|
11 |
+
z = cv2.dilate(z ,kernel,iterations = 1)
|
12 |
z = np.expand_dims(z, axis=0)
|
|
|
13 |
y = model.predict(z)
|
14 |
ysoft = tf.nn.softmax(y)
|
15 |
ymax = np.argmax(ysoft)
|
16 |
+
return int(ymax)
|
17 |
|
18 |
+
sp = gr.Sketchpad(tool="sketch", shape=(140,100), image_mode="L", label='arabic numeral', invert_colors=False).style(height=200, width=280)
|
19 |
gr.Label()
|
20 |
gr.Interface(fn=predict,
|
21 |
inputs=sp,
|
22 |
outputs="label",
|
|
|
23 |
live=True,
|
24 |
examples=[
|
25 |
["writer001_pass01_digit2.png"],
|
requirements.txt
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
numpy == 1.21.3
|
2 |
-
tensorflow == 2.10.1
|
|
|
|
1 |
numpy == 1.21.3
|
2 |
+
tensorflow == 2.10.1
|
3 |
+
cv2
|