开发者社区 > ModelScope模型即服务 > 计算机视觉 > 正文

BSHM人像抠图,小白,这个报错,大佬给指点下,谢谢了。

FileNotFoundError: [Errno 2] No such file or directory: '\u202aD:\x01\x01.png'


FileNotFoundError Traceback (most recent call last)
Cell In[2], line 7
4 from modelscope.outputs import OutputKeys
6 portrait_matting = pipeline(Tasks.portrait_matting,model='damo/cv_unet_image-matting')
----> 7 result = portrait_matting('‪D:\1\1.png')
8 cv2.imwrite('result.png', result[OutputKeys.OUTPUT_IMG])

File /opt/conda/lib/python3.8/site-packages/modelscope/pipelines/base.py:219, in Pipeline.call(self, input, args, **kwargs)
216 return self._process_iterator(input,
args, kwargs)
218 else:
--> 219 output = self._process_single(input, *args,
kwargs)
220 return output

File /opt/conda/lib/python3.8/site-packages/modelscope/pipelines/base.py:247, in Pipeline._process_single(self, input, args, *kwargs)
245 postprocess_params = kwargs.get('postprocess_params', {})
246 self._check_input(input)
--> 247 out = self.preprocess(input,
preprocess_params)
249 with device_placement(self.framework, self.device_name):
250 if self.framework == Frameworks.torch:

File /opt/conda/lib/python3.8/site-packages/modelscope/pipelines/cv/image_matting_pipeline.py:55, in ImageMattingPipeline.preprocess(self, input)
54 def preprocess(self, input: Input) -> Dict[str, Any]:
---> 55 img = LoadImage.convert_to_ndarray(input)
56 img = img.astype(float)
57 result = {'img': img}

File /opt/conda/lib/python3.8/site-packages/modelscope/preprocessors/image.py:89, in LoadImage.convert_to_ndarray(input)
86 @staticmethod
87 def convert_to_ndarray(input) -> ndarray:
88 if isinstance(input, str):
---> 89 img = np.array(load_image(input))
90 elif isinstance(input, PIL.Image.Image):
91 img = np.array(input.convert('RGB'))

File /opt/conda/lib/python3.8/site-packages/modelscope/preprocessors/image.py:133, in load_image(image_path_or_url)
127 """ simple interface to load an image from file or url
128
129 Args:
130 image_path_or_url (str): image file path or http url
131 """
132 loader = LoadImage()
--> 133 return loader(image_path_or_url)['img']

File /opt/conda/lib/python3.8/site-packages/modelscope/preprocessors/image.py:57, in LoadImage.call(self, input)
55 img_shape = (img_h, img_w, img_c)
56 elif self.backend == 'pillow':
---> 57 bytes = File.read(image_path_or_url)
58 # TODO @wenmeng.zwm add opencv decode as optional
59 # we should also look at the input format which is the most commonly
60 # used in Mind' image related models
61 with io.BytesIO(bytes) as infile:

File /opt/conda/lib/python3.8/site-packages/modelscope/fileio/file.py:274, in File.read(uri)
265 """Read data from a given filepath with 'rb' mode.
266
267 Args:
(...)
271 bytes: Expected bytes object.
272 """
273 storage = File._get_storage(uri)
--> 274 return storage.read(uri)

File /opt/conda/lib/python3.8/site-packages/modelscope/fileio/file.py:53, in LocalStorage.read(self, filepath)
44 def read(self, filepath: Union[str, Path]) -> bytes:
45 """Read data from a given filepath with 'rb' mode.
46
47 Args:
(...)
51 bytes: Expected bytes object.
52 """
---> 53 with open(filepath, 'rb') as f:
54 content = f.read()
55 return content

FileNotFoundError: [Errno 2] No such file or directory: '\u202aD:\x01\x01.png'火狐截图_2023-11-26T13-15-29.937Z.png
火狐截图_2023-11-26T13-16-57.783Z.png

展开
收起
不懂46 2023-11-26 21:23:02 178 0
4 条回答
写回答
取消 提交回答
  • 面对过去,不要迷离;面对未来,不必彷徨;活在今天,你只要把自己完全展示给别人看。

    它似乎表示无法找到文件 "\u202aD:\x01\x01.png" 。该文件路径中的字节顺序标记(BOM)可能导致文件路径识别错误,建议将文件名中删除 BOM 或将文件路径转义成字符串进行引用即可解决此问题。
    另外,可以检查该文件是否存在,并确保脚本有足够的权限读取该文件。请确保文件路径正确无误,并遵循相关操作系统的文件命名规则,以免发生此类错误。

    2023-11-27 13:12:59
    赞同 展开评论 打赏
  • 这个错误是因为您指定的图片文件路径不存在或不可读。请检查您的输入文件路径是否正确,并确保文件存在并且可以被读取。请注意代码中的特殊字符 \u202a\x01 ,这两个转义序列可能会导致文件路径解析失败。建议您直接使用原始字符串字面量 r'D:/1/1.png' 来表示路径,以避免任何编码问题。

    2023-11-27 11:58:34
    赞同 展开评论 打赏
  • 北京阿里云ACE会长

    从错误信息来看,问题出在文件路径上。\u202aD:\x01\x01.png 不是一个有效的文件路径。请检查您提供的文件路径是否正确,并确保文件存在于指定的位置。如果文件路径包含特殊字符,请尝试将其替换为常规字符。
    另外,文件路径中的 \x01 可能是 Unicode 编码问题导致的。您可以尝试将文件路径从 Unicode 转换为 ASCII 编码,然后再次尝试加载文件。可以使用 Python 的 encode() 方法将 Unicode 字符串转换为 ASCII 编码的字节串。例如:

    file_path = 'D:\x01\1.png'
    file_path_ascii = file_path.encode('ascii', errors='ignore').decode()
    CopyCopy

    然后,使用转换后的文件路径尝试加载文件:

    result = portrait_matting(file_path_ascii)
    CopyCopy

    如果问题仍然存在,请检查文件是否具有正确的格式和扩展名(例如,.png),以及文件是否处于正确的位置。

    2023-11-27 09:35:33
    赞同 展开评论 打赏
  • 这个错误信息“FileNotFoundError:[Errno 2] No such file or directory”表明指定路径“‪D:\1\1.png”下的文件不存在。这可能是因为文件名或路径中的拼写错误,或者是文件已被移动或删除。请检查文件名和路径,确保文件存在并具有正确的读取权限。

    2023-11-27 09:15:54
    赞同 1 展开评论 打赏

包含图像分类、图像生成、人体人脸识别、动作识别、目标分割、视频生成、卡通画、视觉评价、三维视觉等多个领域

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载