NVIDIA / DALI

A GPU-accelerated library containing highly optimized building blocks and an execution engine for data processing to accelerate deep learning training and inference applications.
https://docs.nvidia.com/deeplearning/dali/user-guide/docs/index.html
Apache License 2.0
5.06k stars 615 forks source link

Random rotate without cropping side #1118

Closed zheLim closed 4 years ago

zheLim commented 5 years ago

Hi, i would like to create random rotate/warpaffine operator without cropping side like OpenCV Python : rotate image without cropping sides. Firstly I suppose it can be done using Paste+rotate. However, random parameter pass to rotate operator cannot be known. Thus I cannot do padding before rotate. Any suggestion on this problem?

zheLim commented 5 years ago

BTW, It is not easy to do Mirror for image and mask at the same time. In my case CropMirrorNorm output wrong mask(i.e. value in msak is not 0/1). FastResizeCrop cannot be used, since mask require resize with inter_NN.

mzient commented 5 years ago

I'm currently reworking all warping operators (rotate, warp affine, etc). New rotate will enlarge canvas to accommodate whole image, while new WarpAffine will accept externally provided canvas size. It should be available quite soon, but I can't commit to any particular release. Using paste + warp/rotate is possible, but quite wasteful.

zheLim commented 5 years ago

@mzient Looking forward to your later commit!

lxlee commented 4 years ago

I have the same needs,is there any new solution now?

JanuszL commented 4 years ago

Hi, Reworked WarpAffine operator is already available in the master branch and you can try is by installing the nightly build of DALI. An example of how it works can be found https://docs.nvidia.com/deeplearning/sdk/dali-master-branch-user-guide/docs/examples/warp.html. @mzient anything to add?

mzient commented 4 years ago

Regarding rotate: the new rotate automatically adjusts canvas size to fit the image. Just download the new version and you're set. You can reuse the angles tensor for images and masks, too. If you need more than just rotation, you can use WarpAffine, but that leaves you on your own with calculating the matrix elements and output sizes. I guess some solution can be hacked together with the combination of ExternalSource for base transform matrices and incorporating the input sizes with the newly-added arithmetic operators (see https://docs.nvidia.com/deeplearning/sdk/dali-master-branch-user-guide/docs/examples/expressions.html) and Shapes operator. If the images at the input to WarpAffine are of uniform size, you can simply calculate the sizes and matrices in python and just feed them to the pipeline through external source.

JanuszL commented 4 years ago

This change is available in DALI 0.16.0.