Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of Loading Pretrained Model #163

Closed
cancan101 opened this issue Oct 12, 2015 · 3 comments
Closed

Example of Loading Pretrained Model #163

cancan101 opened this issue Oct 12, 2015 · 3 comments

Comments

@cancan101
Copy link
Contributor

https://github.com/Lasagne/Recipes (see modelzoo) offers a number of pre-trained models. I suggest providing an example of loading weights for one of the pre-trained model.

See also: Lasagne/Recipes#20

@dnouri
Copy link
Owner

dnouri commented Mar 26, 2016

Here's an example of loading params for a VGG16 net.

from lasagne.layers import set_all_param_values

with open('vgg16.pkl', 'rb') as f:
    params = pickle.load(f)

net.initialize_layers()
set_all_param_values(net.layers_.values(), params['param values'])

I'll try and remember to move this into the documentation at some point.

@xuleiyang
Copy link

Hi all, i meet the following error, how to solve? Thanks a lot.

AttributeError: 'dict' object has no attribute 'initialize_layers'

@tdeboissiere
Copy link

You can do the following (example with VGG_s model):


net = {}
net['input'] = InputLayer((None, 3, 224, 224))
net['conv1'] = ConvLayer(net['input'], num_filters=96, filter_size=7, stride=2, flip_filters=False)
net['norm1'] = NormLayer(net['conv1'], alpha=0.0001)  # caffe has alpha = alpha * pool_size
net['pool1'] = PoolLayer(net['norm1'], pool_size=3, stride=3, ignore_border=False)
net['conv2'] = ConvLayer(net['pool1'], num_filters=256, filter_size=5, flip_filters=False)
net['pool2'] = PoolLayer(net['conv2'], pool_size=2, stride=2, ignore_border=False)
net['conv3'] = ConvLayer(net['pool2'], num_filters=512, filter_size=3, pad=1, flip_filters=False)
net['conv4'] = ConvLayer(net['conv3'], num_filters=512, filter_size=3, pad=1, flip_filters=False)
net['conv5'] = ConvLayer(net['conv4'], num_filters=512, filter_size=3, pad=1, flip_filters=False)
net['pool5'] = PoolLayer(net['conv5'], pool_size=3, stride=3, ignore_border=False)
net['fc6'] = DenseLayer(net['pool5'], num_units=4096)
net['drop6'] = DropoutLayer(net['fc6'], p=0.5)
net['fc7'] = DenseLayer(net['drop6'], num_units=4096)
net['drop7'] = DropoutLayer(net['fc7'], p=0.5)
net['fc8'] = DenseLayer(net['drop7'], num_units=1000, nonlinearity=lasagne.nonlinearities.softmax)
output_layer = net['fc8']

import pickle
model = pickle.load(open('vgg_cnn_s.pkl'))
CLASSES = model['synset words']
MEAN_IMAGE = model['mean image']
lasagne.layers.set_all_param_values(output_layer, model['values'])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants