You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by gi...@git.apache.org on 2017/08/21 12:00:51 UTC
[GitHub] M4xim4l opened a new issue #7538: Different prediction when manually creating batch
M4xim4l opened a new issue #7538: Different prediction when manually creating batch
URL: https://github.com/apache/incubator-mxnet/issues/7538
Hey everyone,
I'm using mxnet-cu80 0.11.0 under Debian 8.
I was playing around with adversarial perturbations using mxnet and I noticed some strange behavior.
I have a batch which comes from an ImageIter which reads a .rec file and for this batch, the classifier seems to do the right prediction, namely for the first example in the batch I get label 956. However, when I create my own batch in the following way, the classifier predicts a different label for the first data point:
```
#this batch comes from the ImageIter
batch_data = batch.data[0]
batch_label = batch.label[0].asnumpy()
batch_size = batch_label.size
_, _, img_size, _ = batch_data.shape
#this is the new batch
perturbed_data = mx.nd.zeros(batch_data.shape)
#it should be all zeros, except for the first image in the batch
perturbed_data[0] = batch_data[0]
dataDesc = [mx.io.DataDesc('data', (batch_size, 3, img_size, img_size), layout='NCHW')]
new_batch = mx.io.DataBatch([perturbed_data], provide_data=dataDesc)
#forward pass on original batch
mod.forward(batch, is_train=True)
old_probs = mod.get_outputs()[0].asnumpy()
old_preds = np.argmax(old_probs,1)
#forward pass on new batch
mod.forward(new_batch, is_train=True)
new_probs = mod.get_outputs()[0].asnumpy()
new_preds = np.argmax(new_probs,1)
```
For the original batch, I get the output [956 577 201 64 412 307 314 141 54 641], whereas I get
[479 845 845 845 845 845 845 845 845 845] for the new batch, so I was wondering why the classifier predicts a different class in this case and how I could fix this behavior? I also tried removing the dataDesc, however this does not influence the classification.
Thanks,
Max
----------------------------------------------------------------
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