欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

mxnet报错TypeError: type <class ‘mxnet.initializer.InitDesc‘> not supported

程序员文章站 2022-05-27 11:32:05
...

手动写mxnet预测代码对单个图像进行预测时,报错:

Traceback (most recent call last):
  File "/home/user1/pjs/frvt/arcface_Siamese_offline/recognition/tools/eval_on_train_set.py", line 163, in <module>
    fc7_mod.init_params(arg_params=fc7_overall, aux_params=None)
  File "/home/user1/miniconda3/envs/hardsample/lib/python2.7/site-packages/mxnet/module/module.py", line 309, in init_params
    _impl(desc, arr, arg_params)
  File "/home/user1/miniconda3/envs/hardsample/lib/python2.7/site-packages/mxnet/module/module.py", line 292, in _impl
    if name in cache:
  File "/home/user1/miniconda3/envs/hardsample/lib/python2.7/site-packages/mxnet/ndarray/ndarray.py", line 324, in __eq__
    return equal(self, other)
  File "/home/user1/miniconda3/envs/hardsample/lib/python2.7/site-packages/mxnet/ndarray/ndarray.py", line 3245, in equal
    None)
  File "/home/user1/miniconda3/envs/hardsample/lib/python2.7/site-packages/mxnet/ndarray/ndarray.py", line 2706, in _ufunc_helper
    raise TypeError('type %s not supported' % str(type(rhs)))
TypeError: type <class 'mxnet.initializer.InitDesc'> not supported

原因:传入参数的格式不对。使用下面的fc7_arg_params 这种形式就可以了。不要采用 fc7_overall = fc7_arg_params[‘fc7_weight’] 作为传入参数

# 要传入的参数读取
fc7_weight = mx.ndarray.load(fc7 + '-' + str(epoch) + '.bin')
fc7_arg_params = {'fc7_weight': fc7_weight[0]} # 正确的形式

# 传入参数并初始化
_initializer = mx.init.Normal(0.01)
fc7_mod.init_params(_initializer, arg_params=fc7_arg_params, aux_params={}, allow_missing=True,
                                force_init=False, allow_extra=False)
相关标签: MxNet # DL-报错