Spaces:
Sleeping
Sleeping
Eric P. Nusbaum
commited on
Commit
·
4e8cd1a
1
Parent(s):
0b444ec
Update Space
Browse files
app.py
CHANGED
@@ -63,12 +63,11 @@ class Model:
|
|
63 |
outputs = self.session.run(self.output_names, {self.input_name: input_tensor})
|
64 |
|
65 |
# Process outputs
|
66 |
-
#
|
67 |
-
# Adjust based on your actual model's output format
|
68 |
if len(outputs) >= 3:
|
69 |
-
boxes = outputs[0]
|
70 |
-
labels = outputs[1].astype(int) # shape: [num_detections]
|
71 |
-
scores = outputs[2]
|
72 |
return boxes, labels, scores
|
73 |
else:
|
74 |
raise ValueError("Unexpected number of outputs from the model.")
|
@@ -87,7 +86,9 @@ def draw_boxes(image, boxes, labels, scores, threshold=0.5):
|
|
87 |
for box, label, score in zip(boxes, labels, scores):
|
88 |
if score < threshold:
|
89 |
continue
|
90 |
-
|
|
|
|
|
91 |
xmin, ymin, xmax, ymax = box
|
92 |
width, height = image.size
|
93 |
xmin = int(xmin * width)
|
@@ -108,10 +109,14 @@ def draw_boxes(image, boxes, labels, scores, threshold=0.5):
|
|
108 |
|
109 |
# Prediction function for Gradio
|
110 |
def predict_image(input_image):
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
|
|
|
|
|
|
|
|
115 |
|
116 |
# Define Gradio Interface
|
117 |
def get_example_images():
|
@@ -136,7 +141,7 @@ iface = gr.Interface(
|
|
136 |
examples=example_images,
|
137 |
title=title,
|
138 |
description=description,
|
139 |
-
allow_flagging="never"
|
140 |
)
|
141 |
|
142 |
# Launch the interface
|
|
|
63 |
outputs = self.session.run(self.output_names, {self.input_name: input_tensor})
|
64 |
|
65 |
# Process outputs
|
66 |
+
# Extract the first (and only) batch element
|
|
|
67 |
if len(outputs) >= 3:
|
68 |
+
boxes = outputs[0][0] # shape: [num_detections, 4]
|
69 |
+
labels = outputs[1][0].astype(int) # shape: [num_detections]
|
70 |
+
scores = outputs[2][0] # shape: [num_detections]
|
71 |
return boxes, labels, scores
|
72 |
else:
|
73 |
raise ValueError("Unexpected number of outputs from the model.")
|
|
|
86 |
for box, label, score in zip(boxes, labels, scores):
|
87 |
if score < threshold:
|
88 |
continue
|
89 |
+
if len(box) != 4:
|
90 |
+
print(f"Invalid box format: {box}")
|
91 |
+
continue
|
92 |
xmin, ymin, xmax, ymax = box
|
93 |
width, height = image.size
|
94 |
xmin = int(xmin * width)
|
|
|
109 |
|
110 |
# Prediction function for Gradio
|
111 |
def predict_image(input_image):
|
112 |
+
try:
|
113 |
+
boxes, labels, scores = model.predict(input_image)
|
114 |
+
output_image = input_image.copy()
|
115 |
+
output_image = draw_boxes(output_image, boxes, labels, scores, threshold=0.5)
|
116 |
+
return output_image
|
117 |
+
except Exception as e:
|
118 |
+
print(f"Error during prediction: {e}")
|
119 |
+
return input_image # Return the original image if prediction fails
|
120 |
|
121 |
# Define Gradio Interface
|
122 |
def get_example_images():
|
|
|
141 |
examples=example_images,
|
142 |
title=title,
|
143 |
description=description,
|
144 |
+
flagging_mode="never" # Updated from allow_flagging="never"
|
145 |
)
|
146 |
|
147 |
# Launch the interface
|