@@ -71,26 +71,26 @@ def set_training_random_scale_factors(self, scale_min, scale_max):
7171 """Set the parameters for multiscale training."""
7272 # Select a random scale factor.
7373 random_scale_factor = tf .random_uniform ([], scale_min , scale_max )
74- scaled_size_y = tf .to_int32 (random_scale_factor * self ._output_size [0 ])
75- scaled_size_x = tf .to_int32 (random_scale_factor * self ._output_size [1 ])
74+ scaled_y = tf .cast (random_scale_factor * self ._output_size [0 ], tf . int32 )
75+ scaled_x = tf .cast (random_scale_factor * self ._output_size [1 ], tf . int32 )
7676
7777 # Recompute the accurate scale_factor using rounded scaled image size.
78- height = tf .shape (self ._image )[0 ]
79- width = tf .shape (self ._image )[1 ]
80- image_scale_y = tf .to_float ( scaled_size_y ) / tf . to_float ( height )
81- image_scale_x = tf .to_float ( scaled_size_x ) / tf . to_float ( width )
78+ height = tf .cast ( tf . shape (self ._image )[0 ], tf . float32 )
79+ width = tf .cast ( tf . shape (self ._image )[1 ], tf . float32 )
80+ image_scale_y = tf .cast ( scaled_y , tf . float32 ) / height
81+ image_scale_x = tf .cast ( scaled_x , tf . float32 ) / width
8282 image_scale = tf .minimum (image_scale_x , image_scale_y )
8383
8484 # Select non-zero random offset (x, y) if scaled image is larger than
8585 # self._output_size.
86- scaled_height = tf .to_int32 ( tf . to_float ( height ) * image_scale )
87- scaled_width = tf .to_int32 ( tf . to_float ( width ) * image_scale )
88- offset_y = tf .to_float (scaled_height - self ._output_size [0 ])
89- offset_x = tf .to_float (scaled_width - self ._output_size [1 ])
86+ scaled_height = tf .cast ( height * image_scale , tf . int32 )
87+ scaled_width = tf .cast ( width * image_scale , tf . int32 )
88+ offset_y = tf .cast (scaled_height - self ._output_size [0 ], tf . float32 )
89+ offset_x = tf .cast (scaled_width - self ._output_size [1 ], tf . float32 )
9090 offset_y = tf .maximum (0.0 , offset_y ) * tf .random_uniform ([], 0 , 1 )
9191 offset_x = tf .maximum (0.0 , offset_x ) * tf .random_uniform ([], 0 , 1 )
92- offset_y = tf .to_int32 (offset_y )
93- offset_x = tf .to_int32 (offset_x )
92+ offset_y = tf .cast (offset_y , tf . int32 )
93+ offset_x = tf .cast (offset_x , tf . int32 )
9494 self ._image_scale = image_scale
9595 self ._scaled_height = scaled_height
9696 self ._scaled_width = scaled_width
@@ -100,13 +100,13 @@ def set_training_random_scale_factors(self, scale_min, scale_max):
100100 def set_scale_factors_to_output_size (self ):
101101 """Set the parameters to resize input image to self._output_size."""
102102 # Compute the scale_factor using rounded scaled image size.
103- height = tf .shape (self ._image )[0 ]
104- width = tf .shape (self ._image )[1 ]
105- image_scale_y = tf .to_float (self ._output_size [0 ]) / tf . to_float ( height )
106- image_scale_x = tf .to_float (self ._output_size [1 ]) / tf . to_float ( width )
103+ height = tf .cast ( tf . shape (self ._image )[0 ], tf . float32 )
104+ width = tf .cast ( tf . shape (self ._image )[1 ], tf . float32 )
105+ image_scale_y = tf .cast (self ._output_size [0 ], tf . float32 ) / height
106+ image_scale_x = tf .cast (self ._output_size [1 ], tf . float32 ) / width
107107 image_scale = tf .minimum (image_scale_x , image_scale_y )
108- scaled_height = tf .to_int32 ( tf . to_float ( height ) * image_scale )
109- scaled_width = tf .to_int32 ( tf . to_float ( width ) * image_scale )
108+ scaled_height = tf .cast ( height * image_scale , tf . int32 )
109+ scaled_width = tf .cast ( width * image_scale , tf . int32 )
110110 self ._image_scale = image_scale
111111 self ._scaled_height = scaled_height
112112 self ._scaled_width = scaled_width
@@ -151,7 +151,7 @@ def resize_and_crop_boxes(self):
151151 # Adjust box coordinates based on the offset.
152152 box_offset = tf .stack ([self ._crop_offset_y , self ._crop_offset_x ,
153153 self ._crop_offset_y , self ._crop_offset_x ,])
154- boxes -= tf .to_float (tf .reshape (box_offset , [1 , 4 ]))
154+ boxes -= tf .cast (tf .reshape (box_offset , [1 , 4 ]), tf . float32 )
155155 # Clip the boxes.
156156 boxes = self .clip_boxes (boxes )
157157 # Filter out ground truth boxes that are all zeros.
0 commit comments