I have a trained detector model (SSD), for which I have a .params and a .json files.
I’d like to instantiate the model, but this command:net = gluon.nn.SymbolBlock.imports("model_algo_1-symbol.json", ['data'], "model_algo_1-0000.params", ctx=ctx) fails: AssertionError: Parameter 'label' is missing in file 'model_algo_1-0000.params', which contains parameters: 'multi_feat_3_conv_1x1_conv_weight', 'stage2_unit3_bn3_gamma', 'stage1_unit1_sc_weight', ..., 'stage4_unit1_bn3_moving_mean', 'stage1_unit2_conv3_weight', 'stage3_unit4_bn1_beta', 'multi_feat_5_conv_1x1_conv_weight'. Please make sure source and target networks have the same prefix.
Hey @olivcruche,
I had a similar problem when I tried loading a model trained with MXNet into the Gluon API.
The problem was resolved when the model was constructed manually:
In need this code segment for my particular mode because it has multiple output heads. value_tanh0_output is the last output layer for the first head and 'flatten0_output' the output layer name of the second head.
For your model this code might be sufficient:
model_arch_path = 'model_algo_1-symbol.json'
model_params_path = 'model_algo_1-0000.params'
ctx = mx.cpu() # or mx.gpu()
symbol = mx.sym.load(model_arch_path)
inputs = mx.sym.var('data', dtype='float32')
sym = symbol.get_internals()['<name_of_the_last_output_layer>']
net = mx.gluon.SymbolBlock(sym, inputs)
net.collect_params().load(model_params_path, ctx)
Replace '<name_of_the_last_output_layer>'with the name of you the last output layer of your network.
The reason why you can’t load your model via SymbolBlock.imports() is because the label parameter wasn’t saved in the .params file. This seems to be the case when you train the model with MXNet’s symbol API and later load it in Gluon.
Every Layer which has a SoftmaxOutput or for example LinearRegressionOutput is an output head of your model.
In most cases Resnet models have only a single SoftmaxOutput head and are used as classification models.
when I use mx.viz.print_summary(symbol, shape={'data':(1, 3, 500, 500)}) (I have a 500x500 SSD model), I get a MXNetError: Error in operator multibox_target: [19:28:12] src/operator/contrib/./multibox_target-inl.h:225: Check failed: lshape.ndim() == 3 (0 vs. 3) Label should be [batch, num_labels, label_width] tensor
I’m getting the model from the sagemaker service, all it tells me in that it is a resnet50-SSD and it returns the .params and .json. The net = mx.model.load_checkpoint('model_algo_1', 0) call is successful but I have no idea of how to go from there to a model that can predict on images…
It should be easier to use gluoncv to have ssd model training, loading, and prediction in a easy way. There’s custom method for you to refer the class names, etc.