This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
eval.py
76 lines (65 loc) · 2.74 KB
/
eval.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
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
""" This script evaluates full F2F models on the val/test sets."""
import cv2
import os
import sys
import pprint
import torch
from mypython.logger import create_logger
#-------------------------------------------------------------------------------
from config import make_config
opt, configs, _ = make_config()
assert opt['train_single_level'] is None
assert opt['n_target_frames'] == 1 # >1 means batch prediction of >1 time steps
assert opt['n_target_frames_ar'] >= 1
#-------------------------------------------------------------------------------
# Start logging
logger = create_logger(os.path.join(opt['logs'], 'eval.log'))
logger.info('============ Initialized logger ============')
logger.info(pprint.pformat(opt))
#-------------------------------------------------------------------------------
# Create dataloader
valsetConfig = configs['valset']
from data_multiscale import load_cityscapes_val
logger.info(pprint.pprint(valsetConfig))
valsetConfig['loaded_model'] = None
valset = load_cityscapes_val(valsetConfig)
valLoader, loaded_model = iter(valset)
#-------------------------------------------------------------------------------
# Create model
modelsConfig = configs['models']
if opt['architecture'] == 'parallel':
if opt['architecture_f2fi'] == 'multiscale':
from models import F2F_multiscale as F2F
else:
raise NotImplementedError('architecture F2F not implemented: %r' % opt['architecture_f2fi'])
else:
raise NotImplementedError('architecture not implemented: %r' % opt['architecture'])
single_frame_model = F2F(modelsConfig)
autoregressiveConfig = {
'FfpnLevels' : opt['FfpnLevels'],
'n_target_frames_ar' : opt['n_target_frames_ar'],
'nb_features' : opt['nb_features'],
'n_input_frames' : opt['n_input_frames'],
'train_single_level' : opt['train_single_level'],
'nb_scales' : opt['nb_scales']
}
from autoregressive import Autoregressive
model = Autoregressive(autoregressiveConfig, single_frame_model)
assert not opt['model'] is None, 'This script is only for evaluation of a given model'
model.single_frame_model.load_state_dict(torch.load(opt['model']))
logger.info('loaded' + opt['model'])
model.cuda(opt['id_gpu_model'])
logger.info(model)
from mytorch.implementation_utils import get_nb_parameters
logger.info('This model has %d parameters.' % (get_nb_parameters(model)))
#-------------------------------------------------------------------------------
# Evaluate
from evaluation_functions import evaluate
evalConfig = configs['eval']
evaluate(evalConfig, model, valLoader)