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

Unset output results in empty objects #295

Closed
erthromero opened this issue Jun 27, 2024 · 0 comments · Fixed by #318
Closed

Unset output results in empty objects #295

erthromero opened this issue Jun 27, 2024 · 0 comments · Fixed by #318
Labels
bug Something isn't working

Comments

@erthromero
Copy link

Environment Information

  • samgeo version: 0.10.6
  • Python version: 3.10.14
  • Operating System: Windows 10

Description

I've been attempting to save segments to an in-memory numpy array by leaving the 'output' variable as None in my code when running the generate function with the SamGeo object. Here is some of my code for an example:

sam_kwargs = {
"points_per_side": 70,
"pred_iou_thresh": 0.9,
"stability_score_thresh": 0.92,
"crop_n_layers": 1,
"crop_n_points_downscale_factor": 2,
"min_mask_region_area": 80,
}

sam = SamGeo(
    model_type="vit_h",
    checkpoint="E:\\SummerGSR2024\\MLModels\\SAM-Eo\\sam_vit_h_4b8939.pth",
    sam_kwargs=sam_kwargs,
)

sam.generate(source=image[:,:,:3], foreground=False, unique=True, batch=False)
segmentation = sam.objects

When I do this, the variable 'segmentation' returns None. After some debugging the samgeo.py script, I found where this error is coming from. Line 225 through 229 only calls the 'save_segments' function if the argument 'output' is not None. This seemed a little silly since 'output' defaults to None.

Anyways, I found the bug and fixed it by changing the code in lines 225 through 229 from this:

if output is not None:
# Save the masks to the output path. The output is either a binary mask or a mask of objects with unique values.
self.save_masks(
output, foreground, unique, erosion_kernel, mask_multiplier, **kwargs
)

to this:

Save the masks to the output path. The output is either a binary mask or a mask of objects with unique values.

    self.save_masks(
        output, foreground, unique, erosion_kernel, mask_multiplier, **kwargs
    )
@erthromero erthromero added the bug Something isn't working label Jun 27, 2024
@giswqs giswqs linked a pull request Sep 21, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant