Skip to content

Instantly share code, notes, and snippets.

@sgl0v
Created June 2, 2021 19:16
Show Gist options
  • Save sgl0v/79cb63414b97c0e5edb035acb5e5f93f to your computer and use it in GitHub Desktop.
Save sgl0v/79cb63414b97c0e5edb035acb5e5f93f to your computer and use it in GitHub Desktop.
def colorize(image_name):
image = img_to_array(load_img(image_name))
image = np.array(image, dtype=np.float32)
X = rgb2lab(1.0/255*image)[:, :, 0]
X = X.reshape(1, 400, 400, 1)
model = ct.models.MLModel('model_alpha.mlmodel')
input = np.zeros((1, 400, 400))
input[0] = X[0][:, :, 0]
output = model.predict({'input_1': X})["Identity"]
output *= 128
# Create & save output
output_lab = np.zeros((400, 400, 3))
output_lab[:, :, 0] = X[0][:, :, 0]
output_lab[:, :, 1] = output[0][:, :, 0]
output_lab[:, :, 2] = output[0][:, :, 1]
output_rgb = lab2rgb(output_lab)
imsave("output.jpg", output_rgb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment