Load saved parameters in gluon block

I am trying to do something very trivial, but unfortunately I didn’t get it to work.

I create a simple network as follows

net = gluon.nn.HybridSequential()
with net.name_scope():
    net.add(gluon.nn.Dense(input_dim, activation="relu"))
    net.add(gluon.nn.BatchNorm(axis=1, center=True, scale=True))
    net.add(gluon.nn.Dropout(0.25))
    net.add(gluon.nn.Dense(output_dim))
net.collect_params().initialize(force_reinit=True, ctx=ctx)
net.hybridize()

Then I serialize the network and params dictionary in this way

    net.export(model_output_prefix, epoch=0)
    net.save_parameters(model_output_prefix+PARAM_DICT_SUFFIX)

The reason I do it is that apparent parameters not used in the forward pass do not get saved with export() [I found that in the github issues, not sure if the problem is solved].
Anyway, I save the parameters and then I try to load them in my deserialized network

    net = gluon.nn.SymbolBlock.imports(symbol_filename, ["data"], params_filename, ctx=ctx)
    net.load_parameters(param_dict_filename)

And it fails when I try to do the load_parameters(…) with the following error:

AssertionError: Parameter ‘dense0_weight’ is missing in file ‘$THE_PARAMDICT_FILE’, which contains parameters: ‘0.weight’, ‘0.bias’, ‘1.gamma’, …, ‘1.running_mean’, ‘1.running_var’, ‘3.weight’, ‘3.bias’. Set allow_missing=True to ignore missing parameters.


If I do replace the import of the symbol block with the “real” network, then everything works as expected.

    net = gluon.nn.HybridSequential()
    with net.name_scope():
        net.add(gluon.nn.Dense(input_dim, activation="relu"))
        net.add(gluon.nn.BatchNorm(axis=1, center=True, scale=True))
        net.add(gluon.nn.Dropout(0.25))
        net.add(gluon.nn.Dense(output_dim))
    net.collect_params().initialize(force_reinit=True, ctx=ctx)
    net.load_parameters(param_dict_filename)