Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -25,6 +25,7 @@ def preprocess_image(image):
|
|
25 |
try:
|
26 |
image = image.convert("RGB") # Ensure image is in RGB mode
|
27 |
image_tensor = F.to_tensor(image)
|
|
|
28 |
return image_tensor.unsqueeze(0).to(device)
|
29 |
except Exception as e:
|
30 |
print(f"Error in preprocessing image: {e}")
|
@@ -55,7 +56,12 @@ def detect_objects(image):
|
|
55 |
return image
|
56 |
try:
|
57 |
outputs = model(image_tensor)[0] # Get the first element of the output
|
|
|
58 |
outputs = non_max_suppression(outputs, conf_thres=0.25, iou_thres=0.45)[0] # Apply NMS
|
|
|
|
|
|
|
|
|
59 |
result_image = draw_boxes(image, outputs)
|
60 |
return result_image
|
61 |
except Exception as e:
|
|
|
25 |
try:
|
26 |
image = image.convert("RGB") # Ensure image is in RGB mode
|
27 |
image_tensor = F.to_tensor(image)
|
28 |
+
print(f"Preprocessed image tensor: {image_tensor.shape}")
|
29 |
return image_tensor.unsqueeze(0).to(device)
|
30 |
except Exception as e:
|
31 |
print(f"Error in preprocessing image: {e}")
|
|
|
56 |
return image
|
57 |
try:
|
58 |
outputs = model(image_tensor)[0] # Get the first element of the output
|
59 |
+
print(f"Model raw outputs: {outputs}")
|
60 |
outputs = non_max_suppression(outputs, conf_thres=0.25, iou_thres=0.45)[0] # Apply NMS
|
61 |
+
if outputs is None or len(outputs) == 0:
|
62 |
+
print("No objects detected.")
|
63 |
+
return image
|
64 |
+
print(f"Filtered outputs: {outputs}")
|
65 |
result_image = draw_boxes(image, outputs)
|
66 |
return result_image
|
67 |
except Exception as e:
|