关于机器学习:Anaconda-jupyter-notebook路径读取错误提示路径不存在解决方案

9次阅读

共计 2861 个字符,预计需要花费 8 分钟才能阅读完成。

当我在 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
正文完
 0