apache / mxnet

Lightweight, Portable, Flexible Distributed/Mobile Deep Learning with Dynamic, Mutation-aware Dataflow Dep Scheduler; for Python, R, Julia, Scala, Go, Javascript and more
https://mxnet.apache.org
Apache License 2.0
20.78k stars 6.79k forks source link

gluon.data.vision.transforms.RandomRotation does not work when NumPy-array semantics is turned on #20223

Open FLSAlg opened 3 years ago

FLSAlg commented 3 years ago

Description

if npx.set_np() sets numpy-array semantics on then RandomRotation will not work

Error Message

File "C:\Users.....\venv\lib\site-packages\mxnet\gluon\block.py", line 682, in call out = self.forward(*args) File "C:\Users.......\venv\lib\site-packages\mxnet\gluon\data\vision\transforms.py", line 269, in forward raise TypeError("This transformation only supports float32. " TypeError: This transformation only supports float32. Consider calling it after ToTensor

To Reproduce

        from mxnet import npx
        import mxnet as mx
        from mxnet.gluon.data.vision import transforms

        npx.set_np()   # without this (or with npx.reset_np()) there is no problem

        img = mx.image.imread("image.png")
        img_t = transforms.ToTensor()(img)
        rotation = transforms.RandomRotation((5, 6), True, False)  
        img_rt = rotation(img_t)  # this generates the error

Steps to reproduce

  1. Run the code snippet above

What have you tried to solve it?

I suspect there are more transforms with this problem - dont have time to search and catalog all appearnces. My work around is to deactivate np semantics with npx.reset_np() before calling functions from transforms and then reactivate with npx.set_np() afterwards (the problem appears in a large project)

Environment

mxnet 1.7.0.post2

github-actions[bot] commented 3 years ago

Welcome to Apache MXNet (incubating)! We are on a mission to democratize AI, and we are glad that you are contributing to it by opening this issue. Please make sure to include all the relevant context, and one of the @apache/mxnet-committers will be here shortly. If you are interested in contributing to our project, let us know! Also, be sure to check out our guide on contributing to MXNet and our development guides wiki.