fchollet / deep-learning-models

Keras code and weights files for popular deep learning models.
MIT License
7.3k stars 2.46k forks source link

issues with VGG16 weights #69

Open MrChenFeng opened 6 years ago

MrChenFeng commented 6 years ago

I downloaded the vgg16-notop pretrained weights,but when I want to load the weights it always show me: KeyError: "Can't open attribute (Can't locate attribute: 'nb_layers')" the environment is{ spyder+keras 2.0.6+tensorflow backend+python 3.5.2} src here:

import h5py weights_path = 'vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5' f = h5py.File(weights_path) for k in range(f.attrs['nb_layers']): if k >= len(model.layers):

we don't look at the last (fully-connected) layers in the savefile

    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.')

rockywind commented 6 years ago

I meet the same problem.

Zemin-Arzch commented 4 years ago

Is there a solution?

aicha200 commented 2 years ago

nb_layers = len(f.attrs['layer_names']) for k in range(nb_layers):