You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2017/12/01 16:51:17 UTC

[GitHub] adrianloy opened a new issue #8910: Possible Bug in Mxnet when training a Network with no labels

adrianloy opened a new issue #8910: Possible Bug in Mxnet when training a Network with no labels
URL: https://github.com/apache/incubator-mxnet/issues/8910
 
 
   I am trying to implement a network that does not need training labels and I recieve the following error:
   
   ```
   Traceback (most recent call last):
     File "/home/adrian/PycharmProjects/DIRNet/convnet.py", line 135, in <module>
       num_epoch=10)
   
     File "/home/adrian/.local/lib/python3.5/site-packages/mxnet/module/base_module.py", line 460, in fit
       for_training=True, force_rebind=force_rebind)
   
     File "/home/adrian/.local/lib/python3.5/site-packages/mxnet/module/module.py", line 417, in bind
       state_names=self._state_names)
   
     File "/home/adrian/.local/lib/python3.5/site-packages/mxnet/module/executor_group.py", line 231, in __init__
       self.bind_exec(data_shapes, label_shapes, shared_group)
   
     File "/home/adrian/.local/lib/python3.5/site-packages/mxnet/module/executor_group.py", line 313, in bind_exec
       self.label_layouts = self.decide_slices(label_shapes)
   
     File "/home/adrian/.local/lib/python3.5/site-packages/mxnet/module/executor_group.py", line 241, in decide_slices
       assert len(data_shapes) > 0
   AssertionError
   ```
   
   When debugging, I discovered that `train_data.provide_label` in base_module.py (line 459) returns an empty list and not `None`. Therefore, in `bind_exec` in  `executor_group.py` the following if statement (line 311)
   
   ```
   if label_shapes is not None:
               # call it to make sure labels has the same batch size as data
               self.label_layouts = self.decide_slices(label_shapes)
   ```
   evaluates to true and the AssertionError is fired in `self.decide_slices(label_shapes)`, as label_shapes is an empty list instead of `None`. From the comment in the if statement I guess that this is a bug in Mxnet, as it should not check for correct shapes of the labels if I do not have any.
   
   My data iterator looks like this:
   ```
   def get_mnist_data_iterator(mnistdir='./data/', digit=1):
       def get_iterator_single_digit(data, label):
           one_digit_indices = []  # Contains all indices with images depicting the digit
           for index in range(len(label)):  # There might be a faster way to do this
               if label[index] == digit:
                   one_digit_indices.append(index)
           one_digit_data = data[one_digit_indices]
           one_digit_label = label[one_digit_indices]
           fixed_image = one_digit_data[np.random.randint(0, len(one_digit_label))]
           one_digit_fixed_image = []  # array of same length as above data array, but its the same img multiple times
           for _ in one_digit_data:
               one_digit_fixed_image.append(fixed_image)
           data = {'data_fixed': one_digit_fixed_image, 'data_moving': one_digit_data}
           iterator = mx.io.NDArrayIter(data, batch_size=1, shuffle=True)
           return iterator
   
       mnist = get_mnist(mnistdir)
       train_iter = get_iterator_single_digit(mnist['train_data'], mnist['train_label'])
       val_iter = get_iterator_single_digit(mnist['test_data'], mnist['test_label'])
       return train_iter, val_iter
   ```
   
   And here is my Module and fit call:
   ```
   if __name__ == '__main__':
       mnist_shape = (1, 28, 28)
       iterators = get_mnist_data_iterator()
       model = mx.mod.Module(symbol=get_symbol(mnist_shape), context=mx.gpu(),
                             label_names=None, data_names=['data_fixed', 'data_moving'])
       model.fit(iterators[0],  # eval_data=val_iter,
                       optimizer='sgd',
                       optimizer_params={'learning_rate': 0.1},
                       #eval_metric=eval_metrics,#mx.metric.Loss(),#'acc',
                       #batch_end_callback = mx.callback.Speedometer(batch_size, 100),
                       num_epoch=10)
   ```
   If you need more details let me know.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services