Load_checkpoint ValueError: not enough values to unpack


#1

I use the load_checkpoint with the saved model-symbol.json and model-0000.params . But I get the Error:

File "/home/csf/anaconda3/envs/mxnet/lib/python3.6/site-packages/mxnet/model.py", line 424, in load_checkpoint
    tp, name = k.split(':', 1)
ValueError: not enough values to unpack (expected 2, got 1)

I see the source code and find in the function load_checkpoint, it expect the saved params have the keys with a prefix, so that can be splited by :, however, I directly load the saved params use nd.load(), I don’t find the expected prefix?

I use the save_params() and save_parameters(), but get the same result.


ValueError: not enough values to unpack (expected 2, got 1)
#2

When I load the params pointed at the official tutotial Predict with pre-trained models, I find the keys of
resnet-18-0000.params is really equipped with the prefix , looks like:

arg:stage3_unit1_bn2_beta
arg:fc1_weight
arg:stage4_unit1_bn2_gamma
arg:stage3_unit1_bn2_gamma
arg:bn0_beta
arg:stage2_unit1_bn1_beta
aux:stage2_unit1_bn1_moving_mean
arg:stage1_unit1_bn1_beta
aux:stage1_unit2_bn1_moving_mean
aux:stage2_unit1_bn2_moving_var
arg:stage2_unit2_conv1_weight
arg:stage1_unit2_bn1_gamma
aux:stage2_unit2_bn1_moving_var
aux:stage2_unit2_bn2_moving_var

#3

Have a look at this tutorial to learn how to save/load parameters in MXNet:

You shouldn’t load the parameters directly with nd.load(), but use .load_parameters() on your block in Gluon.

If you want to save your Gluon model for use in a symbolic fashion, you need to make sure you model is hybridized and then you can use the HybridBlock.export() API.

If you share a bit more your use-case and code I’ll be able to guide you better.


#4

thank you very much, it helps me.

And I modify a line in this code:

deserialized_net = gluon.nn.SymbolBlock.imports("lenet-symbol.json", ['data'], "lenet-0001.params")

to

deserialized_net = gluon.nn.SymbolBlock.imports("lenet-symbol.json", ['data'], "lenet-0001.params", ctx=ctx)

i.e. just add context of the load model parameters. It works fine for me.