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 2018/05/11 12:57:16 UTC

[GitHub] dwSun opened a new issue #10906: transforms.Compose not working as expected.

dwSun opened a new issue #10906: transforms.Compose not working as expected.
URL: https://github.com/apache/incubator-mxnet/issues/10906
 
 
   ```py
   #!/usr/bin/env python3
   # %% import libs
   import mxnet as mx
   from mxnet.gluon.data.vision import transforms
   
   # %% set random seed
   mx.random.seed(123)
   
   # %% the image
   img = mx.nd.random_uniform(0,255,(1024,1024,3))
   img.shape #(1024, 1024, 3)
   img.mean().asscalar() # 127.47173
   
   # %%
   transforms.Resize((224,320))(img).shape#(320, 224, 3)
   transforms.Resize((224,320))(img).mean().asscalar()#127.2181
   
   transforms.ToTensor()(img).shape#(3, 1024, 1024)
   transforms.ToTensor()(img).mean().asscalar()#0.49988914
   
   # %% This is confusing...
   transform1 = transforms.Compose(
       [transforms.ToTensor(), # should be (1024, 1024, 3) => (3, 1024, 1024)
       transforms.Resize((224, 320))]) # should be (3, 1024, 1024) => (320, 224, 1024)
   
   # I am confused with this 2 lines
   transform1(img).shape # got (1024, 320, 224) with mxnet-mkl-1.1.0; got (320, 224, 1024) with mxnet-mkl-1.2.0b20180508
   transform1(img).mean().asscalar() #got 0.00097802561 with mxnet-mkl-1.1.0;  got 0.24939652 with mxnet-mkl-1.2.0b20180508
   
   # %% This is the one works as expected.
   transform2 = transforms.Compose(
       [transforms.Resize((224, 320)),
       transforms.ToTensor()])
   
   transform2(img).shape#(3, 320, 224)
   transform2(img).mean().asscalar() # 0.49889451
   
   # %% Guess there is a ToTensor at the end implicitly.
   transform3 = transforms.Compose(
       [transforms.Resize((224, 320))])
   
   # Actually not!
   transform3(img).shape#(320, 224, 3)
   transform3(img).mean().asscalar() # 127.2181
   
   # %% those lines works exactlly as transform1 with mxnet-mkl-1.1.0, why?
   img_mod = transforms.ToTensor()(img)
   img_mod = transforms.Resize((224, 320))(img_mod)
   img_mod = transforms.ToTensor()(img_mod)
   
   img_mod.shape#(1024, 320, 224)
   img_mod.mean().asscalar() # 0.00097802561
   
   
   ```
   tested both with opencv-python            3.4.0.12 from pypi.

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