我的代码是来自github的副本。 VGG-16预训练的Keras模型 https://gist.github.com/baraldilorenzo/07d7802847aaad0a35d3
但是当我运行代码时,始终显示密钥错误。 错误消息:
Traceback (most recent call last):
File "v16.py", line 107, in <module>
model.load_weights('vgg16_weights.h5')
File "C:\Anaconda3\lib\site-packages\keras\models.py", line 706, in
load_weights topology.load_weights_from_hdf5_group(f, layers)
File "C:\Anaconda3\lib\site-packages\keras\engine\topology.py", line 2869,
in load_weights_from_hdf5_group
layer_names = [n.decode('utf8') for n in f.attrs['layer_names']]
File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
(D:\Build\h5py\h5py-2.7.0\h5py\_objects.c:2853)
File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
(D:\Build\h5py\h5py-2.7.0\h5py\_objects.c:2811)
File "C:\Anaconda3\lib\site-packages\h5py\_hl\attrs.py", line 58, in
__getitem__attr = h5a.open(self._id, self._e(name))
File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
(D:\Bud\h5py\h5py-2.7.0\h5py\_objects.c:2853)
File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
(D:\Build\h5py\h5py-2.7.0\h5py\_objects.c:2811)
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: 'layer_names')"