gpt4 book ai didi

python - key 错误 : "Can' t open attribute (Can't locate attribute: 'nb_layers' )"

转载 作者:行者123 更新时间:2023-11-28 18:23:19 24 4
gpt4 key购买 nike

我有一个使用 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')"

可能是什么问题?它与Keras有关吗?我该如何解决这个问题?

编辑 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 - key 错误 : "Can' t open attribute (Can't locate attribute: 'nb_layers' )",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43356449/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com