Spaces:
Sleeping
Sleeping
add more debug log
Browse files
app.py
CHANGED
|
@@ -12,19 +12,22 @@ def detect_traffic_signs(image):
|
|
| 12 |
:param image: PIL Image or numpy array
|
| 13 |
:return: numpy array of processed image
|
| 14 |
"""
|
|
|
|
| 15 |
# Convert PIL to numpy if necessary
|
| 16 |
if hasattr(image, 'convert'):
|
| 17 |
image = np.array(image)
|
| 18 |
-
|
|
|
|
| 19 |
# Convert RGB to BGR for OpenCV
|
| 20 |
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
| 21 |
-
|
|
|
|
| 22 |
# Perform detection
|
| 23 |
result_image = detector.detect(image)
|
| 24 |
-
|
| 25 |
# Convert back to RGB for Gradio
|
| 26 |
result_image = cv2.cvtColor(result_image, cv2.COLOR_BGR2RGB)
|
| 27 |
-
|
| 28 |
return result_image
|
| 29 |
|
| 30 |
# Create Gradio interface
|
|
|
|
| 12 |
:param image: PIL Image or numpy array
|
| 13 |
:return: numpy array of processed image
|
| 14 |
"""
|
| 15 |
+
print(f"Received image type: {type(image)}")
|
| 16 |
# Convert PIL to numpy if necessary
|
| 17 |
if hasattr(image, 'convert'):
|
| 18 |
image = np.array(image)
|
| 19 |
+
print(f"Converted PIL to numpy array, shape: {image.shape}")
|
| 20 |
+
|
| 21 |
# Convert RGB to BGR for OpenCV
|
| 22 |
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
| 23 |
+
print(f"Converted to BGR, shape: {image.shape}")
|
| 24 |
+
|
| 25 |
# Perform detection
|
| 26 |
result_image = detector.detect(image)
|
| 27 |
+
|
| 28 |
# Convert back to RGB for Gradio
|
| 29 |
result_image = cv2.cvtColor(result_image, cv2.COLOR_BGR2RGB)
|
| 30 |
+
|
| 31 |
return result_image
|
| 32 |
|
| 33 |
# Create Gradio interface
|
model.py
CHANGED
|
@@ -45,21 +45,25 @@ class TrafficSignDetector:
|
|
| 45 |
:param image: numpy array of the image
|
| 46 |
:return: image with drawn bounding boxes
|
| 47 |
"""
|
|
|
|
| 48 |
results = self.model(image, conf=self.conf_threshold)
|
| 49 |
-
|
|
|
|
| 50 |
for result in results:
|
| 51 |
boxes = result.boxes
|
|
|
|
| 52 |
for box in boxes:
|
| 53 |
# Get bounding box coordinates
|
| 54 |
x1, y1, x2, y2 = box.xyxy[0].cpu().numpy().astype(int)
|
| 55 |
conf = box.conf[0].cpu().numpy()
|
| 56 |
cls = int(box.cls[0].cpu().numpy())
|
| 57 |
-
|
|
|
|
| 58 |
# Draw bounding box
|
| 59 |
cv2.rectangle(image, (x1, y1), (x2, y2), self.box_color, self.thickness)
|
| 60 |
-
|
| 61 |
# Draw label
|
| 62 |
label = f"{self.classes[cls]}: {conf:.2f}"
|
| 63 |
cv2.putText(image, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, self.text_color, 2)
|
| 64 |
-
|
| 65 |
return image
|
|
|
|
| 45 |
:param image: numpy array of the image
|
| 46 |
:return: image with drawn bounding boxes
|
| 47 |
"""
|
| 48 |
+
print(f"Input image shape: {image.shape}")
|
| 49 |
results = self.model(image, conf=self.conf_threshold)
|
| 50 |
+
print(f"Number of results: {len(results)}")
|
| 51 |
+
|
| 52 |
for result in results:
|
| 53 |
boxes = result.boxes
|
| 54 |
+
print(f"Number of boxes in this result: {len(boxes)}")
|
| 55 |
for box in boxes:
|
| 56 |
# Get bounding box coordinates
|
| 57 |
x1, y1, x2, y2 = box.xyxy[0].cpu().numpy().astype(int)
|
| 58 |
conf = box.conf[0].cpu().numpy()
|
| 59 |
cls = int(box.cls[0].cpu().numpy())
|
| 60 |
+
print(f"Detected: {self.classes[cls]} with conf {conf:.2f} at ({x1},{y1})-({x2},{y2})")
|
| 61 |
+
|
| 62 |
# Draw bounding box
|
| 63 |
cv2.rectangle(image, (x1, y1), (x2, y2), self.box_color, self.thickness)
|
| 64 |
+
|
| 65 |
# Draw label
|
| 66 |
label = f"{self.classes[cls]}: {conf:.2f}"
|
| 67 |
cv2.putText(image, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, self.text_color, 2)
|
| 68 |
+
|
| 69 |
return image
|