forked from srijandas07/LSTM_action_recognition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lstm_evaluate.py
41 lines (34 loc) · 1.25 KB
/
lstm_evaluate.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
41
"""
Test load_model and obtain results (per class accuracies)
"""
import numpy as np
from keras.models import Model, load_model
from readers.smarthome_skeleton_fromjson_sampling import DataGenerator
from tqdm import tqdm
import config as cfg
print('Loading model ...')
wdir = cfg.weights_dir + '/weights_' + cfg.name
model = load_model('%s/epoch_150_101.hdf5' % wdir)
# model = load_model('./weights_crossview_nt_rot_sw/epoch_290.hdf5')
print('Done.')
splits_dir = cfg.dataset_dir + '/splits'
if cfg.num_classes == 19: # Cross-view
print('Assuming cross-view.')
test_generator = DataGenerator(splits_dir + '/test_CV.txt', batch_size=1)
elif cfg.num_classes == 35: # Cross-subject
print('Assuming cross-subject.')
test_generator = DataGenerator(splits_dir + '/test_CS.txt', batch_size=1)
num_tests = len(test_generator)
print('Testing %d samples.' % num_tests)
nc = test_generator.n_classes
print('number of classes: %d' % nc)
conf_mat = np.zeros((nc, nc))
for i in tqdm(range(num_tests)):
sample = test_generator[i]
x, y, wg = sample
pred = model.predict(x)
p = np.argmax(pred)
t = np.argmax(y)
conf_mat[t, p] += 1
np.savetxt("confusion_matrix_lstm_CS_nt_rot_wc_298_THIRD.csv", conf_mat, delimiter=";")
print('FINISHED.')