facebookresearch / segment-anything

The repository provides code for running inference with the SegmentAnything Model (SAM), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.
Apache License 2.0
47.18k stars 5.59k forks source link

Prompt error #431

Open okanduzyel opened 1 year ago

okanduzyel commented 1 year ago

Hi,

I have got that prompt issue below:

Traceback (most recent call last):
  File "/Users/okanduzyel/Downloads/segment-anything/testWithPrompt.py", line 23, in <module>
    masks, _, _ = predictor.predict("brain tumor")
  File "/Users/okanduzyel/Downloads/segment-anything/segment_anything/predictor.py", line 139, in predict
    assert (
AssertionError: point_labels must be supplied if point_coords is supplied.

My code:

import cv2
import matplotlib.pyplot as plt
import numpy as np
import os
import argparse

from segment_anything import SamPredictor, sam_model_registry
sam = sam_model_registry["vit_h"](checkpoint="/Users/okanduzyel/Downloads/segment-anything/sam_vit_h_4b8939.pth")
predictor = SamPredictor(sam)

image_path = '/Users/okanduzyel/Downloads/archive-2/Testing/glioma_tumor/image.jpg' #args.input
img = cv2.imread(image_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

predictor.set_image(img)

masks, _, _ = predictor.predict("brain tumor")

Any idea?

DUT-CSJ commented 1 year ago

Hi,

I have got that prompt issue below:

Traceback (most recent call last):
  File "/Users/okanduzyel/Downloads/segment-anything/testWithPrompt.py", line 23, in <module>
    masks, _, _ = predictor.predict("brain tumor")
  File "/Users/okanduzyel/Downloads/segment-anything/segment_anything/predictor.py", line 139, in predict
    assert (
AssertionError: point_labels must be supplied if point_coords is supplied.

My code:

import cv2
import matplotlib.pyplot as plt
import numpy as np
import os
import argparse

from segment_anything import SamPredictor, sam_model_registry
sam = sam_model_registry["vit_h"](checkpoint="/Users/okanduzyel/Downloads/segment-anything/sam_vit_h_4b8939.pth")
predictor = SamPredictor(sam)

image_path = '/Users/okanduzyel/Downloads/archive-2/Testing/glioma_tumor/image.jpg' #args.input
img = cv2.imread(image_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

predictor.set_image(img)

masks, _, _ = predictor.predict("brain tumor")

Any idea?

It seems you use text as prompt "brain tumor" while the open-source SAM only support point or box now. The SAM support text is not available now.

Suncheng2022 commented 1 year ago

Will the ability to use text for segmentation be open source?

FGarridoV commented 1 year ago

Check this