示例#1
0
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

    file_name = time.strftime("%Y_%m_%d_%H%M", time.localtime())
    if FLAGS.unreg:
        file_name += "_unreg_dcgan"
    else:
        file_name += "_regularized_dcgan_" + str(FLAGS.gamma) + "gamma"
    if FLAGS.annealing:
        file_name += "_annealing_" + str(FLAGS.decay_factor) + "decayfactor"
    if FLAGS.rmsprop:
        file_name += "_rmsprop"
    else:
        file_name += "_adam"
    file_name += "_" + str(FLAGS.disc_update_steps) + "dsteps"
    file_name += "_" + str(FLAGS.disc_learning_rate) + "dlnr"
    file_name += "_" + str(FLAGS.gen_learning_rate) + "glnr"
    file_name += "_" + str(FLAGS.epochs) + "epochs"
    file_name += "_" + str(FLAGS.dataset)

    log_dir = os.path.abspath(os.path.join(FLAGS.root_dir, file_name))

    if not os.path.exists(log_dir):
        os.makedirs(log_dir)

    pp.pprint(flags.FLAGS.__flags)

    with tf.Session() as sess:

        dcgan = DCGAN(sess, log_dir, FLAGS)

        show_all_variables()

        if FLAGS.checkpoint_dir is not "None":
            if not dcgan.load_ckpt()[0]:
                raise Exception("[!] ERROR: provide valid checkpoint_dir")
        else:
            starttime = time.time()

            dcgan.train(FLAGS)

            endtime = time.time()
            print('Total Train Time: {:.2f}'.format(endtime - starttime))

        dcgan.generate(FLAGS, option=1)

    file = open(os.path.join(log_dir, "flags.json"), 'a')
    json.dump(vars(FLAGS), file)
    file.close()