-
Notifications
You must be signed in to change notification settings - Fork 1
/
predict.py
45 lines (35 loc) · 1.11 KB
/
predict.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
#! /usr/bin/python
# -*- coding: utf8 -*-
import tensorflow as tf
from utils.get_model import GetModel
from data_loader.load_data import Data
from utils.config import load_config, log_config
from utils.utils import get_args
import time,os
def main():
# capture the config path from the run arguments
# then process the json configuration file
try:
args = get_args()
except:
print("missing or invalid arguments")
exit(0)
exp_name = args.opt
args.opt = 'experiments/{0}/config.json'.format(exp_name)
config = load_config(args.opt, is_train = False, exp_name= exp_name)
os.environ["CUDA_VISIBLE_DEVICES"] = args.gpu
if not config.exp_name :
raise Exception('please specify experiment name')
# create the data generator
data = Data(config)
# create an instance of the model
Model = GetModel(config.model)
model = Model(config)
# create trainer and pass all the previous components to it
model.compile(data)
#load model if exists
model.load()
# evaluate the model
model.evaluate()
if __name__ == '__main__':
main()