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
15.11k stars 1.4k forks source link

trying to create dataset with sam masks but getting error #373

Open andysingal opened 1 year ago

andysingal commented 1 year ago

How to run on multiple images at the same time?

import supervision as sv

TEXT_PROMPT = "fox"
BOX_TRESHOLD = 0.35
TEXT_TRESHOLD = 0.25
TEXT_THRESHOLD = 0.25
TEXT_PROMPT = "fox . background"

MODEL_TYPE = "vit_h"  # default

IMAGE_PATH = f"/workspace/data/fox.jpg"

IMAGE_NAME = IMAGE_PATH.split("/")[-1]

image_source, image = load_image(IMAGE_PATH)

boxes, logits, phrases = predict(
    model=model,
    image=image,
    caption=TEXT_PROMPT,
    box_threshold=BOX_TRESHOLD,
    text_threshold=TEXT_TRESHOLD
)

annotated_frame = annotate(image_source=image_source, boxes=boxes, logits=logits, phrases=phrases)

%matplotlib inline
sv.plot_image(annotated_frame, (16, 16))

ERROR:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[24], line 16
     12 IMAGE_PATH = f"/workspace/data/fox.jpg"
     14 IMAGE_NAME = IMAGE_PATH.split("/")[-1]
---> 16 image_source, image = load_image(IMAGE_PATH)
     18 boxes, logits, phrases = predict(
     19     model=model,
     20     image=image,
   (...)
     23     text_threshold=TEXT_TRESHOLD
     24 )
     26 annotated_frame = annotate(image_source=image_source, boxes=boxes, logits=logits, phrases=phrases)

TypeError: cannot unpack non-iterable Image object
rentainhe commented 1 year ago

How to run on multiple images at the same time?

import supervision as sv

TEXT_PROMPT = "fox"
BOX_TRESHOLD = 0.35
TEXT_TRESHOLD = 0.25
TEXT_THRESHOLD = 0.25
TEXT_PROMPT = "fox . background"

MODEL_TYPE = "vit_h"  # default

IMAGE_PATH = f"/workspace/data/fox.jpg"

IMAGE_NAME = IMAGE_PATH.split("/")[-1]

image_source, image = load_image(IMAGE_PATH)

boxes, logits, phrases = predict(
    model=model,
    image=image,
    caption=TEXT_PROMPT,
    box_threshold=BOX_TRESHOLD,
    text_threshold=TEXT_TRESHOLD
)

annotated_frame = annotate(image_source=image_source, boxes=boxes, logits=logits, phrases=phrases)

%matplotlib inline
sv.plot_image(annotated_frame, (16, 16))

ERROR:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[24], line 16
     12 IMAGE_PATH = f"/workspace/data/fox.jpg"
     14 IMAGE_NAME = IMAGE_PATH.split("/")[-1]
---> 16 image_source, image = load_image(IMAGE_PATH)
     18 boxes, logits, phrases = predict(
     19     model=model,
     20     image=image,
   (...)
     23     text_threshold=TEXT_TRESHOLD
     24 )
     26 annotated_frame = annotate(image_source=image_source, boxes=boxes, logits=logits, phrases=phrases)

TypeError: cannot unpack non-iterable Image object

Maybe you can only try for loop to reach this now, because we did not support batch-inference yet I think

andysingal commented 1 year ago

Thanks Ren for your instant reply, would be nice to have support . Looking forward to it.

On Sat, Sep 9, 2023 at 9:58 PM Ren Tianhe @.***> wrote:

How to run on multiple images at the same time?

import supervision as sv

TEXT_PROMPT = "fox" BOX_TRESHOLD = 0.35 TEXT_TRESHOLD = 0.25 TEXT_THRESHOLD = 0.25 TEXT_PROMPT = "fox . background"

MODEL_TYPE = "vit_h" # default

IMAGE_PATH = f"/workspace/data/fox.jpg"

IMAGE_NAME = IMAGE_PATH.split("/")[-1]

image_source, image = load_image(IMAGE_PATH)

boxes, logits, phrases = predict( model=model, image=image, caption=TEXT_PROMPT, box_threshold=BOX_TRESHOLD, text_threshold=TEXT_TRESHOLD )

annotated_frame = annotate(image_source=image_source, boxes=boxes, logits=logits, phrases=phrases)

%matplotlib inline sv.plot_image(annotated_frame, (16, 16))

ERROR:


TypeError Traceback (most recent call last) Cell In[24], line 16 12 IMAGE_PATH = f"/workspace/data/fox.jpg" 14 IMAGE_NAME = IMAGE_PATH.split("/")[-1] ---> 16 image_source, image = load_image(IMAGE_PATH) 18 boxes, logits, phrases = predict( 19 model=model, 20 image=image, (...) 23 text_threshold=TEXT_TRESHOLD 24 ) 26 annotated_frame = annotate(image_source=image_source, boxes=boxes, logits=logits, phrases=phrases)

TypeError: cannot unpack non-iterable Image object

Maybe you can only try for loop to reach this now, because we did not support batch-inference yet I think

— Reply to this email directly, view it on GitHub https://github.com/IDEA-Research/Grounded-Segment-Anything/issues/373#issuecomment-1712549234, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE4LJNOBQUMIIIKBA6ATDIDXZSKLBANCNFSM6AAAAAA4RIPVSY . You are receiving this because you authored the thread.Message ID: @.***>