-
Notifications
You must be signed in to change notification settings - Fork 17
/
run.py
39 lines (31 loc) · 1.15 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# This file processes an image
# If you change the training code, add normalization or something different
# Please make sure this works.
#
# Usage: run.py <model_file_path> <input_image> <output_image>
#
# model_file_path should initially be a path to an h5 file. By default wandb
# will save a model in wandb/<run_id>/model-best.h5
import argparse
import keras
from PIL import Image
import cv2
import numpy as np
parser = argparse.ArgumentParser(description='Run model file on input_image file and output out_image.')
parser.add_argument('model')
parser.add_argument('input_image')
parser.add_argument('output_image')
height=256
width=256
args = parser.parse_args()
model = keras.models.load_model(args.model)
img = Image.open(args.input_image).resize((width, height))
color_image = np.array(img)
# bw_image is the input image converted to black and white
bw_image = np.array(img.convert('L'))
bw_image = bw_image.reshape((1,width,height))
recolored_image_array = model.predict(bw_image)
# new_image is the output from the model
new_image = recolored_image_array[0].astype(np.uint8)
new_image = Image.fromarray(new_image, 'RGB' )
new_image.save(args.output_image)