1
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)

When running this part I get the error and my dataset is in pascol voc format

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
kalehmann
  • 4,821
  • 6
  • 26
  • 36
  • Thanks for including the code - all the included code looks good. This has to do with a shape mismatch. Can you include your network definition as well as the same of your input data. Thanks! – Vishaal Mar 24 '19 at 00:04
  • thanks for ur reply the problem was with network – manasi rakhecha Mar 29 '19 at 09:31

1 Answers1

0

kernel size exceed input error is usually seen when your input image is too small for the network. You either need to resize your input image, or change the network architecture to remove layers that reduce the spatial dimensions of the feature maps (e.g. pooling layers, or convolution with stride).

Thom Lane
  • 993
  • 9
  • 9