当前位置: 代码迷 >> 综合 >> mxnet报错TypeError: type <class ‘mxnet.initializer.InitDesc‘> not supported
  详细解决方案

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

热度:52   发布时间:2023-12-15 16:11:23.0

手动写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 _implif 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 equalNone)File "/home/user1/miniconda3/envs/hardsample/lib/python2.7/site-packages/mxnet/ndarray/ndarray.py", line 2706, in _ufunc_helperraise 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)
  相关解决方案