Skip to content

Instantly share code, notes, and snippets.

@ogyalcin
Created September 17, 2020 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ogyalcin/a768a710daa51697f406d41bc04ceceb to your computer and use it in GitHub Desktop.
Save ogyalcin/a768a710daa51697f406d41bc04ceceb to your computer and use it in GitHub Desktop.
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