IDEA-Research / Grounded-Segment-Anything

Grounded SAM: Marrying Grounding DINO with Segment Anything & Stable Diffusion & Recognize Anything - Automatically Detect , Segment and Generate Anything
https://arxiv.org/abs/2401.14159
Apache License 2.0
14.85k stars 1.37k forks source link

The size of the mask and raw image don't match #210

Open Puhouchen opened 1 year ago

Puhouchen commented 1 year ago

After running grounded_sam_demo.py, the size of the mask and raw image don't match each other. Although the mask can be resized, i wonder why the size of mask has been changed? keeping the same size maybe a normal idea...

rentainhe commented 1 year ago

After running grounded_sam_demo.py, the size of the mask and raw image don't match each other. Although the mask can be resized, i wonder why the size of mask has been changed? keeping the same size maybe a normal idea...

Would you like to share the image you've tested for this issue~

Puhouchen commented 1 year ago
    thanks for your reply!My command is as follows and images in attachment which have different size:python

grounded_sam_demo.py \  --config GroundingDINO/groundingdino/config/GroundingDINO_SwinT_OGC.py \  --grounded_checkpoint groundingdino_swint_ogc.pth \  --sam_checkpoint sam_vit_h_4b8939.pth \  --input_image assets/dophin_and_man.jpeg \  --output_dir "outputs" \  --box_threshold 0.3 \  --text_threshold 0.25 \  --text_prompt "dolphin" \  --device "cuda"

                ***@***.***

---- Replied Message ----

     From 

        Ren ***@***.***>

     Date 

    5/2/2023 22:06

     To 

        ***@***.***>

     Cc 

        ***@***.***>
        ,

        ***@***.***>

     Subject 

          Re: [IDEA-Research/Grounded-Segment-Anything] The size of the mask and raw image don't match (Issue #210)

After running grounded_sam_demo.py, the size of the mask and raw image don't match each other. Although the mask can be resized, i wonder why the size of mask has been changed? keeping the same size maybe a normal idea...

Would you like to share the image you've tested for this issue~

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

Puhouchen commented 1 year ago

dophin_and_man mask

antarestcguo commented 1 year ago

The same problem. the shape of raw image input to the demo is (1280, 853, 3). The output mask's shape is (2310, 1539, 3). The scaling ratio is not a integer.

Niuxf16 commented 1 year ago

The size of the mask.jpg depends on the figsize and dpi of the matplotlib used to plot the mask in ‘save_mask_data’ function in ‘grounded_sam_demo.py’ , as for example, using the following code, the size of the mask.jpg will be 3000x3000x3

plt.figure(figsize=(10, 10))
plt.imshow(mask_img.numpy())
plt.axis('off')
plt.savefig(os.path.join(output_dir, 'mask.jpg'), dpi=300, pad_inches=0.0)
# plt.savefig(os.path.join(output_dir, 'mask.jpg'), bbox_inches="tight", dpi=300, pad_inches=0.0)

if your want to use the mask value whose size is equal to raw_jpg , you can just save the variable ‘mask_img’ by

np.save(os.path.join(output_dir,'mask.npy'),mask_img)