-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.py
96 lines (78 loc) · 3.22 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
import os
import sys
import argparse
import numpy as np
import tensorflow as tf
from model import BicycleGAN
from folder import check_folder
#from load_data import load_images
def parse_args():
desc = "Tensorflow implementation of BicycleGAN"
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('--Z_dim', type=int, default=8, help='Size of latent vector')
parser.add_argument('--reconst_coeff', type=float, default=10, help='Reconstruction Coefficient')
parser.add_argument('--latent_coeff', type=float, default=0.5, help='Latent Coefficient')
parser.add_argument('--kl_coeff', type=float, default=0.01, help='KL Coefficient')
parser.add_argument('--learning_rate', type=float, default=0.0001, help='Learning Rate')
parser.add_argument('--image_size', type=int, default=256, help='Image Size')
parser.add_argument('--batch_size', type=int, default=1, help='Size of the minibatch')
parser.add_argument('--gan_type', type=str, default='BicycleGAN', help='Type of GAN')
parser.add_argument('--dataset', type=str, default='cityscapes', help='The name of dataset')
parser.add_argument('--epoch', type=int, default=20, help='The number of epochs to run')
parser.add_argument('--checkpoint_dir', type=str, default='checkpoint',help='Directory name to save the checkpoints')
parser.add_argument('--result_dir', type=str, default='results', help='Directory name to save the generated images')
parser.add_argument('--log_dir', type=str, default='logs', help='Directory name to save training logs')
return check_args(parser.parse_args())
"""checking arguments"""
def check_args(args):
# --checkpoint_dir
check_folder(args.checkpoint_dir)
# --result_dir
check_folder(args.result_dir)
# --result_dir
check_folder(args.log_dir)
# --epoch
assert args.epoch > 0, 'Totral number of epochs must be greater than zero'
# --batch_size
assert args.batch_size > 0, 'Batch size must be greater than zero'
# --z_dim
assert args.Z_dim > 0, 'Size of the noise vector must be greater than zero'
return args
"""main function"""
def main():
# parse arguments
args = parse_args()
if args is None:
exit()
# Open New Tensorflow Session
model = BicycleGAN
with tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) as sess:
# Declare instance for GAN
gan = None
if args.gan_type == model.model_name:
gan = model(sess,
epoch=args.epoch,
batch_size=args.batch_size,
Z_dim=args.Z_dim,
image_size=args.image_size,
dataset_name=args.dataset,
checkpoint_dir=args.checkpoint_dir,
result_dir=args.result_dir,
log_dir=args.log_dir)
if gan is None:
raise Exception("[!] There is no option for " + args.gan_type)
# Build Tesnorflow Graph
gan.build_model()
# show network architecture
# show_all_variables()
# Launch the graph in a session
gan.train()
print(" [*] Training finished!")
# visualize learned generator
gan.test()
print(" [*] Testing finished!")
if __name__ == '__main__':
main()