Refactor predict function: add debug prints for non-zero pixel values and update input sketchpad to grayscale mode
Browse files
app.py
CHANGED
@@ -39,6 +39,14 @@ def predict(data):
|
|
39 |
# Convert to NumPy array
|
40 |
img = np.array(data['composite'])
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
print("img.shape", img.shape)
|
43 |
|
44 |
# Handle RGBA or RGB images
|
@@ -80,7 +88,7 @@ label = gr.Label(num_top_classes=3)
|
|
80 |
# Open Gradio interface for sketch recognition
|
81 |
interface = gr.Interface(
|
82 |
fn=predict,
|
83 |
-
inputs=gr.Sketchpad(type='numpy'),
|
84 |
outputs=label,
|
85 |
title=title,
|
86 |
description=head,
|
|
|
39 |
# Convert to NumPy array
|
40 |
img = np.array(data['composite'])
|
41 |
|
42 |
+
# print non-zero values
|
43 |
+
print("non-zero values", np.count_nonzero(img))
|
44 |
+
for i in range(img.shape[0]):
|
45 |
+
for j in range(img.shape[1]):
|
46 |
+
for k in range(img.shape[2]):
|
47 |
+
if img[i][j][k] != 0:
|
48 |
+
print("img[i][j][k]", img[i][j][k])
|
49 |
+
|
50 |
print("img.shape", img.shape)
|
51 |
|
52 |
# Handle RGBA or RGB images
|
|
|
88 |
# Open Gradio interface for sketch recognition
|
89 |
interface = gr.Interface(
|
90 |
fn=predict,
|
91 |
+
inputs=gr.Sketchpad(type='numpy', image_mode='L', brush=gr.Brush()),
|
92 |
outputs=label,
|
93 |
title=title,
|
94 |
description=head,
|