sam3 icon indicating copy to clipboard operation
sam3 copied to clipboard

the reasons for bad segmentation results

Open JohnZhan2023 opened this issue 8 months ago • 1 comments

I try to segment the plane using prompt "plane", but got this

Image

Is there any flaws in my implementation?

model = build_sam3_image_model()
processor = Sam3Processor(model)
segm_mask = None
# Load an image
for frame_id in candidate_frames:
    image = video[:, frame_id].squeeze(0)  # C H W
    inference_state = processor.set_image(image)

    # Prompt the model with text
    output = processor.set_text_prompt(state=inference_state, prompt=prompt)

    # Get the masks, bounding boxes, and scores
    masks, boxes, scores = output["masks"], output["boxes"], output["scores"]
    if masks is not None and len(masks) > 0:
        if scores[0]>0.8:
            segm_mask = masks[0].unsqueeze(0).float()  # H W
            masked_image = overlay_masks(image, segm_mask)
            masked_image.save("saved_videos/masked_frame.png")
            break

JohnZhan2023 avatar Mar 25 '26 09:03 JohnZhan2023

I think there's probably an issue with the image formatting, either the channel ordering or normalization might not be correct.

You could try running the pre-processing steps on your input, something like:

from torchvision.transforms import v2
image = video[:, frame_id].squeeze(0)
image = v2.functional.to_image(image).to(processor.device)
image = processor.transform(image).unsqueeze(0)
print(image.mean())

If everything is working correctly, the result should have a mean near 0. If that is working, then the other thing to check is that your input is using RGB channel ordering.

Using a prompt of 'plane' on the image you posted gives this result:

Image

heyoeyo avatar Mar 25 '26 14:03 heyoeyo

I think there's probably an issue with the image formatting, either the channel ordering or normalization might not be correct.

You could try running the pre-processing steps on your input, something like:

from torchvision.transforms import v2 image = video[:, frame_id].squeeze(0) image = v2.functional.to_image(image).to(processor.device) image = processor.transform(image).unsqueeze(0) print(image.mean()) If everything is working correctly, the result should have a mean near 0. If that is working, then the other thing to check is that your input is using RGB channel ordering.

Using a prompt of 'plane' on the image you posted gives this result:

Image

Hi, heyoeyo, please could you solve that kind? https://github.com/facebookresearch/sam3/issues/501

olegkolesnik911 avatar Mar 26 '26 12:03 olegkolesnik911