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

mxnet报错 Check failed: dshp.ndim() == 4U (3 vs. 4) : Input data should be 4D in batch-num_filter-y-x

程序员文章站 2022-05-27 10:33:40
...

报错:mxnet.base.MXNetError: Error in operator conv0: [17:40:27] src/operator/nn/convolution.cc:152: Check failed: dshp.ndim() == 4U (3 vs. 4) : Input data should be 4D in batch-num_filter-y-x

明明输入数据是4维的,为什么报错?

因为用collections.namedtuple装载数据,进行前向预测时,没有给data外面加上括号。也就是放在list里面

Batch = namedtuple("Batch",["data","label"])
label = 123
print('label',label)
label = mx.nd.array([label])
mod.forward(Batch([img],[label])) # 注意 Batch([img])的形式

参考

完整报错很吓人,问题很简单

Traceback (most recent call last):
  File "/home/user1/pjs/frvt/arcface_Siamese_offline/recognition/tools/eval_on_train_set.py", line 70, in <module>
    mod.forward(Batch(imgsNoMask))
  File "/home/user1/miniconda3/envs/hardsample/lib/python2.7/site-packages/mxnet/module/module.py", line 625, in forward
    self.reshape(new_dshape, new_lshape)
  File "/home/user1/miniconda3/envs/hardsample/lib/python2.7/site-packages/mxnet/module/module.py", line 472, in reshape
    self._exec_group.reshape(self._data_shapes, self._label_shapes)
  File "/home/user1/miniconda3/envs/hardsample/lib/python2.7/site-packages/mxnet/module/executor_group.py", line 396, in reshape
    self.bind_exec(data_shapes, label_shapes, reshape=True)
  File "/home/user1/miniconda3/envs/hardsample/lib/python2.7/site-packages/mxnet/module/executor_group.py", line 372, in bind_exec
    allow_up_sizing=True, **dict(data_shapes_i + label_shapes_i))
  File "/home/user1/miniconda3/envs/hardsample/lib/python2.7/site-packages/mxnet/executor.py", line 458, in reshape
    ctypes.byref(handle)))
  File "/home/user1/miniconda3/envs/hardsample/lib/python2.7/site-packages/mxnet/base.py", line 253, in check_call
    raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: Error in operator conv0: [17:40:27] src/operator/nn/convolution.cc:152: Check failed: dshp.ndim() == 4U (3 vs. 4) : Input data should be 4D in batch-num_filter-y-x
Stack trace:
  [bt] (0) /home/user1/miniconda3/envs/hardsample/lib/python2.7/site-packages/mxnet/libmxnet.so(+0x4b04cb) [0x7ff30319c4cb]
  [bt] (1) /home/user1/miniconda3/envs/hardsample/lib/python2.7/site-packages/mxnet/libmxnet.so(+0x8eb956) [0x7ff3035d7956]
  [bt] (2) /home/user1/miniconda3/envs/hardsample/lib/python2.7/site-packages/mxnet/libmxnet.so(+0x26206f2) [0x7ff30530c6f2]
  [bt] (3) /home/user1/miniconda3/envs/hardsample/lib/python2.7/site-packages/mxnet/libmxnet.so(+0x2622f68) [0x7ff30530ef68]
  [bt] (4) /home/user1/miniconda3/envs/hardsample/lib/python2.7/site-packages/mxnet/libmxnet.so(mxnet::exec::GraphExecutor::Reshape(bool, bool, mxnet::Context const&, std::map<std::string, mxnet::Context, std::less<std::string>, std::allocator<std::pair<std::string const, mxnet::Context> > > const&, std::unordered_map<std::string, mxnet::TShape, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, mxnet::TShape> > > const&, std::vector<mxnet::NDArray, std::allocator<mxnet::NDArray> >*, std::vector<mxnet::NDArray, std::allocator<mxnet::NDArray> >*, std::vector<mxnet::NDArray, std::allocator<mxnet::NDArray> >*)+0x2a5) [0x7ff3052f9745]
  [bt] (5) /home/user1/miniconda3/envs/hardsample/lib/python2.7/site-packages/mxnet/libmxnet.so(MXExecutorReshapeEx+0x98c) [0x7ff305235bfc]
  [bt] (6) /home/user1/miniconda3/envs/hardsample/lib/python2.7/lib-dynload/../../libffi.so.7(+0x69dd) [0x7ff33b1679dd]
  [bt] (7) /home/user1/miniconda3/envs/hardsample/lib/python2.7/lib-dynload/../../libffi.so.7(+0x6067) [0x7ff33b167067]
  [bt] (8) /home/user1/miniconda3/envs/hardsample/lib/python2.7/lib-dynload/_ctypes.so(_ctypes_callproc+0x4de) [0x7ff33b1809de]
相关标签: MxNet # DL-报错