-
Notifications
You must be signed in to change notification settings - Fork 111
/
eval2.py
70 lines (51 loc) · 1.78 KB
/
eval2.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
# -*- coding: utf-8 -*-
# /usr/bin/python2
from __future__ import print_function
import tensorflow as tf
from data_load import get_batch
from models import Model
import argparse
from hparams import logdir_path
import hparams as hp
def eval(logdir='logdir/default/train2', queue=True):
# Load graph
model = Model(mode="test2", batch_size=hp.Test2.batch_size, queue=queue)
# Loss
loss_op = model.loss_net2()
# Summary
summ_op = summaries(loss_op)
session_conf = tf.ConfigProto(
allow_soft_placement=True,
device_count={'CPU': 1, 'GPU': 0},
)
with tf.Session(config=session_conf) as sess:
# Load trained model
sess.run(tf.global_variables_initializer())
model.load(sess, 'test2', logdir=logdir)
writer = tf.summary.FileWriter(logdir, sess.graph)
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
if queue:
summ, loss = sess.run([summ_op, loss_op])
else:
mfcc, spec, mel = get_batch(model.mode, model.batch_size)
summ, loss = sess.run([summ_op, loss_op], feed_dict={model.x_mfcc: mfcc, model.y_spec: spec, model.y_mel: mel})
writer.add_summary(summ)
writer.close()
coord.request_stop()
coord.join(threads)
print("loss:", loss)
def summaries(loss):
tf.summary.scalar('net2/eval/loss', loss)
return tf.summary.merge_all()
def get_arguments():
parser = argparse.ArgumentParser()
parser.add_argument('case', type=str, help='experiment case name')
arguments = parser.parse_args()
return arguments
if __name__ == '__main__':
args = get_arguments()
case = args.case
logdir = '{}/{}/train2'.format(logdir_path, case)
eval(logdir=logdir)
print("Done")