import argparse
import template

parser = argparse.ArgumentParser(description='EDSR and MDSR')

parser.add_argument('--debug', action='store_true',
                    help='Enables debug mode')
parser.add_argument('--debug_num', type=int, default=1, 
                    help='debugging session identifier')
parser.add_argument('--template', default='.',
                    help='You can set various templates in option.py')

# Hardware specifications
parser.add_argument('--n_threads', type=int, default=6,
                    help='number of threads for data loading')
parser.add_argument('--cpu', action='store_true',
                    help='use cpu only')
parser.add_argument('--n_GPUs', type=int, default=1,
                    help='number of GPUs')
parser.add_argument('--seed', type=int, default=1,
                    help='random seed')

# Data specifications
parser.add_argument('--dir_data', type=str, default='/datadrive',
                    help='dataset directory')
parser.add_argument('--dir_demo', type=str, default='../test',
                    help='demo image directory')
parser.add_argument('--data_train', type=str, default='DIV2K',
                    help='train dataset name')
parser.add_argument('--rrl_data', type=str, default='DIV2K',
                    help='dataset to load using RRL dataloader')
parser.add_argument('--data_test', type=str, default='DIV2K',
                    help='test dataset name')
parser.add_argument('--benchmark_noise', action='store_true',
                    help='use noisy benchmark sets')
parser.add_argument('--n_train', type=int, default=790,
                    help='number of training set')
parser.add_argument('--n_val', type=int, default=10,
                    help='number of validation set')
parser.add_argument('--offset_val', type=int, default=790,
                    help='validation index offest')
parser.add_argument('--ext', type=str, default='sep',
                    help='dataset file extension')
parser.add_argument('--scale', default='4',
                    help='super resolution scale')
parser.add_argument('--patch_size', type=int, default=96,
                    help='output patch size')
parser.add_argument('--patch_strategy', type=str, default='random',
                    help='strategy to pick out patches') 
parser.add_argument('--rgb_range', type=int, default=255,
                    help='maximum value of RGB')
parser.add_argument('--n_channel_in', type=int, default=3,
                    help='number of input channels for network')
parser.add_argument('--n_channel_out', type=int, default=3,
                    help='number of channels for network to output')
parser.add_argument('--interpolate', action='store_true',
                    help='bilinearly interpolate the LR image')
parser.add_argument('--noise', type=str, default='.',
                    help='Gaussian noise std.')
parser.add_argument('--chop', action='store_true',
                    help='enable memory-efficient forward')

# Model specifications
parser.add_argument('--model', default='EDSR',
                    help='model name')
parser.add_argument('--branch_num', type=int, default=1,
                    help='branch number for RRL')
parser.add_argument('--enable_branches', action='store_true',
                    help='incremental residual learning using sequential branches')
parser.add_argument('--n_branches', type=int, default=1,
                    help='number of sequential branches to train')
parser.add_argument('--train_jointly', action='store_true',
                    help='train branches jointly')
parser.add_argument('--branch_label', type=str, default='residual',
                    help='whether to predict HR (i.e b0+b1=gt) or \
                    residuals (i.e b1=gt-b0)')
parser.add_argument('--bilateral_residuals',action='store_true',
                    help='apply bilateral filter before generating residuals')
parser.add_argument('--down_feats', action='store_true',
                    help='take downsampled feature maps as input for next branch')
parser.add_argument('--half_feats', action='store_true', 
                    help='whether half the number of feats at each branch')
parser.add_argument('--half_resblocks', action='store_true',
                    help='whether half the number of resblocks at each branch')
parser.add_argument('--act', type=str, default='relu',
                    help='activation function')
parser.add_argument('--negative_slope', type=float, default=0.2,
                    help='negative slope parameter for PRelu')
parser.add_argument('--pre_train', type=str, default='.',
                    help='pre-trained model directory')
parser.add_argument('--master_branch_pretrain', type=str, default='.',
                    help='pre-trained master branch directory')
parser.add_argument('--n_resblocks', type=int, default=16,
                    help='number of residual blocks [EDSR]')
