-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpredict.py
More file actions
27 lines (18 loc) · 713 Bytes
/
predict.py
File metadata and controls
27 lines (18 loc) · 713 Bytes
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
import os
# Try running on CPU
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
import numpy as np
import cv2
from keras.models import load_model
MODEL_NAME = './model.h5'
model = load_model(MODEL_NAME)
# Dont forget to delete gitkeep
for root, dirs, files in os.walk('./input', topdown=False):
for name in files:
print(os.path.join(root, name))
im = cv2.imread(os.path.join(root, name), cv2.IMREAD_GRAYSCALE)
im_predict = np.reshape(im, (1, im.shape[0], im.shape[1], 1))
im_predict = im_predict.astype(np.float32) / 255 * 2 - 1
result = model.predict(im_predict)
im_res = (result[0] + 1) / 2 * 255
cv2.imwrite(os.path.join('./output', name), im_res)