--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Cell In[11], line 1 ----> 1 predictor.set_image("bingbao.jpg") File /workspace/segment-anything/segment_anything/predictor.py:56, in SamPredictor.set_image(self, image, image_format) 53 image = image[..., ::-1] 55 # Transform the image to the form expected by the model ---> 56 input_image = self.transform.apply_image(image) 57 input_image_torch = torch.as_tensor(input_image, device=self.device) 58 input_image_torch = input_image_torch.permute(2, 0, 1).contiguous()[None, :, :, :] File /workspace/segment-anything/segment_anything/utils/transforms.py:30, in ResizeLongestSide.apply_image(self, image) 26 def apply_image(self, image: np.ndarray) -> np.ndarray: 27 """ 28 Expects a numpy array with shape HxWxC in uint8 format. 29 """ ---> 30 target_size = self.get_preprocess_shape(image.shape[0], image.shape[1], self.target_length) 31 return np.array(resize(to_pil_image(image), target_size)) AttributeError: 'str' object has no attribute 'shape'
时间: 2023-08-27 12:39:22 浏览: 298
这是一个Python的AttributeError错误,错误信息显示在predictor.py的第56行,因为传递给set_image方法的参数是一个字符串而不是numpy数组,因此在apply_image方法中调用image.shape时会出错。解决方法是在调用set_image方法之前将图像转换为numpy数组。例如,可以使用OpenCV库中的imread方法读取图像并将其转换为numpy数组。
阅读全文