I’m using python 3.6.8 and mxnet-cu101==1.5.0.
I hava a question about ‘gluon.data.vision.transforms’.
this is my code.
import mxnet as mx
from mxnet import image, gluon
img = image.imread(‘sample.png’)
method 1
transformer1 = gluon.data.vision.transforms.Compose([
gluon.data.vision.transforms.ToTensor(),
gluon.data.vision.transforms.Normalize([.5, .5, .5], [.5, .5, .5])
])
img1 = transformer1(img)
method 2
transformer2 = gluon.data.vision.transforms.Compose([
gluon.data.vision.transforms.ToTensor(),
gluon.data.vision.transforms.Normalize(0.5, 0.5)
])
img2 = transformer2(img)
another method
img3 = img.transpose((2,0,1)).astype(‘float32’) / 127.5 - 1
The result is below.
import numpy as np
np.array_equal(img1.asnumpy(), img2.asnumpy())
False
np.array_equal(img1.asnumpy(), img3.asnumpy())
True
I can’t understand why ‘img1’ is not equal ‘img2’.
I would be grateful if anyone could tell me.
spanev
2
I just tried it in 1.4 then 1.5. Works fine for 1.4 but not in 1.5.
It looks when using method2 the std
didn’t work for the last channel.
img = mx.nd.random.uniform(0,255, shape=(4,4,3))
[... declaring and applying transforms ...]
>>> img
[[[139.94745 151.17537 182.37328 ]
[215.28777 153.70465 218.77614 ]
[138.94522 216.0492 108.031975 ]
[159.00874 164.703 98.017334 ]]
[[111.58474 75.87133 227.40211 ]
[ 14.461809 245.734 69.52735 ]
[ 97.77759 121.8046 201.8899 ]
[207.10303 134.8682 122.39417 ]]
[[144.85136 100.160126 236.02715 ]
[213.20009 18.114195 86.036026 ]
[ 22.21797 165.28383 5.1556916]
[ 93.901596 212.31805 244.07457 ]]
[[198.42998 35.789448 221.8531 ]
[221.87225 249.54767 120.77005 ]
[203.78543 204.23225 117.67724 ]
[132.72176 199.03494 173.11429 ]]]
<NDArray 4x4x3 @cpu(0)>
>>> img1
[[[ 0.09762704 0.6885315 0.08976638 0.24712741]
[-0.1248256 -0.88657403 -0.23311698 0.62433743]
[ 0.13608909 0.6721575 -0.8257414 -0.2635169 ]
[ 0.5563135 0.74017453 0.59831715 0.04095495]]
[[ 0.18568921 0.20552671 0.6945034 0.29178822]
[-0.40493077 0.9273255 -0.04466975 0.0577898 ]
[-0.21443039 -0.8579279 0.2963438 0.6652397 ]
[-0.7192985 0.95723665 0.60182154 0.5610584 ]]
[[ 0.43037868 0.71589124 -0.15269041 -0.23123658]
[ 0.783546 -0.45468742 0.5834501 -0.04004568]
[ 0.8511933 -0.32520765 -0.9595632 0.91431034]
[ 0.7400243 -0.05278391 -0.07704127 0.35775912]]]
<NDArray 3x4x4 @cpu(0)>
>>> img2
[[[ 0.09762704 0.6885315 0.08976638 0.24712741]
[-0.1248256 -0.88657403 -0.23311698 0.62433743]
[ 0.13608909 0.6721575 -0.8257414 -0.2635169 ]
[ 0.5563135 0.74017453 0.59831715 0.04095495]]
[[ 0.18568921 0.20552671 0.6945034 0.29178822]
[-0.40493077 0.9273255 -0.04466975 0.0577898 ]
[-0.21443039 -0.8579279 0.2963438 0.6652397 ]
[-0.7192985 0.95723665 0.60182154 0.5610584 ]]
[[ 1.4303787 1.7158912 0.8473096 0.7687634 ]
[ 1.783546 0.5453126 1.5834501 0.9599543 ]
[ 1.8511933 0.67479235 0.0404368 1.9143103 ]
[ 1.7400243 0.9472161 0.92295873 1.3577591 ]]]
<NDArray 3x4x4 @cpu(0)>
Thank you for your quick response.
Is it a bug?
spanev
4
After investigating, it seems like it was a bug fixed in https://github.com/apache/incubator-mxnet/pull/15539/
Many thanks.
I changed mxnet-cu101 version from 1.5.0 to 1.6.0b20190805.
This problem was salved.