From 1e07500da9fc855ad4b5f9318d8d795c160cfb00 Mon Sep 17 00:00:00 2001 From: Patrick Leary Date: Thu, 16 May 2024 12:27:29 -0400 Subject: [PATCH] fix variable names, use native min method --- lib/inat_inferrer.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/inat_inferrer.py b/lib/inat_inferrer.py index 977e09a..dfcb608 100644 --- a/lib/inat_inferrer.py +++ b/lib/inat_inferrer.py @@ -563,10 +563,10 @@ def prepare_image_for_inference(file_path): eventual_size = 299 central_crop_factor = 0.875 - resize_min_dimension = eventual_size/central_crop_factor + resize_min_dimension = eventual_size / central_crop_factor height, width = image.shape[0], image.shape[1] - resize_ratio = np.array([height, width]).min() / resize_min_dimension + resize_ratio = min(height, width) / resize_min_dimension new_height = math.ceil(height / resize_ratio) new_width = math.ceil(width / resize_ratio) # resize the image so we can take a central crop without needing to resample again @@ -577,11 +577,11 @@ def prepare_image_for_inference(file_path): preserve_aspect_ratio=True ) # determine the upper-left corner that needs to be used to grab the square crop - upper_left = math.floor((new_height - eventual_size) / 2) - upper_right = math.floor((new_width - eventual_size) / 2) + offset_height = math.floor((new_height - eventual_size) / 2) + offset_width = math.floor((new_width - eventual_size) / 2) # take a square crop out of the resized image image = tf.image.crop_to_bounding_box( - image, upper_left, upper_right, eventual_size, eventual_size + image, offset_height, offset_width, eventual_size, eventual_size ) return tf.expand_dims(image, 0)