代码:
layer_out = mx.symbol.Softmax(data=softmax_input, name='gdn_softmax')
# 下面这种也一样
# layer_out = mx.symbol.SoftmaxOutput(data=softmax_input, name='gdn_softmax') # (256,)
报错:
Traceback (most recent call last):File "train_0723.py", line 434, in <module>main()File "train_0723.py", line 430, in maintrain_net(args)File "train_0723.py", line 424, in train_netepoch_end_callback=epoch_cb)File "/home/user1/recognition/parall_module_local_v1_gluon_group.py", line 537, in fitallow_missing=allow_missing, force_init=force_init)File "/home/user1/recognition/parall_module_local_v1_gluon_group.py", line 183, in init_paramsforce_init=force_init, allow_extra=allow_extra)File "/home/user1/miniconda3/lib/python3.7/site-packages/mxnet/module/module.py", line 309, in init_params_impl(desc, arr, arg_params)File "/home/user1/miniconda3/lib/python3.7/site-packages/mxnet/module/module.py", line 304, in _implinitializer(name, arr)File "/home/user1/miniconda3/lib/python3.7/site-packages/mxnet/initializer.py", line 172, in __call__self._init_default(desc, arr)File "/home/user1/miniconda3/lib/python3.7/site-packages/mxnet/initializer.py", line 269, in _init_default'Please use mx.sym.Variable(init=mx.init.*) to set initialization pattern' % name)
ValueError: Unknown initialization pattern for gdn_out_softmax_label. Default initialization is now limited to "weight", "bias", "gamma" (1.0), and "beta" (0.0).Please use mx.sym.Variable(init=mx.init.*) to set initialization pattern
原因: 调用了错误的网络层API。mxnet构建模型时,想在模型中间(不是最后输出)加一层softmax层,但是却加成了softmax计算loss的那种输出层(报错代码中提到的)。
解决: 正确的应该是添加一层softmax激活层。而不是输出层
layer_out = mx.sym.SoftmaxActivation(data=softmax_input, name='gdn_softmax')
其他情况下也会报这种错,不过不是我遇到的情况。参考:
https://discuss.gluon.ai/t/topic/14110
https://blog.csdn.net/u011765306/article/details/72568734?utm_source=blogxgwz2