parser.add_argument('--n_denseblocks', type=int, default=16,
                    help='number of dense blocks in [DenseSkip]')                    
parser.add_argument('--n_layers', type=int, default=8,
                    help='number of layers inside a dense block [DenseSkip]')
parser.add_argument('--growth_rate', type=int, default=64,
                    help='Growth rate inside a dense block [DenseSkip]')
parser.add_argument('--n_feats', type=int, default=64,
                    help='number of feature maps')
parser.add_argument('--res_scale', type=float, default=1,
                    help='residual scaling')
parser.add_argument('--is_sub_mean', default=True,
                    help='subtract pixel mean from the input')
parser.add_argument('--precision', type=str, default='single',
                    choices=('single', 'half'),
                    help='FP precision for test (single | half)')

# Training specifications
parser.add_argument('--reset', action='store_true',
                    help='reset the training')
parser.add_argument('--test_every', type=int, default=1000,
                    help='do test per every N batches')
parser.add_argument('--epochs', type=int, default=300,
                    help='number of epochs to train')
parser.add_argument('--batch_size', type=int, default=16,
                    help='input batch size for training')
parser.add_argument('--split_batch', type=int, default=1,
                    help='split the batch into smaller chunks')
parser.add_argument('--self_ensemble', action='store_true',
                    help='use self-ensemble method for test')
parser.add_argument('--test_only', action='store_true',
                    help='set this option to test the model')
parser.add_argument('--gan_k', type=int, default=1,
                    help='k value for adversarial loss')

# Optimization specifications
parser.add_argument('--lr', type=float, default=1e-4,
                    help='learning rate')
parser.add_argument('--lr_decay', type=int, default=200,
                    help='learning rate decay per N epochs')
parser.add_argument('--decay_type', type=str, default='step',
                    help='learning rate decay type')
parser.add_argument('--gamma', type=float, default=0.5,
                    help='learning rate decay factor for step decay')
parser.add_argument('--optimizer', default='ADAM',
                    choices=('SGD', 'ADAM', 'RMSprop'),
                    help='optimizer to use (SGD | ADAM | RMSprop)')
parser.add_argument('--momentum', type=float, default=0.9,
                    help='SGD momentum')
parser.add_argument('--beta1', type=float, default=0.9,
                    help='ADAM beta1')
parser.add_argument('--beta2', type=float, default=0.999,
                    help='ADAM beta2')
parser.add_argument('--epsilon', type=float, default=1e-8,
                    help='ADAM epsilon for numerical stability')
parser.add_argument('--weight_decay', type=float, default=0,
                    help='weight decay')

# Loss specifications
parser.add_argument('--loss', type=str, default='1*L1',
                    help='loss function configuration')
parser.add_argument('--intensity_loss',action='store_true',
                    help='compute loss on intensity channel only')
parser.add_argument('--normalized_loss', action='store_true',
                    help='normalize images before computing loss')
parser.add_argument('--skip_threshold', type=float, default='1e6',
                    help='skipping batch that has large error')

# Log specifications
parser.add_argument('--save', type=str, default='test',
                    help='file name to save')
parser.add_argument('--load', type=str, default='.',
                    help='file name to load')
parser.add_argument('--resume', type=int, default=0,
                    help='resume from specific checkpoint')
parser.add_argument('--print_model', action='store_true',
                    help='print model')
parser.add_argument('--save_models', action='store_true',
                    help='save all intermediate models')
parser.add_argument('--print_every', type=int, default=100,
                    help='how many batches to wait before logging training status')
parser.add_argument('--save_results', action='store_true',
                    help='save output results')
parser.add_argument('--save_branches', action='store_true',
                    help='save outputs of each branches in IRL setup')
parser.add_argument('--save_residuals', action='store_true',
                    help='save residuals of output results')

args = parser.parse_args()
template.set_template(args)

args.scale = list(map(lambda x: int(x), args.scale.split('+')))

if args.epochs == 0:
    args.epochs = 1e8

for arg in vars(args):
    if vars(args)[arg] == 'True':
        vars(args)[arg] = True
    elif vars(args)[arg] == 'False':
        vars(args)[arg] = False

