@@ -37,14 +37,17 @@ def _load_image(path, scale, isotropic, crop, mean):
37
37
img = read_image (path )
38
38
# Rescale
39
39
if isotropic :
40
- scale = scale / float (min (w , h ))
41
- new_height , new_width = (h * scale , w * scale )
40
+ img_shape = tf .to_float (tf .shape (img )[:2 ])
41
+ min_length = tf .minimum (img_shape [0 ], img_shape [1 ])
42
+ new_shape = tf .to_int32 ((scale / min_length ) * img_shape )
42
43
else :
43
- new_height , new_width = (scale , scale )
44
- img = tf .image .resize_images (img , new_height , new_width )
45
- # Crop
46
- img = tf .image .crop_to_bounding_box (img , (new_height - crop ) / 2 ,
47
- (new_width - crop ) / 2 , crop , crop )
44
+ new_shape = tf .pack ([scale , scale ])
45
+ img = tf .image .resize_images (img , new_shape [0 ], new_shape [1 ])
46
+ # Center crop
47
+ # Use the slice workaround until crop_to_bounding_box supports deferred tensor shapes
48
+ # See: https://github.com/tensorflow/tensorflow/issues/521
49
+ offset = (new_shape - crop ) / 2
50
+ img = tf .slice (img , begin = tf .pack ([offset [0 ], offset [1 ], 0 ]), size = tf .pack ([crop , crop , - 1 ]))
48
51
# Mean subtraction
49
52
return tf .to_float (img ) - mean
50
53
0 commit comments