-
Notifications
You must be signed in to change notification settings - Fork 36
/
main.py
75 lines (67 loc) · 3.06 KB
/
main.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
import os
import time
import argparse
import tensorflow as tf
from network import PixelDCN
"""
This file provides configuration to build U-NET for semantic segmentation.
"""
def configure():
# training
flags = tf.app.flags
flags.DEFINE_integer('max_step', 6, '# of step for training')
flags.DEFINE_integer('test_interval', 100, '# of interval to test a model')
flags.DEFINE_integer('save_interval', 2, '# of interval to save model')
flags.DEFINE_integer('summary_interval', 100, '# of step to save summary')
flags.DEFINE_float('learning_rate', 1e-3, 'learning rate')
# data
flags.DEFINE_string('data_dir', './dataset/', 'Name of data directory')
flags.DEFINE_string('train_data', 'training3d.h5', 'Training data')
flags.DEFINE_string('valid_data', 'validation3d.h5', 'Validation data')
flags.DEFINE_string('test_data', 'testing3d.h5', 'Testing data')
flags.DEFINE_string('data_type', '3D', '2D data or 3D data')
flags.DEFINE_integer('batch', 2, 'batch size')
flags.DEFINE_integer('channel', 1, 'channel size')
flags.DEFINE_integer('depth', 16, 'depth size')
flags.DEFINE_integer('height', 256, 'height size')
flags.DEFINE_integer('width', 256, 'width size')
# Debug
flags.DEFINE_string('logdir', './logdir', 'Log dir')
flags.DEFINE_string('modeldir', './modeldir', 'Model dir')
flags.DEFINE_string('sampledir', './samples/', 'Sample directory')
flags.DEFINE_string('model_name', 'model', 'Model file name')
flags.DEFINE_integer('reload_step', 0, 'Reload step to continue training')
flags.DEFINE_integer('test_step', 0, 'Test or predict model at this step')
flags.DEFINE_integer('random_seed', int(time.time()), 'random seed')
# network architecture
flags.DEFINE_integer('network_depth', 5, 'network depth for U-Net')
flags.DEFINE_integer('class_num', 2, 'output class number')
flags.DEFINE_integer('start_channel_num', 16,
'start number of outputs for the first conv layer')
flags.DEFINE_string(
'conv_name', 'conv',
'Use which conv op in decoder: conv or ipixel_cl')
flags.DEFINE_string(
'deconv_name', 'ipixel_dcl',
'Use which deconv op in decoder: deconv, pixel_dcl, ipixel_dcl')
flags.DEFINE_string(
'action', 'concat',
'Use how to combine feature maps in pixel_dcl and ipixel_dcl: concat or add')
# fix bug of flags
flags.FLAGS.__dict__['__parsed'] = False
return flags.FLAGS
def main(_):
parser = argparse.ArgumentParser()
parser.add_argument('--option', dest='option', type=str, default='train',
help='actions: train, test, or predict')
args = parser.parse_args()
if args.option not in ['train', 'test', 'predict']:
print('invalid option: ', args.option)
print("Please input a option: train, test, or predict")
else:
model = PixelDCN(tf.Session(), configure())
getattr(model, args.option)()
if __name__ == '__main__':
# configure which gpu or cpu to use
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
tf.app.run()