File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ from .aim_inference import AIMInference
1
2
from .auto_augment import AutoAugment
2
3
from .native_aspect_ratio_resize import NativeAspectRatioResize
3
4
from .random_crop import RandomCrop
6
7
from .square_resize import SquareResize
7
8
8
9
__all__ = [
10
+ AIMInference ,
9
11
AutoAugment ,
10
12
NativeAspectRatioResize ,
11
13
RandomCrop ,
Original file line number Diff line number Diff line change
1
+ import tensorflow as tf
2
+
3
+ from transformations .transformation import Transformation
4
+
5
+
6
+ class AIMInference (Transformation ):
7
+ def __init__ (self , resize_size , crop_size ):
8
+ self .resize_size = resize_size
9
+ self .crop_size = crop_size
10
+ self .offset = (resize_size - crop_size ) // 2
11
+
12
+ def __call__ (self , image ):
13
+ height = tf .cast (tf .shape (image )[0 ], tf .float32 )
14
+ width = tf .cast (tf .shape (image )[1 ], tf .float32 )
15
+
16
+ if height < width :
17
+ factor = self .resize_size / height
18
+ else :
19
+ factor = self .resize_size / width
20
+
21
+ new_height = tf .cast (height * factor , tf .int32 )
22
+ new_width = tf .cast (width * factor , tf .int32 )
23
+
24
+ resized_image = tf .image .resize (
25
+ image ,
26
+ [new_height , new_width ],
27
+ method = tf .image .ResizeMethod .BICUBIC ,
28
+ antialias = True
29
+ )
30
+
31
+ cropped_image = tf .image .crop_to_bounding_box (
32
+ resized_image ,
33
+ self .offset , self .offset ,
34
+ 224 , 224
35
+ )
36
+ return cropped_image
You can’t perform that action at this time.
0 commit comments