Collect_params().load(model_params_file) does not work


#1

Here is how I save the parameters:

model_params_file = ‘bin_utilization.gluon.params’
bin_net.collect_params().save(model_params_file)

Here is how I load the parameters:

model_params_file = ‘bin_utilization.gluon.params’
bin_net2.collect_params().load(model_params_file, ctx=model_ctx)

Here is error message:


AssertionError Traceback (most recent call last)
in ()
1 model_params_file = ‘bin_utilization.gluon.params’
----> 2 bin_net2.collect_params().load(model_params_file, ctx=model_ctx)

/home/ubuntu/anaconda3/envs/mxnet_p27/lib/python2.7/site-packages/mxnet/gluon/parameter.pyc in load(self, filename, ctx, allow_missing, ignore_extra, restore_prefix)
667 for name in self.keys():
668 assert name in arg_dict,
–> 669 “Parameter %s is missing in file %s”%(name[lprefix:], filename)
670 for name in arg_dict:
671 if name not in self._params:

AssertionError: Parameter resnetv15_conv0_weight is missing in file bin_utilization.gluon.params

The networks are created using the same routine:

def build_net(hyper_params):
from mxnet.gluon.model_zoo import vision as models

res_net = models.resnet152_v1(pretrained=True)
new_net = gluon.nn.HybridSequential()

with new_net.name_scope():
    pretrained_features = res_net.features
    new_tail = gluon.nn.HybridSequential()
    new_tail.add(
        gluon.nn.Dense(hyper_params.NUM_HIDDENS1, activation=hyper_params.ACTIVATION),
        gluon.nn.Dropout(hyper_params.DROPOUT),
        gluon.nn.Dense(hyper_params.NUM_HIDDENS2, activation=hyper_params.ACTIVATION),
        gluon.nn.Dropout(hyper_params.DROPOUT),
        gluon.nn.Dense(hyper_params.NUM_OUTPUTS)
    )
    new_tail.initialize(mx.init.Xavier(magnitude=hyper_params.MAGNITUDE))

    new_net.add(
        pretrained_features,
        new_tail
    )
new_net.hybridize()
return new_net

One interesting fact:
Every time I tried it, the name of the parameter missing changes:

resnetv15_conv0_weight

from

resnetv11_conv0_weight

to

resnetv12_conv0_weight

all the way to

resnetv15_conv0_weight


#2

Hi,

Save is not a recommended way to save the parameters to be reloaded via load. You’ll want to use load_parameters and save_parameters. Here’s the usage:

Vishaal


#3

Does not work for my code:

model_params_file = ‘bin_utilization.gluon.params’
bin_net.save_parameters(model_params_file)

Here is the new error message:


AttributeError Traceback (most recent call last)
in ()
1 model_params_file = ‘bin_utilization.gluon.params’
----> 2 bin_net.save_parameters(model_params_file)

AttributeError: ‘HybridSequential’ object has no attribute ‘save_parameters’


#4

Hey again,

You’ll need to upgrade to 1.2.1 for the load_parameters and save_parameters: https://github.com/apache/incubator-mxnet/releases
Install instructions: http://mxnet.incubator.apache.org/install/index.html?platform=Linux&language=Python&processor=GPU


#5

Thanks for the tip! I’ll give it a try.

Best,

Xin