三个程序的入口地址: main函数()
程序运行的命令是: CUDA_VISIBLE_DEVICES=0 python main --gan_type F_GAN
import os
from CGAN import CGAN
from CVAE import CVAE
from F_GAN import F_GAN
from utils import check_folder
import tensorflow as tf
import argparse
"""parsing and configuration"""
def parse_args():
desc = "Tensorflow implementation of GAN collections"
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('--gan_type', type=str, default='F_GAN',
choices=['CGAN', 'CVAE', 'F_GAN'],
help='The type of GAN', required=True)
parser.add_argument('--dataset', type=str, default='fashion-mnist', choices=['mnist', 'fashion-mnist', 'celebA'],
help='The name of dataset')
parser.add_argument('--epoch', type=int, default=500, help='The number of epochs to run')
parser.add_argument('--batch_size', type=int, default=64, help='The size of batch')
parser.add_argument('--z_dim', type=int, default=100, help='Dimension of noise vector')
parser.add_argument('--result_dir', type=str, default='results',
help='Directory name to save the generated images')
return check_args(parser.parse_args())
def check_args(args):
# if not exited then create the result file
check_folder(args.result_dir)
return args
"""main"""
def main():
# parse arguments
args = parse_args()
if args is None:
exit()
models = ['CGAN', 'CVAE', 'F_GAN']
with tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) as sess:
if args.gan_type in models:
gan = model(sess,
epoch=args.epoch,
batch_size=args.batch_size,
z_dim=args.z_dim,
dataset_name=args.dataset,
result_dir=args.result_dir,)
gan.build_model()
gan.train()
if __name__ == '__main__':
main()