Created
September 17, 2020 11:52
-
-
Save ogyalcin/a768a710daa51697f406d41bc04ceceb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def img_scaler(image, max_dim = 512): | |
# Casts a tensor to a new type. | |
original_shape = tf.cast(tf.shape(image)[:-1], tf.float32) | |
# Creates a scale constant for the image | |
scale_ratio = max_dim / max(original_shape) | |
# Casts a tensor to a new type. | |
new_shape = tf.cast(original_shape * scale_ratio, tf.int32) | |
# Resizes the image based on the scaling constant generated above | |
return tf.image.resize(image, new_shape) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment