Created
June 24, 2021 06:36
-
-
Save Yuvnish017/807c6a187fb3bf443340f409b39d825e 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 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