-
Notifications
You must be signed in to change notification settings - Fork 57
/
run_evaluate.py
61 lines (47 loc) · 2.11 KB
/
run_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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from __future__ import print_function, absolute_import, division
import os
import os.path as path
import random
import numpy as np
import torch
import torch.backends.cudnn as cudnn
from function_baseline.config import get_parse_args
from function_baseline.data_preparation import data_preparation
from function_baseline.model_pos_preparation import model_pos_preparation
from function_poseaug.model_pos_eval import evaluate
def main(args):
print('==> Using settings {}'.format(args))
stride = args.downsample
cudnn.benchmark = True
device = torch.device("cuda")
print('==> Loading dataset...')
data_dict = data_preparation(args)
print("==> Creating model...")
model_pos = model_pos_preparation(args, data_dict['dataset'], device)
# Check if evaluate checkpoint file exist:
assert path.isfile(args.evaluate), '==> No checkpoint found at {}'.format(args.evaluate)
print("==> Loading checkpoint '{}'".format(args.evaluate))
ckpt = torch.load(args.evaluate)
try:
model_pos.load_state_dict(ckpt['state_dict'])
except:
model_pos.load_state_dict(ckpt['model_pos'])
print('==> Evaluating...')
error_h36m_p1, error_h36m_p2 = evaluate(data_dict['H36M_test'], model_pos, device)
print('H36M: Protocol #1 (MPJPE) overall average: {:.2f} (mm)'.format(error_h36m_p1))
print('H36M: Protocol #2 (P-MPJPE) overall average: {:.2f} (mm)'.format(error_h36m_p2))
error_3dhp_p1, error_3dhp_p2 = evaluate(data_dict['3DHP_test'], model_pos, device, flipaug='_flip')
print('3DHP: Protocol #1 (MPJPE) overall average: {:.2f} (mm)'.format(error_3dhp_p1))
print('3DHP: Protocol #2 (P-MPJPE) overall average: {:.2f} (mm)'.format(error_3dhp_p2))
if __name__ == '__main__':
args = get_parse_args()
# fix random
random_seed = args.random_seed
torch.manual_seed(random_seed)
torch.cuda.manual_seed(random_seed)
np.random.seed(random_seed)
random.seed(random_seed)
os.environ['PYTHONHASHSEED'] = str(random_seed)
# copy from #https://pytorch.org/docs/stable/notes/randomness.html
torch.backends.cudnn.deterministic = True
main(args)