我有一个使用Keras的Python代码。我没有发布代码,因为它有点长,这个问题似乎与代码本身无关。
这就是我犯的错误:

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格式。

关于python - KeyError:“无法打开属性(无法找到属性:'nb_layers')”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43356449/

10-12 23:04