KeyError:“无法打开属性(无法找到属性:'nb_layers')”
问题描述:
我有一个使用Keras
的Python代码。我没有发布代码,因为它有点长,而且问题似乎与代码本身没有关系。KeyError:“无法打开属性(无法找到属性:'nb_layers')”
这是错误我在:
File "h5py\h5a.pyx", line 77, in h5py.h5a.open (D:\Build\h5py\h5py-2.7.0\h5py\h5a.c:2350)
KeyError: "Can't open attribute (Can't locate attribute: 'nb_layers')"
可能是什么问题?它与凯拉斯有关吗?我该如何解决这个问题?
编辑1
的错误似乎涉及到这部分代码:
# load VGG16 weights
f = h5py.File(weights_path)
for k in range(f.attrs['nb_layers']):
if k >= len(model.layers):
break
g = f['layer_{}'.format(k)]
weights = [g['param_{}'.format(p)] for p in range(g.attrs['nb_params'])]
model.layers[k].set_weights(weights)
f.close()
print('Model loaded.')
感谢。
答
使用来自https://github.com/fchollet/deep-learning-models/releases
此文件中的权重文件vgg16_weights_th_dim_ordering_th_kernels.h5是Keras 2格式。
+0
您可能想添加一些解释。 – GhostCat
这个人有类似的问题https://github.com/hycis/bidirectional_RNN/issues/6 – Scheme
你能发表一些周围的代码,特别是在77行左右? –
感谢您的评论。是的,我遇到了你发布的链接,并注意到它是由于缺少h5文件,但仍然无法得到的重点,这是什么h5将是 – Simplicity