import argparse
import os
import numpy as np
# import A_spliteImage
# import A_evaluation
import tensorflow as tf

np.random.seed(123)

from model import pix2pix
dir_name = 'model_1'

os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = "0,1"
parser = argparse.ArgumentParser(description='')
parser.add_argument('--dataset_name', dest='dataset_name', default='ChangeDetection', help='name of the dataset')
parser.add_argument('--', dest='epoch', type=int, default=16000, help='# of epoch')
parser.add_argument('--batch_size', dest='batch_size', type=int, default=1, help='# images in batch')
parser.add_argument('--train_size', dest='train_size', type=int, default=1e8, help='# images used to train')
parser.add_argument('--load_size', dest='load_size', type=int, default=286, help='scale images to this size')
parser.add_argument('--fine_size_H', dest='fine_size_H', type=int, default=256, help='then crop to this size')

parser.add_argument('--fine_size_w', dest='fine_size_W', type=int, default=256, help='then crop to this size')

parser.add_argument('--ngf', dest='ngf', type=int, default=64, help='# of gen filters in first conv layer')
parser.add_argument('--ndf', dest='ndf', type=int, default=64, help='# of discri filters in first conv layer')
parser.add_argument('--input_nc', dest='input_nc', type=int, default=3, help='# of input image channels')
parser.add_argument('--output_nc', dest='output_nc', type=int, default=3, help='# of output image channels')
parser.add_argument('--niter', dest='niter', type=int, default=10, help='# of iter at starting learning rate')
# parser.add_argument('--lr', dest='lr', type=float, default=0.0001, help='initial learning rate for adam')
parser.add_argument('--beta1', dest='beta1', type=float, default=0.5, help='momentum term of adam')
parser.add_argument('--flip', dest='flip', type=bool, default=True, help='if flip the images for data argumentation')
parser.add_argument('--which_direction', dest='which_direction', default='AtoB', help='AtoB or BtoA')
parser.add_argument('--phase', dest='phase', default='demo', help='train, test')
parser.add_argument('--save_epoch_freq', dest='save_epoch_freq', type=int, default=50, help='save a model every save_epoch_freq epochs (does not overwrite previously saved models)')
parser.add_argument('--save_latest_freq', dest='save_latest_freq', type=int, default=600, help='save the latest model every latest_freq sgd iterations (overwrites the previous latest model)')
parser.add_argument('--print_freq', dest='print_freq', type=int, default=50, help='print the debug information every print_freq iterations')
parser.add_argument('--continue_train', dest='continue_train', type=bool, default=False, help='if continue training, load the latest model: 1: true, 0: false')
parser.add_argument('--serial_batches', dest='serial_batches', type=bool, default=False, help='f 1, takes images in order to make batches, otherwise takes them randomly')
parser.add_argument('--serial_batch_iter', dest='serial_batch_iter', type=bool, default=True, help='iter into serial image list')
parser.add_argument('--checkpoint_dir', dest='checkpoint_dir', default='./checkpoint/checkpoint{}'.format(dir_name), help='models are saved here')
parser.add_argument('--sample_dir', dest='sample_dir', default='./sample/sample{}'.format(dir_name), help='sample are saved here')
parser.add_argument('--test_dir', dest='test_dir', default='./test/test{}'.format(dir_name), help='test sample are saved here')
parser.add_argument('--log_dir', dest='log_dir', default='./logs_CD/log{}'.format(dir_name), help='test sample are saved here')
parser.add_argument('--L1_lambda', dest='L1_lambda', type=float, default=400.0, help='weight on L1 term in objective')

args = parser.parse_args()

def main(_):
    if not os.path.exists(args.checkpoint_dir):
        os.makedirs(args.checkpoint_dir)
    if not os.path.exists(args.sample_dir):
        os.makedirs(args.sample_dir)
    if not os.path.exists(args.test_dir):
        os.makedirs(args.test_dir)
    if not os.path.exists(args.log_dir):
        os.makedirs(args.log_dir)
    config = tf.ConfigProto(allow_soft_placement=True)
    with tf.Session(config=config) as sess:
        model = pix2pix(sess, image_size_H=args.fine_size_H,
                        image_size_W=args.fine_size_W,
                        batch_size=args.batch_size,
                        output_size_H=args.fine_size_H,
                        output_size_W=args.fine_size_W,
                        gf_dim=args.ngf,
                        df_dim=args.ndf,
                        dataset_name=args.dataset_name,
                        L1_lambda=args.L1_lambda,
                        checkpoint_dir=args.checkpoint_dir,
                        sample_dir=args.sample_dir)

        if args.phase == 'train':
            model.train(args)
        elif args.phase == 'test':
            model.test(args)
        else:
            model.demo(args)

if __name__ == '__main__':
    tf.app.run()

import argparse
import os
import numpy as np
# import A_spliteImage
# import A_evaluation
import tensorflow as tf

