我在我的项目文件夹中调用“project”。我有两个神经网络 h5 文件,一个位于“project/my_folder/my_model_1.h5”中,我还将其复制到文件夹“project/my_model_2.h5”中。所以我打开在“project”文件夹中工作的 Jupyter Notebook。
import h5py
f = h5py.File("my_model_2.h5") # has NO Issue
but
f = h5py.File("my_folder/my_model_1.h5") # OSError
It says 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 机器上没有遇到任何问题。
如果您知道如何解决此问题,请告诉我。先感谢您。
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文件夹复制粘贴的路径名。
第 93 行是我逐字输入的路径,然后就没有错误并且 .h5 文件被正确加载。有人通过此链接发现了类似的问题:标识符中的字符无效
我只需将错误代码复制到 Pycharm,这个不受欢迎的角色就被抓获了。
因此,对于 Mac 用户,请注意不要只是简单地从文件夹系统复制文本,如果出现明显奇怪的情况,请尝试在文本编辑器中键入每个字母。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)