【问题标题】:fp = builtins.open(filename, "rb") filenotfounderror: [errno 2] no such file or directory:fp = builtins.open(filename, "rb") filenotfounderror: [errno 2] 没有这样的文件或目录:
【发布时间】:2018-07-04 06:08:11
【问题描述】:

我想一起加载整个图像文件夹。我正在使用带有 python 接口的 Keras 在 R 中工作。我已经设置了文件夹的路径,然后使用 lapply 函数将文件夹中的图像一张一张加载。

> files <- list.files(path="C:/Users/acer/Desktop/Triparna/traitestimage/Test/Bone/", pattern=".png",all.files=T, full.names=F, no.. = T)
 > list_of_images = lapply(files, image_load)

错误:

Error in py_call_impl(callable, dots$args, dots$keywords) : 
FileNotFoundError: [Errno 2] No such file or directory: 'bone58.png'

Detailed traceback: 
File "C:\Users\acer\ANACON~1\envs\R-TENS~1\lib\site- 
packages\keras\preprocessing\image.py", line 387, in load_img
img = pil_image.open(path)
File "C:\Users\acer\ANACON~1\envs\R-TENS~1\lib\site- 
packages\PIL\Image.py", line 2548, in open
fp = builtins.open(filename, "rb")

你能帮帮我吗?我了解python接口无法识别路径。但是我该怎么做呢?

【问题讨论】:

  • 你可能想运行 procmon 并过滤文件名,之后你就知道程序在哪里寻找文件

标签: python r image keras


【解决方案1】:

老问题,但与keras::image_array_save 有类似问题

我的解决方法是使用 OpenImageR 包中的 writeImage。效果很好。

您可以使用OpenImageR::readImage 代替image_load

【讨论】:

    【解决方案2】:

    在我的 MacBook 上使用 vs 代码时遇到了同样的问题,我正在处理多个子文件夹中的图像文件。所以我所做的是将我正在使用的文件夹放在我的 Mac 的用户根文件夹中,程序和图像资源所在的位置并从那里运行它并且它工作。事实证明,当文件被放置在多个子文件夹深处时,vs code 在查找文件时遇到问题。FileNotFoundError solution

    【讨论】:

      【解决方案3】:

      将其转换为路径类型;因为当您尝试访问它时它不在路径类型中。

      如果你的路径是:- "my_path/this_way" 然后:-

      import os
      path1 = os.path.normpath("my_path/this_way")
      

      现在使用path1。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-11-03
        • 2021-08-24
        • 2021-03-07
        • 2015-06-09
        • 2021-04-01
        • 2021-10-15
        • 1970-01-01
        相关资源
        最近更新 更多