当我在jupyter notebook里想展示一张图片时,我使用了以下代码:
import matplotlib.pyplot as plt
import skimage.io as io
path = "E:\pythonFiles\YOLOX\YOLOX_outputs\yolox_l\vis_res\2022_06_06_16_26_36\dog.jpg"
image = io.imread(path)
plt.imshow(image)
然后jupyter notebook给出了报错:
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_1280\1200427059.py in <module>
3
4 path = "E:\pythonFiles\YOLOX\YOLOX_outputs\yolox_l\vis_res\2022_06_06_16_26_36\dog.jpg"
----> 5 image = io.imread(path)
6 plt.imshow(image)
~\AppData\Roaming\Python\Python37\site-packages\skimage\io\_io.py in imread(fname, as_gray, plugin, **plugin_args)
51
52 with file_or_url_context(fname) as fname:
---> 53 img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
54
55 if not hasattr(img, 'ndim'):
~\AppData\Roaming\Python\Python37\site-packages\skimage\io\manage_plugins.py in call_plugin(kind, *args, **kwargs)
205 (plugin, kind))
206
--> 207 return func(*args, **kwargs)
208
209
~\AppData\Roaming\Python\Python37\site-packages\skimage\io\_plugins\imageio_plugin.py in imread(*args, **kwargs)
8 @wraps(imageio_imread)
9 def imread(*args, **kwargs):
---> 10 return np.asarray(imageio_imread(*args, **kwargs))
~\AppData\Roaming\Python\Python37\site-packages\imageio\__init__.py in imread(uri, format, **kwargs)
95 )
96
---> 97 return imread_v2(uri, format=format, **kwargs)
98
99
~\AppData\Roaming\Python\Python37\site-packages\imageio\v2.py in imread(uri, format, **kwargs)
198 imopen_args["legacy_mode"] = True
199
--> 200 with imopen(uri, "ri", **imopen_args) as file:
201 return file.read(index=0, **kwargs)
202
~\AppData\Roaming\Python\Python37\site-packages\imageio\core\imopen.py in imopen(uri, io_mode, plugin, extension, format_hint, legacy_mode, **kwargs)
116 request.format_hint = format_hint
117 else:
--> 118 request = Request(uri, io_mode, format_hint=format_hint, extension=extension)
119
120 source = "<bytes>" if isinstance(uri, bytes) else uri
~\AppData\Roaming\Python\Python37\site-packages\imageio\core\request.py in __init__(self, uri, mode, extension, format_hint, **kwargs)
246
247 # Parse what was given
--> 248 self._parse_uri(uri)
249
250 # Set extension
~\AppData\Roaming\Python\Python37\site-packages\imageio\core\request.py in _parse_uri(self, uri)
405 # Reading: check that the file exists (but is allowed a dir)
406 if not os.path.exists(fn):
--> 407 raise FileNotFoundError("No such file: '%s'" % fn)
408 else:
409 # Writing: check that the directory to write to does exist
FileNotFoundError: No such file: 'E:\pythonFiles\YOLOX\YOLOX_outputs\yolox_l is_res 2_06_06_16_26_36\dog.jpg'
单独看报错的最后一行:
FileNotFoundError: No such file: 'E:\pythonFiles\YOLOX\YOLOX_outputs\yolox_l is_res 2_06_06_16_26_36\dog.jpg'
本次报错最重要的是最后一行,这其实是在说明,系统读取到的路径与我们自己输入的路径并不一样,所以才没有读取到相应的文件,那么为什么不一样呢?我觉得大概是因为\v ,\t,\s这样的字眼本身有其特殊的意义,放在字符串里时变成了占位符,所以产生了这样的错误。
解决方法也很简单,直接使用两个斜杠即可。
也就是说将原来的路径:
E:\pythonFiles\YOLOX\YOLOX_outputs\yolox_l\vis_res\2022_06_06_16_26_36\dog.jpg
改写成:
E:\pythonFiles\YOLOX\YOLOX_outputs\yolox_l\\vis_res\\2022_06_06_16_26_36\dog.jpg
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。