-
Notifications
You must be signed in to change notification settings - Fork 18
/
patch_predict_SHT.py
executable file
·36 lines (29 loc) · 1.15 KB
/
patch_predict_SHT.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
# predict patch image's count using trained fully connected model
from keras.models import Sequential
from keras.models import model_from_json
from keras.layers import Dense, Dropout, Activation,LSTM
from keras.optimizers import SGD
import numpy as np
import scipy.io as sci
from features2XY import features2XY
test_data_dir = 'data/test_B_SHT.mat'
print('load testing data...')
test_data = sci.loadmat(test_data_dir)
X_test, Y_test = features2XY(test_data['features'][0], test_data['counts'][0])
# load trained model from disk
json_file = open('model/model_B_SHT.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
model = model_from_json(loaded_model_json)
# load weights into new model
model.load_weights("model/model_B_SHT.h5")
print("Loaded model from disk")
print(model.summary())
# exit()
model.compile(optimizer='Adam',
loss='mean_squared_error',
metrics=['mean_absolute_error'])
result = model.evaluate(X_test, Y_test, batch_size=1000, verbose=1, sample_weight=None)
print(result)
predictions = model.predict(X_test, batch_size=1000, verbose=0)
sci.savemat('data/predictions_B_SHT.mat', {'predictions':predictions})