2424import albumentations as A
2525from albumentations .core .transforms_interface import DualTransform
2626from albumentations .augmentations .geometric import functional as fgeometric
27+ from packaging import version
28+
29+ ALBU_VERSION = version .parse (A .__version__ )
30+ IS_ALBU_NEW_VERSION = ALBU_VERSION >= version .parse ("1.4.15" )
2731
2832
2933# Custom resize transformation mimicking Imgaug's behavior with scaling
3034class ImgaugLikeResize (DualTransform ):
31- def __init__ (
32- self , scale_range = (0.5 , 3.0 ), interpolation = 1 , always_apply = False , p = 1.0
33- ):
34- super (ImgaugLikeResize , self ).__init__ (always_apply , p )
35+ def __init__ (self , scale_range = (0.5 , 3.0 ), interpolation = 1 , p = 1.0 ):
36+ super (ImgaugLikeResize , self ).__init__ (p )
3537 self .scale_range = scale_range
3638 self .interpolation = interpolation
3739
@@ -41,11 +43,10 @@ def apply(self, img, scale=1.0, **params):
4143 new_height = int (height * scale )
4244 new_width = int (width * scale )
4345
44- # For compatibility with Albumentations 1.4.15 and later
45- # return fgeometric.resize(
46- # img, (new_height, new_width), interpolation=self.interpolation
47- # )
48-
46+ if IS_ALBU_NEW_VERSION :
47+ return fgeometric .resize (
48+ img , (new_height , new_width ), interpolation = self .interpolation
49+ )
4950 return fgeometric .resize (
5051 img , new_height , new_width , interpolation = self .interpolation
5152 )
0 commit comments