mxnet
mxnet copied to clipboard
Softmax_label magically appears
Description
The Softmax/SoftmaxOutput operator has an optional label input that is enabled by setting the ignore_label or use_length:
https://github.com/apache/incubator-mxnet/blob/master/src/operator/nn/softmax-inl.h#L616-L618
https://github.com/apache/incubator-mxnet/blob/v1.x/src/operator/softmax_output-inl.h#L61-L63
Many common image classification/CNN models use softmax, but dont use the softmax_label input meaningfully. Yet there is an actual input to the model for this.
Notice in ResNet models:
{
"op": "null",
"param": {},
"name": "softmax_label",
"inputs": [],
"backward_source_id": -1
},
{
"op": "SoftmaxOutput",
"param": {
"grad_scale": "1",
"ignore_label": "-1",
"multi_output": "False",
"normalization": "null",
"out_grad": "False",
"preserve_shape": "False",
"use_ignore": "False"
},
"name": "softmax",
"inputs": [[131, 0], [132, 0]],
"backward_source_id": -1
}
Error Message
Symbol/Module flow:
Traceback (most recent call last):
File "test.py", line 13, in <module>
mod.set_params(args, aux)
File "/home/ubuntu/incubator-mxnet/python/mxnet/module/module.py", line 350, in set_params
allow_extra=allow_extra)
File "/home/ubuntu/incubator-mxnet/python/mxnet/module/module.py", line 309, in init_params
_impl(desc, arr, arg_params)
File "/home/ubuntu/incubator-mxnet/python/mxnet/module/module.py", line 300, in _impl
raise RuntimeError("%s is not presented" % name)
RuntimeError: softmax_label is not presented
Gluon flow:
Traceback (most recent call last):
File "test.py", line 5, in <module>
'resnet-18-0000.params')
File "/home/ubuntu/incubator-mxnet/python/mxnet/gluon/block.py", line 1409, in imports
dtype_source='saved')
File "/home/ubuntu/incubator-mxnet/python/mxnet/gluon/parameter.py", line 1020, in load
ignore_extra, restore_prefix, filename, cast_dtype, dtype_source)
File "/home/ubuntu/incubator-mxnet/python/mxnet/gluon/parameter.py", line 1057, in load_dict
name[lprefix:], error_str, _brief_print_list(arg_dict.keys()))
AssertionError: Parameter 'softmax_label' is missing in file: resnet-18-0000.params, which contains parameters: 'stage1_unit1_sc_weight', 'stage2_unit1_bn2_gamma', 'bn_data_moving_var', ..., 'stage2_unit2_conv1_weight', 'stage1_unit2_bn1_gamma', 'stage2_unit2_bn1_moving_var', 'stage2_unit2_bn2_moving_var'. Please make sure source and target networks have the same prefix.For more info on naming, please see https://mxnet.io/api/python/docs/tutorials/packages/gluon/blocks/naming.html
To Reproduce
comment out the allow_missing=True to reproduce the error messages.
import mxnet as mx
path='http://data.mxnet.io/models/imagenet/'
[mx.test_utils.download(path+'resnet/18-layers/resnet-18-0000.params'),
mx.test_utils.download(path+'resnet/18-layers/resnet-18-symbol.json')]
block = mx.gluon.nn.SymbolBlock.imports('resnet-18-symbol.json',
['data'],
'resnet-18-0000.params',
allow_missing=True)
sym, args, aux = mx.model.load_checkpoint('resnet-18',0)
mod = mx.mod.Module(symbol=sym, context=mx.cpu(), label_names=None)
mod.bind(for_training=False, data_shapes=[('data', (1,3,224,224))],
label_shapes=mod._label_shapes)
mod.set_params(args, aux,
allow_missing=True)
I have met the same problem, and how to fix it?
any fix?
You can set allow_missing=True like in the examples above to avoid the issue.