【问题标题】:Can anyone tell me what's wrong here in cnn own model in mxnet?谁能告诉我 mxnet 中的 cnn 自己的模型有什么问题?
【发布时间】:2019-03-12 14:58:34
【问题描述】:
def acc(output, label):
    correct_preds = output.argmax(axis=1) == label.astype('float32')
    return correct_preds.mean().asscalar()

for epoch in range(10):

    train_loss, train_acc, valid_acc = 0., 0., 0.
    tic = time()

    for data, label in train_data:
        data = data.copyto(mx.cpu(0))
        label = label.copyto(mx.cpu(0))
        with autograd.record():
            output = net(data)
            loss = softmax_cross_entropy(output, label)

        loss.backward()

        trainer.step(batch_size)

        train_loss += loss.mean().asscalar()
        train_acc += acc(output, label)

运行这部分时出现错误,我的数据集是 pascol voc 格式

ValueError                                
Traceback (most recent call last)
<ipython-input-7-9926ba7deb21> in <module>()

         12         label = label.copyto(mx.cpu(0))
         13         with autograd.record():
    ---> 14             output = net(data)
         15             loss = softmax_cross_entropy(output, label)
         16 

/home/manasi/.local/lib/python2.7/site-packages/mxnet/gluon/block.pyc in __call__(self, *args)


      539             hook(self, args)
        540 
    --> 541         out = self.forward(*args)
        542 
        543         for hook in self._forward_hooks.values():

/home/manasi/.local/lib/python2.7/site-packages/mxnet/gluon/nn/basic_layers.pyc in forward(self, x)


        51     def forward(self, x):
         52         for block in self._children.values():
    ---> 53             x = block(x)
         54         return x
         55 

/home/manasi/.local/lib/python2.7/site-packages/mxnet/gluon/block.pyc in __call__(self, *args)


        539             hook(self, args)
        540 
    --> 541         out = self.forward(*args)
        542 
        543         for hook in self._forward_hooks.values():

/home/manasi/.local/lib/python2.7/site-packages/mxnet/gluon/block.pyc in forward(self, x, *args)
    911                     params = {i: j.data(ctx) for i, j in self._reg_params.items()}


     912                 except DeferredInitializationError:
    --> 913                     self._deferred_infer_shape(x, *args)
        914                     for _, i in self.params.items():
        915                         i._finish_deferred_init()

/home/manasi/.local/lib/python2.7/site-packages/mxnet/gluon/block.pyc in _deferred_infer_shape(self, *args)

        792             error_msg = "Deferred initialization failed 
           because shape"\
        793                         " cannot be inferred. {}".format(e)
    --> 794             raise ValueError(error_msg)
        795 
        796     def _call_cached_op(self, *args):

ValueError: Deferred initialization failed because shape cannot be inferred. Error in operator conv2_fwd: [10:56:15] src/operator/nn/convolution.cc:196: Check failed: dilated_ksize_x <= AddPad(dshape[3], param_.pad[1]) (5 vs. 3) kernel size exceed input

【问题讨论】:

  • 感谢您提供代码 - 所有包含的代码看起来都不错。这与形状不匹配有关。您能否包括您的网络定义以及相同的输入数据。谢谢!
  • 感谢您的回复,问题出在网络

标签: mxnet


【解决方案1】:

kernel size exceed input 错误通常出现在您的输入图像对于网络来说太小时。您要么需要调整输入图像的大小,要么更改网络架构以移除降低特征图空间维度的层(例如池化层或带步幅的卷积)。

【讨论】:

  • 我认为 Thom 的意思是输入图像太小而不是太大。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-04-29
  • 2021-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-22
  • 2021-09-06
相关资源
最近更新 更多