我试图为我的任务加载名为"tr_model.h5“的pre_trained模型,但得到以下错误:
Traceback (most recent call last):
File "Trigger_Project.py", line 84, in <module>
model = load_model(filename)
File "Trigger_Project.py", line 84, in <module>
model = load_model(filename)
File "/home/neeraj/anaconda3/lib/python3.6/site-packages/h5py/_hl/files.py", line 99, in make_fid
fid = h5f.open(name, flags, fapl=fapl)
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapperh5py._objects.with_phil.wrapper中的文件"h5py/_objects.pyx",第55行
File "h5py/h5f.pyx", line 78, in h5py.h5f.open
OSError: Unable to open file (unable to open file: name = 'tr_model.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)我已经确认文件已经存在。我不明白为什么它会显示os错误。我使用的是linux 18.04,所有需要的库都已升级。任何帮助都是非常感谢的。
发布于 2019-08-13 12:34:20
我遇到了与我在问题中发布的问题相同的问题:
h5py.File(path) doesn't recognize folder path
我最初的推理是h5py.File( path )不会将标准子文件夹路径作为它的参数,例如load_model("neunet.h5")没有问题,但是load_model("subfolder/neunet.h5")会给出同样的错误。
简而言之,我的解决方案是简单地将任何.h5文件放到我的jupyter笔记本中的工作主文件夹中,也就是您创建.ipynb文件的位置。您可以在jupyter notebook中使用print(os.getcwd())来查看当前工作目录的位置。
发布于 2019-09-15 23:52:33
如果您正在使用colab和google驱动器,请使用以下命令将驱动器挂载到colab
# Load the Drive helper and mount
from google.colab import drive
# This will prompt for authorization.
drive.mount('/content/drive')发布于 2019-12-31 11:49:01
我通过指定绝对路径解决了这个问题。获取工作文件夹的绝对路径,然后将该路径附加到工作目录中的文件。在我的示例中,该文件位于名为datasets的目录中,因此我尝试了以下代码
file_name = os.path.dirname(__file__) +'\\datasets\\test_catvnoncat.h5'
test_dataset = h5py.File(file_name, "r")https://stackoverflow.com/questions/51593527
复制相似问题