TensorFlow:如何在 TensorFlow 1.14 中加载使用旧版 TensorFlow 训练的权重?

问题描述 投票:0回答:1

我已经使用 TensorFlow 1.10 训练了一堆模型。当时,模型的权重被保存到两个扩展名为

.hdf5.index
.hdf5.data-00000-of-00001
的文件中。我现在尝试切换到 TensorFlow 1.14,但加载权重(使用
model.load_weights(weights + ".hdf5")
现在会引发以下错误:

Traceback (most recent call last):
  File ".../main.py", line 73, in <module>
    model.load_weights(DIR + "weights/weights.hdf5")
  File ".../python3.5/site-packages/tensorflow/python/keras/engine/training.py", line 162, in load_weights
    return super(Model, self).load_weights(filepath, by_name)
  File ".../python3.5/site-packages/tensorflow/python/keras/engine/network.py", line 1412, in load_weights
    with h5py.File(filepath, 'r') as f:
  File ".../python3.5/site-packages/h5py/_hl/files.py", line 394, in __init__
    swmr=swmr)
  File ".../python3.5/site-packages/h5py/_hl/files.py", line 170, in make_fid
    fid = h5f.open(name, flags, fapl=fapl)
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py/h5f.pyx", line 85, in h5py.h5f.open
OSError: Unable to open file (unable to open file: name = 'weights.hdf5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

TensorFlow 1.14 只是将权重保存到一个

.hd5f
文件中,所以我认为这就是它所期望的。我尝试省略
.hdf5.index
.hdf5.data-00000-of-00001
扩展的附加部分,但同样的错误仍然存在。有什么方法可以打开我的旧权重文件吗?

python tensorflow keras
1个回答
0
投票

以下,如果您找到解决方案,请发布答案

© www.soinside.com 2019 - 2024. All rights reserved.