-
Notifications
You must be signed in to change notification settings - Fork 1
/
cnn_train.py
35 lines (26 loc) · 982 Bytes
/
cnn_train.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
import os
import tensorflow as tf
from config import cfg
from model_eval import train
from cnn_baseline import CNN
from utils import get_dataset_values
def main(_):
dataset = cfg.dataset
input_shape, num_classes = get_dataset_values(dataset, cfg.batch_size)
tf.logging.info("Initializing CNN for {}...".format(dataset))
model = CNN(input_shape, num_classes, is_training=True)
tf.logging.info("Finished initialization.")
if not os.path.exists(cfg.logdir):
os.mkdir(cfg.logdir)
logdir = os.path.join(cfg.logdir, model.name)
if not os.path.exists(logdir):
os.mkdir(logdir)
logdir = os.path.join(logdir, dataset)
if not os.path.exists(logdir):
os.mkdir(logdir)
sv = tf.train.Supervisor(graph=model.graph, logdir=logdir, save_model_secs=0)
tf.logging.info("Initialize training...")
train(model, sv, dataset)
tf.logging.info("Finished training.")
if __name__ == '__main__':
tf.app.run()