Unable to save model on gluon


#1

I am following the pix2pix gan tutorial :
https://gluon.mxnet.io/chapter14_generative-adversarial-networks/pixel2pixel.html

and I would like to save the model at each epoch, I have used

netG.save_params(netg_f)

However this is the error that I am getting:
ValueError: Prefix unetgenerator0_ is to be striped before saving, but Parameter unetskipunit7_conv0_weight does not start with unetgenerator0_. If you are using Block.save_params, This may be due to your Block shares parameters from other Blocks or you forgot to use `with name_scope()`` during init. Consider switching to Block.collect_params.save and Block.collect_params.load instead.

How can I fix this?
Thanks


#2

Hi @shabnam can you please share the code of how you define/declare your model?
Sounds like a with self.name_scope(): is perhaps missing.


#3

the same code at the webpage


#4

Pretty much the exact same code as
https://gluon.mxnet.io/chapter14_generative-adversarial-networks/pixel2pixel.html

But I added netG.save_params(filename) in block[9], in the train block


#5

Hi @shabnam,

in my test (just run the code) when I use block[6] definitions of UNetSkipUnit and UNetGenerator, I can instantatiate netG and save parameters normally. My mxnet version is 1.3.0 installed via:

pip install mxnet-cu91 --pre

The commands I used for reproducing the problem are:

netG = UnetGenerator(in_channels=3,num_downs=6) #identical 
netG.initialize(mx.init.Xavier(),ctx=mx.gpu()) # This may be different? 
netG.save_params('test.params') 

Now in the example initialization of parameters is different that what I did here (I checked the network_init, and it works). If you are sure you are following all steps in all cells, then this may be a bug. I would try and upgrade the mxnet version if I where you, and take it from there. Hopefully, more experienced users here will be able to help.


#6

Thanks, it looks like it is an mxnet version, I am using 0.11, but collect_params().save() worked for me