segment-anything icon indicating copy to clipboard operation
segment-anything copied to clipboard

error occurs in python scritps

Open YuhaoShan2018 opened this issue 2 years ago • 9 comments

1st :masks,_, _ = predictor.predict('bed')

AssertionError: point_labels must be supplied if point_coords is supplied.

2ed: from segment_anything import build_sam, SamAutomaticMaskGenerator mask_generator = SamAutomaticMaskGenerator(build_sam(checkpoint=pth_path)) masks = mask_generator_generate(img) NameError: name 'mask_generator_generate' is not defined

how to deal with that ques?

YuhaoShan2018 avatar Apr 06 '23 12:04 YuhaoShan2018

mask_generator_generate ->mask_generator.generate is done!

samuggi avatar Apr 06 '23 12:04 samuggi

thx! that's clear ,how about the 1st errors? what should I write the correct type of ?

YuhaoShan2018 avatar Apr 06 '23 12:04 YuhaoShan2018

I'm trying too! :)

samuggi avatar Apr 06 '23 13:04 samuggi

Traceback (most recent call last): File "/home/gabriel/workspace/MASKs/makeMasks.py", line 4, in masks = mask_generator.generate('chevette.jpg') File "/home/gabriel/.local/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context return func(*args, **kwargs) File "/home/gabriel/.local/lib/python3.10/site-packages/segment_anything/automatic_mask_generator.py", line 163, in generate mask_data = self._generate_masks(image) File "/home/gabriel/.local/lib/python3.10/site-packages/segment_anything/automatic_mask_generator.py", line 198, in _generate_masks orig_size = image.shape[:2] AttributeError: 'str' object has no attribute 'shape'

elbriga avatar Apr 06 '23 14:04 elbriga

AttributeError: 'str' object has no attribute 'shape' Could not get it to work

elbriga avatar Apr 06 '23 14:04 elbriga

AttributeError: 'str' object has no attribute 'shape' Could not get it to work

Has anyone solved this problem? I too have a 'str' object that has no 'shape' attribute. No idea how to deal with it. Help

NeuroLord avatar Apr 06 '23 17:04 NeuroLord

seams like the object should be a numpi, but is a string, anyone?

elbriga avatar Apr 06 '23 19:04 elbriga

像对象这样的接缝应该是一个 numpi,但是是一个字符串,有人吗?

img = cv2.imread("notebooks/images/dog.jpg") img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) predictor.set_image(img)

ZhouBay-TF avatar Apr 07 '23 02:04 ZhouBay-TF

seams like the object should be a numpi, but is a string, anyone?

it's a NumPy array of an image

wgsthink avatar Apr 07 '23 13:04 wgsthink

Should use cv2.imread() to load the image, this way will solve the problem saying " AttributeError: 'str' object has no attribute 'shape' "

NTUZZH avatar Jun 27 '23 06:06 NTUZZH