Skip to content

Instantly share code, notes, and snippets.

@ogyalcin
Created January 30, 2021 23:31
Show Gist options
  • Select an option

  • Save ogyalcin/4d4838424b86e080c0fe6ea2d0dde42b to your computer and use it in GitHub Desktop.

Select an option

Save ogyalcin/4d4838424b86e080c0fe6ea2d0dde42b to your computer and use it in GitHub Desktop.
def load_img(path_to_img):
# Reads and outputs the entire contents of the input filename.
img = tf.io.read_file(path_to_img)
# Detect whether an image is a BMP, GIF, JPEG, or PNG, and
# performs the appropriate operation to convert the input
# bytes string into a Tensor of type dtype
img = tf.image.decode_image(img, channels=3)
# Convert image to dtype, scaling (MinMax Normalization) its values if needed.
img = tf.image.convert_image_dtype(img, tf.float32)
# Scale the image using the custom function we created
img = img_scaler(img)
# Adds a fourth dimension to the Tensor because
# the model requires a 4-dimensional Tensor
return img[tf.newaxis, :]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment