Skip to content

Instantly share code, notes, and snippets.

@Yuvnish017
Created June 24, 2021 06:36
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 Yuvnish017/807c6a187fb3bf443340f409b39d825e to your computer and use it in GitHub Desktop.
Save Yuvnish017/807c6a187fb3bf443340f409b39d825e to your computer and use it in GitHub Desktop.
def preprocess_image(image_path):
image = cv2.imread(image_path)
image = cv2.resize(image, (img_cols, img_rows))
image = np.array(image)
image = np.expand_dims(image, axis=0)
image = vgg16.preprocess_input(image)
return image
def deprocess_image(x):
# Util function to convert a tensor into a valid image
x = x.reshape((img_rows, img_cols, 3))
# Remove zero-center by mean pixel
x[:, :, 0] += 103.939
x[:, :, 1] += 116.779
x[:, :, 2] += 123.68
# 'BGR'->'RGB'
x = x[:, :, ::-1]
x = np.clip(x, 0, 255).astype("uint8")
return x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment