This repository has been archived by the owner on Jan 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 104
/
test_tum.py
119 lines (97 loc) · 4.09 KB
/
test_tum.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import torch
from options.train_options import TrainOptions
from loaders import aligned_data_loader
from models import pix2pix_model
BATCH_SIZE = 1
opt = TrainOptions().parse() # set CUDA_VISIBLE_DEVICES before import torch
eval_TUM_list_path = 'test_data/test_tum_hdf5_list.txt'
isTrain = False
eval_num_threads = 1
eval_data_loader = aligned_data_loader.TUMDataLoader(opt, eval_TUM_list_path,
isTrain, BATCH_SIZE,
eval_num_threads)
dataset = eval_data_loader.load_data()
data_size = len(eval_data_loader)
print('========================= TUM evaluation #images = %d =========' %
data_size)
model = pix2pix_model.Pix2PixModel(opt, False)
torch.backends.cudnn.enabled = True
torch.backends.cudnn.benchmark = True
best_epoch = 0
global_step = 0
print(
'================================= BEGIN TUM VALIDATION ====================================='
)
print('TESTING ON TUM')
total_si_error = 0.0
total_si_human_full_error = 0.0
total_si_env_error = 0.0
total_si_human_intra_error = 0.0
total_si_human_inter_error = 0.0
total_rel = 0.0
total_rmse = 0.0
count = 0.0
print(
'============================= TUM Validation ============================'
)
model.switch_to_eval()
for i, data in enumerate(dataset):
print(i)
stacked_img = data[0]
targets = data[1]
sc_inv_errors, rel_error, RMSE_error = model.evaluate_tum_error(
stacked_img, targets, global_step, False)
count += stacked_img.size(0)
total_si_error += sc_inv_errors[0]
total_si_human_full_error += sc_inv_errors[1]
total_si_env_error += sc_inv_errors[2]
total_si_human_intra_error += sc_inv_errors[3]
total_si_human_inter_error += sc_inv_errors[4]
total_rel += rel_error
total_rmse += RMSE_error
sc_inv_rmse = float(total_si_error) / float(count)
sc_inv_human_rmse = float(total_si_human_full_error) / float(count)
sc_inv_env_rmse = float(total_si_env_error) / float(count)
sc_inv_intra_rmse = float(
total_si_human_intra_error) / float(count)
sc_inv_inter_rmse = float(
total_si_human_inter_error) / float(count)
rel_avg = float(total_rel) / float(count)
rmse_avg = float(total_rmse) / float(count)
print('============== Sc-inv full RMSE: %f' % sc_inv_rmse)
print('============== Sc-inv Human Full RMSE: %f' %
sc_inv_human_rmse)
print('============== Sc-inv Human Intra RMSE: %f' %
sc_inv_intra_rmse)
print('============== Sc-inv Human Inter RMSE: %f' %
sc_inv_inter_rmse)
print('============== Sc-inv Env RMSE: %f' % sc_inv_env_rmse)
print('============== rel_avg: %f' % rel_avg)
print('============== rmse_avg: %f' % rmse_avg)
sc_inv_rmse = float(total_si_error) / float(count)
sc_inv_human_rmse = float(total_si_human_full_error) / float(count)
sc_inv_env_rmse = float(total_si_env_error) / float(count)
sc_inv_intra_rmse = float(total_si_human_intra_error) / float(count)
sc_inv_inter_rmse = float(total_si_human_inter_error) / float(count)
rel_avg = float(total_rel) / float(count)
rmse_avg = float(total_rmse) / float(count)
print('============== Sc-inv full RMSE: %f' % sc_inv_rmse)
print('============== Sc-inv Human Full RMSE: %f' % sc_inv_human_rmse)
print('============== Sc-inv Human Intra RMSE: %f' % sc_inv_intra_rmse)
print('============== Sc-inv Human Inter RMSE: %f' % sc_inv_inter_rmse)
print('============== Sc-inv Env RMSE: %f' % sc_inv_env_rmse)
print('============== rel_avg: %f' % rel_avg)
print('============== rmse_avg: %f' % rmse_avg)