Пример #1
0
def main():
    # parse arguments
    args = parse_args()
    if args is None:
        exit()

    # open session
    with tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) as sess:
        gan = SAGAN(sess, args)

        # build graph
        gan.build_model()

        # show network architecture
        show_all_variables()

        if args.phase == 'train':
            # launch the graph in a session
            gan.train()

            # visualize learned generator
            gan.visualize_results(args.epoch - 1)

            print(" [*] Training finished!")

        if args.phase == 'test':
            gan.test()
            print(" [*] Test finished!")
Пример #2
0
def main():
    # parse arguments
    args = parse_args()
    if args is None:
      exit()

    # open session
    with tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) as sess:
        gan = SAGAN(sess, args)

        # build graph
        gan.build_model()

        # show network architecture
        show_all_variables()

        if args.phase == 'train' :
            # launch the graph in a session
            gan.train()

            # visualize learned generator
            gan.visualize_results(args.epoch - 1)

            print(" [*] Training finished!")

        if args.phase == 'test' :
            gan.test()
            print(" [*] Test finished!")
def main():
    args = parse_args()
    if args is None:
        exit()

    with tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) as sess:
        gan = SAGAN(sess, args)
        gan.build_model()
        show_all_variables()

        if args.phase == 'train':
            gan.train()
            gan.visualize_results(args.epoch - 1)

            print(" [*] Training finished!")

        if args.phase == 'test':
            gan.test()
            print(" [*] Test finished!")
Пример #4
0
def main():
    # parse arguments
    args = parse_args()
    if args is None:
        exit()

    # open session
    #tf.ConfigProto(allow_soft_placement=True):如果指定的设备不存在,允许tf自动分配设备。(我哪里来的GPU,sigh)
    with tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) as sess:
        #建立模型
        gan = SAGAN(sess, args)
        gan.build_model()
        show_all_variables()
        #两个调用命令:train&&test
        if args.phase == 'train':
            gan.train()
            gan.visualize_results(args.epoch - 1)
            print(" [*] Training finished")
        if args.phase == 'test':
            gan.test()
            print(" [*] Test finished")
Пример #5
0
def main():
    # parse arguments
    args = parse_args()
    if args is None:
        exit()

        # declare instance for GAN
    if args.gan_type == 'GAN':
        gan = GAN(args)
    elif args.gan_type == 'CGAN':
        gan = CGAN(args)
    elif args.gan_type == 'WGAN':
        gan = WGAN(args)
    elif args.gan_type == 'VAE':
        gan = VAE(args)
    elif args.gan_type == 'LSGAN':
        gan = LSGAN(args)
    elif args.gan_type == 'CVAE':
        gan = CVAE(args)
    elif args.gan_type == 'WGAN_GP':
        gan = WGAN_GP(args)
    elif args.gan_type == 'LSGAN':
        gan = LSGAN(args)
    elif args.gan_type == 'EBGAN':
        gan = EBGAN(args)
    elif args.gan_type == 'infoGAN':
        gan = infoGAN(args)
    elif args.gan_type == 'ACGAN':
        gan = ACGAN(args)
    elif args.gan_type == 'SAGAN':
        gan = SAGAN(args)
    else:
        raise Exception("[!] There is no option for " + args.gan_type)

        # launch the graph in a session
    gan.train()
    print(" [*] Training finished!")

    # visualize learned generator
    gan.visualize_results(args.epoch)
    print(" [*] Testing finished!")
