添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

fp = builtins.open(filename, "rb") filenotfounderror: [errno 2] no such file or directory:

Ask Question

I want to load a whole folder of images together. I am working in R using Keras with python interface. I have set the path of the folder, then used the lapply function to load the images in the folder, one by one.

> 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)

The error :

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")

Can you please help me. I understand the python interface is unable to identify the path. But how do I do that?

You might want to run procmon with a filter to the filename, after this you know where the program looks for the files – Marged Jul 4, 2018 at 6:10

Convert it to path type; because it is not in path type when you're trying to access it.

Like if your path is:- "my_path/this_way" Then:-

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

Now use path1.

Old question but had similar issue with keras::image_array_save

My workaround was using writeImage from package OpenImageR. Works very well.

You could use OpenImageR::readImage instead of image_load

Had the same problem using vs code on my MacBook, I was working with image files in multiple subfolders. So what I did was place the folder I am working with in the Users root folder of my mac where the program and the image resources were residing and run it from there and it worked. It turned out vs code was having problems finding the files when they were placed deep in multiple subfolders.FileNotFoundError solution

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.