np.random.seed(123)

from model import pix2pix
dir_name = 'model_1'

os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = "0,1"
parser = argparse.ArgumentParser(description='')
parser.add_argument('--dataset_name', dest='dataset_name', default='ChangeDetection', help='name of the dataset')
parser.add_argument('--', dest='epoch', type=int, default=16000, help='# of epoch')
parser.add_argument('--batch_size', dest='batch_size', type=int, default=1, help='# images in batch')
parser.add_argument('--train_size', dest='train_size', type=int, default=1e8, help='# images used to train')
parser.add_argument('--load_size', dest='load_size', type=int, default=286, help='scale images to this size')
parser.add_argument('--fine_size_H', dest='fine_size_H', type=int, default=256, help='then crop to this size')

parser.add_argument('--fine_size_w', dest='fine_size_W', type=int, default=256, help='then crop to this size')

parser.add_argument('--ngf', dest='ngf', type=int, default=64, help='# of gen filters in first conv layer')
parser.add_argument('--ndf', dest='ndf', type=int, default=64, help='# of discri filters in first conv layer')
parser.add_argument('--input_nc', dest='input_nc', type=int, default=3, help='# of input image channels')
parser.add_argument('--output_nc', dest='output_nc', type=int, default=3, help='# of output image channels')
parser.add_argument('--niter', dest='niter', type=int, default=10, help='# of iter at starting learning rate')
# parser.add_argument('--lr', dest='lr', type=float, default=0.0001, help='initial learning rate for adam')
parser.add_argument('--beta1', dest='beta1', type=float, default=0.5, help='momentum term of adam')
parser.add_argument('--flip', dest='flip', type=bool, default=True, help='if flip the images for data argumentation')
parser.add_argument('--which_direction', dest='which_direction', default='AtoB', help='AtoB or BtoA')
parser.add_argument('--phase', dest='phase', default='demo', help='train, test')
parser.add_argument('--save_epoch_freq', dest='save_epoch_freq', type=int, default=50, help='save a model every save_epoch_freq epochs (does not overwrite previously saved models)')
parser.add_argument('--save_latest_freq', dest='save_latest_freq', type=int, default=600, help='save the latest model every latest_freq sgd iterations (overwrites the previous latest model)')
parser.add_argument('--print_freq', dest='print_freq', type=int, default=50, help='print the debug information every print_freq iterations')
parser.add_argument('--continue_train', dest='continue_train', type=bool, default=False, help='if continue training, load the latest model: 1: true, 0: false')
parser.add_argument('--serial_batches', dest='serial_batches', type=bool, default=False, help='f 1, takes images in order to make batches, otherwise takes them randomly')
parser.add_argument('--serial_batch_iter', dest='serial_batch_iter', type=bool, default=True, help='iter into serial image list')
parser.add_argument('--checkpoint_dir', dest='checkpoint_dir', default='./checkpoint/checkpoint{}'.format(dir_name), help='models are saved here')
parser.add_argument('--sample_dir', dest='sample_dir', default='./sample/sample{}'.format(dir_name), help='sample are saved here')
parser.add_argument('--test_dir', dest='test_dir', default='./test/test{}'.format(dir_name), help='test sample are saved here')
parser.add_argument('--log_dir', dest='log_dir', default='./logs_CD/log{}'.format(dir_name), help='test sample are saved here')
parser.add_argument('--L1_lambda', dest='L1_lambda', type=float, default=400.0, help='weight on L1 term in objective')

args = parser.parse_args()

def main(_):
    if not os.path.exists(args.checkpoint_dir):
        os.makedirs(args.checkpoint_dir)
    if not os.path.exists(args.sample_dir):
        os.makedirs(args.sample_dir)
    if not os.path.exists(args.test_dir):
        os.makedirs(args.test_dir)
    if not os.path.exists(args.log_dir):
        os.makedirs(args.log_dir)
    config = tf.ConfigProto(allow_soft_placement=True)
    with tf.Session(config=config) as sess:
        model = pix2pix(sess, image_size_H=args.fine_size_H,
                        image_size_W=args.fine_size_W,
                        batch_size=args.batch_size,
                        output_size_H=args.fine_size_H,
                        output_size_W=args.fine_size_W,
                        gf_dim=args.ngf,
                        df_dim=args.ndf,
                        dataset_name=args.dataset_name,
                        L1_lambda=args.L1_lambda,
                        checkpoint_dir=args.checkpoint_dir,
                        sample_dir=args.sample_dir)

        if args.phase == 'train':
            model.train(args)
        elif args.phase == 'test':
            model.test(args)
        else:
            model.demo(args)

if __name__ == '__main__':
    tf.app.run()

# import A_spliteImage # import A_evaluation # parser.add_argument('--lr', dest='lr', type=float, default=0.0001, help='initial learning rate for adam')