-
Notifications
You must be signed in to change notification settings - Fork 0
/
predict.py
40 lines (34 loc) · 1.11 KB
/
predict.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
40
import numpy as np
from PIL import Image
import sys
import getopt
from model_keras import DAE
def main(argv):
input_file = ""
output_file = ""
try:
opts, args = getopt.getopt(argv, 'hi:o:', ['ifile=', 'ofile='])
except getopt.GetoptError:
print('usage: python predict.py -i <input_file_path> -o <output_file_path>')
sys.exit(2)
options = [o[0] for o in opts]
print(options)
if ('-i' not in options and '--ifile' not in options) or ('-o' not in options and '--ofile' not in options):
print('Missing arguments')
print('usage: python predict.py -i <input_file_path> -o <output_file_path>')
sys.exit(2)
for opt, arg in opts:
if opt == 'h':
print('usage: python predict.py -i <input_file_path> -o <output_file_path>')
elif opt in ('-i', '--ifile'):
input_file = arg
elif opt in ('-o', '--ofile'):
output_file = arg
input_image = Image.open(input_file).convert('RGB')
input_image_array = np.array(input_image)
d = DAE()
d.load_model_weights('model_weights.hdf5')
output_image = d.denoise(input_image_array)
output_image.save(output_file, format='BMP')
if __name__ == '__main__':
main(sys.argv[1:])