https://github.com/pytorch/vision/blob/86001a871d3335046e2dca7715d9babf73e6956f/torchvision/transforms/transforms.py#L565
Inverted aspect ratio may be out of the range specified.
For example, RandomResizedCrop.get_params(img, ratio=(0.75,0.75)) can return something like (41, 17, 153, 204) where aspect ratio is 1.33.
Looks like you are right.
But I don't think it's simply a matter of removing the line you pointed out, because the sampling will not be uniform over the aspect ratios.
To give an example of why, imagine that we use ratios of 0.1 and 10. Randomly sampling over this interval will generally lead to samples with aspect ratio > 1, while one would expect it to be sampling with the same probability both cases (and that's why we have the line you mentioned).
How about
if random.random() < 0.5 and min(ratio) <= 1/aspect_ratio <= max(ratio):
w, h = h, w
@fmassa what do u think about the proposed solution ?
The solution you implemented prevents obviously invalid crops from being generated, but the distribution is uneven. Actually, the best way to deal with it is to use a uniform distribution _on a logarithmic scale_.
This automatically handles symmetry (logarithm of a reciprocal is a negative) and provides nice, smooth distributions and a sound mathematical basis.
Also, the mean of the distribution is the geometric mean of the ends of the interval (a, b):
exp( (log(a) + log(a)) / 2) = exp( log(ab) / 2) = exp(ab)^(1/2) = sqrt(ab)
@mzient would you be able to send a PR improving this?
I'll have to clear it with the company, but otherwise I would be glad to do so.
Let me know if it would be complicated, and I can make a PR myself
See: #799