Skip to content

Instantly share code, notes, and snippets.

@malnakli
Created November 1, 2018 10:35
Show Gist options
  • Save malnakli/c3f9aeb06e96117388d742709afbe371 to your computer and use it in GitHub Desktop.
Save malnakli/c3f9aeb06e96117388d742709afbe371 to your computer and use it in GitHub Desktop.
from skimage.transform import resize
target_size = 96
def preprocess_image(x):
# Resize the image to have the shape of (96,96)
x = resize(x, (target_size, target_size),
mode='constant',
anti_aliasing=False)
# convert to 3 channel (RGB)
x = np.stack((x,)*3, axis=-1)
# Make sure it is a float32, here is why
# https://www.quora.com/When-should-I-use-tf-float32-vs-tf-float64-in-TensorFlow
return x.astype(np.float32)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment