h5py.File(path)无法识别文件夹路径 [英] h5py.File(path) doesn't recognize folder path

查看:2338
本文介绍了h5py.File(path)无法识别文件夹路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目文件夹中称为项目".我有两个神经网络h5文件,一个在"project/my_folder/my_model_1.h5"中,我还将其复制到文件夹"project/my_model_2.h5"中.因此,我打开了在项目"文件夹下工作的Jupyter Notebook.

I am in my project folder call "project". I have two neural network h5 file, one in "project/my_folder/my_model_1.h5", I also copy it to folder "project/my_model_2.h5". So I open my Jupyter Notebook which is working at "project" folder.

import h5py
f = h5py.File("my_model_2.h5") # has NO Issue

但是

f = h5py.File("my_folder/my_model_1.h5") # OSError

它说OSError: Unable to open file (unable to open file: name = 'my_folder/my_model_1.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

有趣的是,只有在Mac上执行相同的操作时,我才会遇到此问题,但在Linux机器上没有遇到任何问题.

Interestingly, I only have this issue when I do the same thing on my Mac, but I don't encounter any issue in Linux machine.

如果您知道如何解决此问题,请告诉我.预先谢谢你.

Please let me know if you know how to fix this. Thank you in advance.

推荐答案

因此,当我简单地从Mac文件夹系统复制并粘贴文件路径时,似乎偶然地复制了一些隐藏的无效字符.看一下屏幕上的代码.

So it looks like some hidden invalid character incidentally got copied when I simply copy and paste the file path from Mac folder system. Take a look at the code in the screen.

第92行是我直接从Mac文件夹复制并粘贴的路径名.

The Line 92 is the path name I directly copy and paste from Mac folder.

第93行是我逐字键入的路径,因此没有错误,并且.h5文件已正确加载.有人在此链接上发现了类似的问题:标识符中的无效字符

The Line 93 is the path I literally type with every single letter, then there is no error and .h5 file is loaded properly. It's a kinda of similar issue that has been spotted by someone at this link: Invalid character in identifier

我只是将错误代码复制到Pycharm,不受欢迎的字符就被删除了.

I simply copy the error code to Pycharm, and the unwelcome character got busted.

因此,对于Mac用户,解决方案仅是简单地从文件夹系统复制文本,如果有明显的怪异,请尝试在文本编辑器中键入每个字母.

So solution, for Mac user, be careful of of just simply copying the text from folder system, if something obviously weird, try type every letter into the text editor.

这篇关于h5py.File(path)无法识别文件夹路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