-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathevaluations.py
executable file
·60 lines (47 loc) · 1.67 KB
/
evaluations.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
#!/usr/bin/env python3
"""
Copyright 2020, Zixin Luo, HKUST.
Evaluation script.
"""
import os
import yaml
import tensorflow as tf
import progressbar
from datasets import get_dataset
from models import get_model
FLAGS = tf.app.flags.FLAGS
tf.app.flags.DEFINE_string('config', None, """Path to the configuration file.""")
def extract_feat(config):
"""Extract augmented features."""
prog_bar = progressbar.ProgressBar()
config['stage'] = 'det'
dataset = get_dataset(config['data_name'])(**config)
prog_bar.max_value = dataset.data_length
test_set = dataset.get_test_set()
model = get_model('feat_model')(config['model_path'], **(config['net']))
idx = 0
while True:
try:
data = next(test_set)
if config['overwrite'] or not os.path.exists(data['dump_path']):
desc, kpt, score = model.run_test_data(data['image'])
dump_data = {}
dump_data['dump_data'] = (desc, kpt, score)
dump_data['image_path'] = data['image_path']
dump_data['dump_path'] = data['dump_path']
dataset.format_data(dump_data)
prog_bar.update(idx)
idx += 1
except dataset.end_set:
break
model.close()
def main(argv=None): # pylint: disable=unused-argument
"""Program entrance."""
with open(FLAGS.config, 'r') as f:
config = yaml.load(f, Loader=yaml.FullLoader)
if config['dump_root'] is not None and not os.path.exists(config['dump_root']):
os.mkdir(config['dump_root'])
extract_feat(config)
if __name__ == '__main__':
tf.flags.mark_flags_as_required(['config'])
tf.compat.v1.app.run()