Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty mask overlay handling when no objects are detected. #350

Merged
merged 5 commits into from
Oct 22, 2024

Conversation

ro-hit81
Copy link
Contributor

Context

In the current implementation, when no object instances are found in the image, the function simply prints "No objects found in the image." and returns early, potentially leaving users without a usable output for downstream processing.

Proposed Changes
Empty Mask Overlay Creation: I added a line to create and return an empty mask overlay in cases where no objects are detected. This ensures that users still receive a consistent output type, even when no detections occur.

if boxes is None or (len(boxes) == 0): # No "object" instances found print("No objects found in the image.") mask_overlay = np.zeros_like(image_np[..., 0], dtype=dtype)
This change allows for easier downstream processing and integration, providing users with a consistent output type regardless of the detection results.

Related Issue
This addresses issue #348

@@ -342,6 +342,9 @@ def predict(

if boxes.nelement() == 0: # No "object" instances found
print("No objects found in the image.")
mask_overlay = np.zeros_like(
image_np[..., 0], dtype=dtype
) # Create an empty mask overlay
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the return statement needs to be removed here. Otherwise, the mask_overlay will not be returned

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, my bad. Corrected.

@giswqs giswqs merged commit 7d1d648 into opengeos:main Oct 22, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants