File tree 2 files changed +14
-6
lines changed
torchvision/prototype/transforms/functional
2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -251,6 +251,8 @@ def __init__(
251
251
ArgsKwargs (p = 0 ),
252
252
ArgsKwargs (p = 1 ),
253
253
],
254
+ # Use default tolerances of `torch.testing.assert_close`
255
+ closeness_kwargs = dict (rtol = None , atol = None ),
254
256
),
255
257
ConsistencyConfig (
256
258
prototype_transforms .RandomAdjustSharpness ,
Original file line number Diff line number Diff line change @@ -377,17 +377,23 @@ def autocontrast_image_tensor(image: torch.Tensor) -> torch.Tensor:
377
377
return image
378
378
379
379
bound = _FT ._max_value (image .dtype )
380
- dtype = image .dtype if torch .is_floating_point (image ) else torch .float32
380
+ fp = image .is_floating_point ()
381
+ float_image = image if fp else image .to (torch .float32 )
381
382
382
- minimum = image .amin (dim = (- 2 , - 1 ), keepdim = True ). to ( dtype )
383
- maximum = image .amax (dim = (- 2 , - 1 ), keepdim = True ). to ( dtype )
383
+ minimum = float_image .amin (dim = (- 2 , - 1 ), keepdim = True )
384
+ maximum = float_image .amax (dim = (- 2 , - 1 ), keepdim = True )
384
385
385
- scale = bound / (maximum - minimum )
386
386
eq_idxs = maximum == minimum
387
+ inv_scale = maximum .sub_ (minimum ).div_ (bound )
387
388
minimum [eq_idxs ] = 0.0
388
- scale [eq_idxs ] = 1.0
389
+ inv_scale [eq_idxs ] = 1.0
390
+
391
+ if fp :
392
+ diff = float_image .sub (minimum )
393
+ else :
394
+ diff = float_image .sub_ (minimum )
389
395
390
- return ( image - minimum ). mul_ ( scale ).clamp_ (0 , bound ).to (image .dtype )
396
+ return diff . div_ ( inv_scale ).clamp_ (0 , bound ).to (image .dtype )
391
397
392
398
393
399
autocontrast_image_pil = _FP .autocontrast
You can’t perform that action at this time.
0 commit comments