Add several features to converting images to blobs (#15204)
authorFei Sun <feisun@fb.com>
Sat, 15 Dec 2018 01:35:12 +0000 (17:35 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Sat, 15 Dec 2018 01:37:21 +0000 (17:37 -0800)
commite1808be37d7dd011e8c7baa1c881944aa1dd7163
treefeccd81ffdb2b9ccc240bb96b2f5db838a9fd2b7
parent717496e6c19b3c5f263f5b7836de3892d9802274
Add several features to converting images to blobs (#15204)

Summary:
Several enhancements are implemented:

* Resize the images to be within a boundary between min-size and max-size (can be height and weight). It tries to resize the minimum size to match the min-size and keep the aspect ratio. However, if in that case the maximum size is more than the max-size, then resize the maximum size to be equal to the max-size (and the minimum size is less than min-size). The min/max sizes are specified in argument scale, in a comma separated form. If one of the size is -1, then that size is not a restriction.

* Change the OpenCV resize function arguments from using cv::Size() to the x, y scale. Theoretically they should be the same. But in reality, the two ways of specifying them may result to different resized outputs.

* Once the image is read in, change the data to floats. That means, after resize and other preprocessing steps, the float values are preserved (not truncated to int).

* It is possible to convert data in text format to the blob format.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/15204

Reviewed By: llyfacebook

Differential Revision: D13467225

Pulled By: sf-wind

fbshipit-source-id: 7da34a72d43a9603cd7ab953f5821c1222d0178f
binaries/convert_image_to_tensor.cc