forked from WarrenGreen/srcnn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestModel.py
More file actions
48 lines (36 loc) · 1.31 KB
/
testModel.py
File metadata and controls
48 lines (36 loc) · 1.31 KB
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
41
42
43
44
45
46
from keras.models import Sequential
from keras.layers.convolutional import Convolution2D
from keras.callbacks import ModelCheckpoint
import numpy as np
import os
from PIL import Image
BIT_DEPTH = 8
MAX_VAL = 2**8-1
TEST_PATH = "data/test/"
TEST_LABELS_PATH = "data/test_labels/"
def load_data(xPath, yPath):
X, Y = np.zeros((1876,400,400,3)), np.zeros((1876,400,400,3))
index = 0
for file in os.listdir(xPath):
index += 1
img = Image.open(xPath + file)
imgArray = np.asarray(img, dtype='uint8')
imgArray = imgArray / (MAX_VAL * 1.0)
X[index] = imgArray
img = Image.open(yPath + file)
imgArray = np.asarray(img, dtype='uint8')
imgArray = imgArray / (MAX_VAL * 1.0)
Y[index] = imgArray
return X, Y
def get_model():
model = Sequential()
model.add(Convolution2D(32, 9, activation="relu", input_shape=(400,400,3), padding="same"))
model.add(Convolution2D(16, 5, activation="relu", padding="same"))
model.add(Convolution2D(3, 5, activation="relu", padding="same"))
model.load_weights("models/weights.h5")
model.compile(optimizer="adam", loss="mse", metrics=['accuracy'])
return model
model = get_model()
X,Y = load_data(TEST_PATH, TEST_LABELS_PATH)
score = model.evaluate(X, Y)
print (model.metrics_names, score)