deep-learning-models icon indicating copy to clipboard operation
deep-learning-models copied to clipboard

issues with VGG16 weights

Open MrChenFeng opened this issue 6 years ago • 3 comments

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

MrChenFeng avatar Sep 05 '17 02:09 MrChenFeng

I meet the same problem.

rockywind avatar Jan 23 '18 03:01 rockywind

Is there a solution?

Zemin-Arzch avatar Apr 02 '20 03:04 Zemin-Arzch

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

aicha200 avatar Aug 01 '22 11:08 aicha200