Пример #6
0
def main():
    # parse arguments
    args = parse_args()
    if args is None:
        exit()

    # open session
    with tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) as sess:
        # declare instance for GAN
        if args.gan_type == 'GAN':
            gan = GAN(sess,
                      epoch=args.epoch,
                      batch_size=args.batch_size,
                      z_dim=args.z_dim,
                      dataset_name=args.dataset,
                      checkpoint_dir=args.checkpoint_dir,
                      result_dir=args.result_dir,
                      log_dir=args.log_dir)
        elif args.gan_type == 'CGAN':
            gan = CGAN(sess,
                       epoch=args.epoch,
                       batch_size=args.batch_size,
                       z_dim=args.z_dim,
                       dataset_name=args.dataset,
                       checkpoint_dir=args.checkpoint_dir,
                       result_dir=args.result_dir,
                       log_dir=args.log_dir)
        elif args.gan_type == 'ACGAN':
            gan = ACGAN(sess,
                        epoch=args.epoch,
                        batch_size=args.batch_size,
                        z_dim=args.z_dim,
                        dataset_name=args.dataset,
                        checkpoint_dir=args.checkpoint_dir,
                        result_dir=args.result_dir,
                        log_dir=args.log_dir)
        elif args.gan_type == 'infoGAN':
            gan = infoGAN(sess,
                          epoch=args.epoch,
                          batch_size=args.batch_size,
                          z_dim=args.z_dim,
                          dataset_name=args.dataset,
                          checkpoint_dir=args.checkpoint_dir,
                          result_dir=args.result_dir,
                          log_dir=args.log_dir)
        elif args.gan_type == 'EBGAN':
            gan = EBGAN(sess,
                        epoch=args.epoch,
                        batch_size=args.batch_size,
                        z_dim=args.z_dim,
                        dataset_name=args.dataset,
                        checkpoint_dir=args.checkpoint_dir,
                        result_dir=args.result_dir,
                        log_dir=args.log_dir)
        elif args.gan_type == 'WGAN':
            gan = WGAN(sess,
                       epoch=args.epoch,
                       batch_size=args.batch_size,
                       z_dim=args.z_dim,
                       dataset_name=args.dataset,
                       checkpoint_dir=args.checkpoint_dir,
                       result_dir=args.result_dir,
                       log_dir=args.log_dir)
        elif args.gan_type == 'WGAN_GP':
            gan = WGAN_GP(sess,
                          epoch=args.epoch,
                          batch_size=args.batch_size,
                          z_dim=args.z_dim,
                          dataset_name=args.dataset,
                          checkpoint_dir=args.checkpoint_dir,
                          result_dir=args.result_dir,
                          log_dir=args.log_dir)
        elif args.gan_type == 'DRAGAN':
            gan = DRAGAN(sess,
                         epoch=args.epoch,
                         batch_size=args.batch_size,
                         z_dim=args.z_dim,
                         dataset_name=args.dataset,
                         checkpoint_dir=args.checkpoint_dir,
                         result_dir=args.result_dir,
                         log_dir=args.log_dir)
        elif args.gan_type == 'LSGAN':
            gan = LSGAN(sess,
                        epoch=args.epoch,
                        batch_size=args.batch_size,
                        z_dim=args.z_dim,
                        dataset_name=args.dataset,
                        checkpoint_dir=args.checkpoint_dir,
                        result_dir=args.result_dir,
                        log_dir=args.log_dir)
        elif args.gan_type == 'BEGAN':
            gan = BEGAN(sess,
                        epoch=args.epoch,
                        batch_size=args.batch_size,
                        z_dim=args.z_dim,
                        dataset_name=args.dataset,
                        checkpoint_dir=args.checkpoint_dir,
                        result_dir=args.result_dir,
                        log_dir=args.log_dir)
        elif args.gan_type == 'VAE':
            gan = VAE(sess,
                      epoch=args.epoch,
                      batch_size=args.batch_size,
                      z_dim=args.z_dim,
                      dataset_name=args.dataset,
                      checkpoint_dir=args.checkpoint_dir,
                      result_dir=args.result_dir,
                      log_dir=args.log_dir)
        elif args.gan_type == 'CVAE':
            gan = CVAE(sess,
                       epoch=args.epoch,
                       batch_size=args.batch_size,
                       z_dim=args.z_dim,
                       dataset_name=args.dataset,
                       checkpoint_dir=args.checkpoint_dir,
                       result_dir=args.result_dir,
                       log_dir=args.log_dir)
        elif args.gan_type == 'VAE_GAN':
            gan = VAE_GAN(sess,
                          epoch=args.epoch,
                          batch_size=args.batch_size,
                          z_dim=args.z_dim,
                          dataset_name=args.dataset,
                          checkpoint_dir=args.checkpoint_dir,
                          result_dir=args.result_dir,
                          log_dir=args.log_dir)
        elif args.gan_type == 'SAGAN':
            gan = SAGAN(sess,
                        epoch=args.epoch,
                        batch_size=args.batch_size,
                        z_dim=args.z_dim,
                        dataset_name=args.dataset,
                        checkpoint_dir=args.checkpoint_dir,
                        result_dir=args.result_dir,
                        log_dir=args.log_dir)
        else:
            raise Exception("[!] There is no option for " + args.gan_type)

        # build 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.visualize_results(args.epoch - 1)
        print(" [*] Testing finished!")
Пример #7
0
# -*- coding: utf-8 -*-

from config import Config
from SAGAN import SAGAN

if __name__ == "__main__":
    config = Config()
    model = SAGAN(config)
    if config.RESUME_TRAIN:
        discriminator_path = "./result/181104_1905/weights/ramen_cam/discriminator245000.hdf5"
        generator_path = "./result/181104_1905/weights/ramen_cam/generator245000.hdf5"
        print("Training start at {} iterations".format(config.COUNTER))
        model.resume_train(discriminator_path, generator_path, config.COUNTER)
    else:
        print("Training start")
        model.train()