forked from LiAoqi96/GAN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
77 lines (66 loc) · 3.23 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
76
77
import os
import tensorflow as tf
from model import DCGAN
import numpy as np
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
flags = tf.flags
flags.DEFINE_integer("epoch", 10, "Epoch to train [25]")
flags.DEFINE_float("learning_rate", 0.0002, "Learning rate of for adam [0.0002]")
flags.DEFINE_integer("train_size", 15071, "The size of train data [np.inf]")
flags.DEFINE_integer("batch_size", 64, "The size of batch data [64]")
flags.DEFINE_integer('input_depth', 12, 'The depth of data to use [12 for taxibj_v2, 8 for taxibj]')
flags.DEFINE_integer("input_height", 32, "The size of data to use (will be center cropped).")
flags.DEFINE_integer("input_width", None,
"The size of data to use (will be center cropped). If None, same value as input_height [None]")
flags.DEFINE_integer('output_depth', 12, 'The depth of the output data [12 for taxibj_v2, 8 for taxibj]')
flags.DEFINE_integer("output_height", 32, "The size of the output data to produce [64]")
flags.DEFINE_integer("output_width", None,
"The size of the output data to produce. If None, same value as output_height [None]")
flags.DEFINE_integer("c_dim", 8, "Dimension of data.]")
flags.DEFINE_string("dataset", "taxibj", "The name of dataset [taxibj, taxibj_v2]")
flags.DEFINE_string('data_type', '', 'Which the data is complete or not')
flags.DEFINE_string('mode', '3d', 'The mode of convolution')
flags.DEFINE_string("checkpoint_dir", "checkpoint", "Directory name to save the checkpoints [checkpoint]")
flags.DEFINE_string("sample_dir", "samples", "Directory name to save the data samples [samples]")
flags.DEFINE_boolean("is_train", False, "True for training, False for testing [False]")
FLAGS = flags.FLAGS
def main(_):
if FLAGS.input_width is None:
FLAGS.input_width = FLAGS.input_height
if FLAGS.output_width is None:
FLAGS.output_width = FLAGS.output_height
if not os.path.exists(FLAGS.checkpoint_dir):
os.makedirs(FLAGS.checkpoint_dir)
if not os.path.exists(FLAGS.sample_dir):
os.makedirs(FLAGS.sample_dir)
run_config = tf.ConfigProto(allow_soft_placement=True)
run_config.gpu_options.allow_growth = True
with tf.Session(config=run_config) as sess:
dcgan = DCGAN(
sess,
input_depth=FLAGS.input_depth,
input_width=FLAGS.input_width,
input_height=FLAGS.input_height,
output_depth=FLAGS.output_depth,
output_width=FLAGS.output_width,
output_height=FLAGS.output_height,
batch_size=FLAGS.batch_size,
sample_num=1,
c_dim=FLAGS.c_dim,
dataset_name=FLAGS.dataset,
data_type=FLAGS.data_type,
mode=FLAGS.mode,
checkpoint_dir=FLAGS.checkpoint_dir,
training=FLAGS.is_train)
if FLAGS.is_train:
dcgan.train(FLAGS)
exit(0)
else:
if not dcgan.load(FLAGS.checkpoint_dir):
raise Exception("[!] Train a model first, then run test mode")
sample_z = np.random.uniform(-1., 1., size=(10, 1, 100)).astype(np.float32)
dcgan.same(sample_z, radio=1)
# visualize(sess, dcgan, FLAGS, option=1)
if __name__ == '__main__':
tf.app.run()