Exemplo n.º 1
0
def parse_args():
    parser = argparse.ArgumentParser(description='Train the SZO nowcasting model')
    parser.add_argument('--batch_size', dest='batch_size', help="batchsize of the training process",
                        default=None, type=int)
    parser.add_argument('--cfg', dest='cfg_file', help='Optional configuration file', default=None, type=str)
    parser.add_argument('--save_dir', help='The saving directory', required=True, type=str)
    parser.add_argument('--ctx', dest='ctx', help='Running Context. E.g `--ctx gpu` or `--ctx gpu0,gpu1` or `--ctx cpu`',
                        type=str, default='gpu')
    parser.add_argument('--resume', dest='resume', action='store_true', default=False)
    parser.add_argument('--resume_param_only', dest='resume_param_only', action='store_true', default=False)
    parser.add_argument('--lr', dest='lr', help='learning rate', default=None, type=float)
    parser.add_argument('--wd', dest='wd', help='weight decay', default=None, type=float)
    parser.add_argument('--grad_clip', dest='grad_clip', help='gradient clipping threshold',
                        default=None, type=float)
    args = parser.parse_args()
    args.ctx = parse_ctx(args.ctx)
    if args.cfg_file is not None:
        cfg_from_file(args.cfg_file, target=cfg.MODEL)
    if args.batch_size is not None:
        cfg.MODEL.TRAIN.BATCH_SIZE = args.batch_size
    if args.lr is not None:
        cfg.MODEL.TRAIN.LR = args.lr
    if args.wd is not None:
        cfg.MODEL.TRAIN.WD = args.wd
    if args.grad_clip is not None:
        cfg.MODEL.TRAIN.GRAD_CLIP = args.grad_clip
    if args.wd is not None:
        cfg.MODEL.TRAIN.WD = args.wd
    cfg.MODEL.SAVE_DIR = args.save_dir
    logging.info(args)
    return args
Exemplo n.º 2
0
def parse_args():
    parser = argparse.ArgumentParser(
        description='Train the Meteotn nowcasting model')
    parser.add_argument('--batch_size',
                        dest='batch_size',
                        help="batchsize of the training process",
                        default=None,
                        type=int)
    parser.add_argument('--cfg',
                        dest='cfg_file',
                        help='Configuration file',
                        required=True,
                        type=str)
    parser.add_argument('--save_dir',
                        help='The saving directory',
                        required=True,
                        type=str)
    parser.add_argument(
        '--data_dir',
        help=
        'The data directory with hdf_archives folder, hdf_metadata.csv and mask.png',
        required=True,
        type=str)
    parser.add_argument(
        '--data_csv',
        help=
        'alternate metadata CSV file (default: [data_dir]/hdf_metadata.csv)',
        default=None,
        type=str)
    parser.add_argument(
        '--date_start',
        help='Start date to filter the sequences (e.g. 2010-12-31)',
        default=None,
        type=lambda s: datetime.strptime(s, '%Y-%m-%d'))
    parser.add_argument(
        '--date_end',
        help='End date to filter the sequences (e.g. 2016-12-31)',
        default=None,
        type=lambda s: datetime.strptime(s, '%Y-%m-%d'))
    parser.add_argument(
        '--ctx',
        default='cpu',
        help='Running Context. (default: %(default)s): `--ctx gpu` '
        'or `--ctx gpu0,gpu1` for GPU(s). `--ctx cpu` for CPU')
    parser.add_argument('--threshold',
                        dest='threshold',
                        help='rainfall filter threshold (default 0.28)',
                        default=None,
                        type=float)
    args = parser.parse_args()
    args.ctx = parse_ctx(args.ctx)
    if args.cfg_file is not None:
        cfg_from_file(args.cfg_file, target=cfg.MODEL)
    if args.batch_size is not None:
        cfg.MODEL.TRAIN.BATCH_SIZE = args.batch_size
    if args.threshold is not None:
        cfg.HKO.ITERATOR.FILTER_RAINFALL_THRESHOLD = float(args.threshold)
    cfg.MODEL.SAVE_DIR = args.save_dir
    logging.info(args)
    return args
Exemplo n.º 3
0
    def __init__(self, model_dir: str, model_iter: int, model_cfg: str,
                 batch_size: int, ctx: list):
        self.batch_size = batch_size
        self.ctx = ctx
        self.model_dir = model_dir
        self.model_iter = model_iter
        cfg_from_file(model_cfg, target=cfg.MODEL)
        assert cfg.MODEL.FRAME_STACK == 1 and cfg.MODEL.FRAME_SKIP == 1
        assert len(self.model_dir) > 0

        hko_factory = RadarNowcastingFactory(batch_size=self.batch_size,
                                             in_seq_len=cfg.MODEL.IN_LEN,
                                             out_seq_len=cfg.MODEL.OUT_LEN)
        self.encoder_net, self.forecaster_net, t_loss_net = encoder_forecaster_build_networks(
            factory=hko_factory, context=self.ctx, for_finetune=True)
        self.encoder_net.summary()
        self.forecaster_net.summary()
        t_loss_net.summary()
        load_encoder_forecaster_params(load_dir=self.model_dir,
                                       load_iter=self.model_iter,
                                       encoder_net=self.encoder_net,
                                       forecaster_net=self.forecaster_net)

        self.states = EncoderForecasterStates(factory=hko_factory,
                                              ctx=self.ctx[0])
Exemplo n.º 4
0
def parse_mode_args(args):
    args.ctx = parse_ctx(args.ctx)
    if args.cfg_file:
        cfg_from_file(args.cfg_file, target=cfg)
    # Parameter loading
    if args.test or cfg.MODEL.TESTING:
        cfg.MODEL.TESTING = True
        args.resume = True
    if args.resume:
        cfg.MODEL.RESUME = True
    if args.load_dir:
        cfg.MODEL.LOAD_DIR = args.load_dir
    if args.load_iter:
        cfg.MODEL.LOAD_ITER = args.load_iter
Exemplo n.º 5
0
def parse_args():
    parser = argparse.ArgumentParser(
        description='Test the MovingMNIST++ dataset')
    parser.add_argument('--batch_size',
                        dest='batch_size',
                        help="batchsize of the testing process",
                        default=None,
                        type=int)
    parser.add_argument('--cfg',
                        dest='cfg_file',
                        help='Testing configuration file',
                        default=None,
                        type=str)
    parser.add_argument('--load_dir',
                        help='The loading directory',
                        default=None,
                        type=str)
    parser.add_argument('--load_iter',
                        help='The loading iterator',
                        default=None,
                        type=int)
    parser.add_argument('--save_dir',
                        help='The saving directory',
                        required=True,
                        type=str)
    parser.add_argument(
        '--ctx',
        dest='ctx',
        help=
        'Running Context. E.g `--ctx gpu` or `--ctx gpu0,gpu1` or `--ctx cpu`',
        type=str,
        default='gpu')
    args = parser.parse_args()
    args.ctx = parse_ctx(args.ctx)
    if args.cfg_file is not None:
        cfg_from_file(args.cfg_file, target=cfg)
    if args.load_dir is not None:
        cfg.MODEL.LOAD_DIR = args.load_dir
    if args.load_iter is not None:
        cfg.MODEL.LOAD_ITER = args.load_iter
    cfg.MODEL.SAVE_DIR = args.save_dir
    logging.info(args)
    return args
Exemplo n.º 6
0
def parse_args():
    parser = argparse.ArgumentParser(description='Test the HKO nowcasting model')
    parser.add_argument('--cfg', dest='cfg_file', help='Optional configuration file', type=str)
    parser.add_argument('--load_dir', help='The directory to load the model', default=None, type=str)
    parser.add_argument('--load_iter', help='The iterator to load', default=-1, type=int)
    parser.add_argument('--save_dir', help='The saving directory', required=True, type=str)
    parser.add_argument('--ctx', dest='ctx', help='Running Context. E.g `--ctx gpu` or `--ctx gpu0,gpu1` or `--ctx cpu`',
                        type=str, default='gpu')
    parser.add_argument('--finetune', dest='finetune', help='Whether to do online finetuning',
                        default=None, type=int)
    parser.add_argument('--finetune_min_mse', dest='finetune_min_mse', help='Minimum error for finetuning',
                        default=None, type=float)
    parser.add_argument('--mode', dest='mode', help='Whether to used fixed setting or online setting',
                        required=True, type=str)
    parser.add_argument('--dataset', dest='dataset', help='Whether to used the test set or the validation set',
                        default="test", type=str)
    parser.add_argument('--lr', dest='lr', help='learning rate', default=None, type=float)
    parser.add_argument('--wd', dest='wd', help='weight decay', default=None, type=float)
    parser.add_argument('--grad_clip', dest='grad_clip', help='gradient clipping threshold',
                        default=None, type=float)
    args = parser.parse_args()
    args.ctx = parse_ctx(args.ctx)
    if args.cfg_file is not None:
        cfg_from_file(args.cfg_file, target=cfg.MODEL)
    if args.load_dir is not None:
        cfg.MODEL.LOAD_DIR = args.load_dir
    if args.load_iter != -1:
        cfg.MODEL.LOAD_ITER = args.load_iter
    if args.lr is not None:
        cfg.MODEL.TEST.ONLINE.LR = args.lr
    if args.wd is not None:
        cfg.MODEL.TEST.ONLINE.WD = args.wd
    if args.grad_clip is not None:
        cfg.MODEL.TEST.ONLINE.GRAD_CLIP = args.grad_clip
    if args.mode is not None:
        cfg.MODEL.TEST.MODE = args.mode
    if args.finetune is not None:
        cfg.MODEL.TEST.FINETUNE = (args.finetune != 0)
    if args.finetune_min_mse is not None:
        cfg.MODEL.TEST.ONLINE.FINETUNE_MIN_MSE = args.finetune_min_mse
    cfg.MODEL.SAVE_DIR = args.save_dir
    logging.info(args)
    return args
Exemplo n.º 7
0
def parse_args():
    parser = argparse.ArgumentParser(
        description="Test the SST nowcasting model")
    parser.add_argument("--cfg",
                        dest="cfg_file",
                        help="Optional configuration file",
                        type=str)
    parser.add_argument("--load_dir",
                        help="The directory to load the model",
                        default=None,
                        type=str)
    parser.add_argument("--load_iter",
                        help="The iterator to load",
                        default=-1,
                        type=int)
    parser.add_argument("--save_dir",
                        help="The saving directory",
                        required=True,
                        type=str)
    parser.add_argument(
        "--ctx",
        dest="ctx",
        help=
        "Running Context. E.g `--ctx gpu` or `--ctx gpu0,gpu1` or `--ctx cpu`",
        type=str,
        default="gpu",
    )
    parser.add_argument(
        "--finetune",
        dest="finetune",
        help="Whether to do online finetuning",
        default=None,
        type=int,
    )
    parser.add_argument(
        "--finetune_min_mse",
        dest="finetune_min_mse",
        help="Minimum error for finetuning",
        default=None,
        type=float,
    )
    parser.add_argument(
        "--mode",
        dest="mode",
        help="Whether to used fixed setting or online setting",
        required=True,
        type=str,
    )
    parser.add_argument(
        "--dataset",
        dest="dataset",
        help="Whether to used the test set or the validation set",
        default="test",
        type=str,
    )
    parser.add_argument("--lr",
                        dest="lr",
                        help="learning rate",
                        default=None,
                        type=float)
    parser.add_argument("--wd",
                        dest="wd",
                        help="weight decay",
                        default=None,
                        type=float)
    parser.add_argument(
        "--grad_clip",
        dest="grad_clip",
        help="gradient clipping threshold",
        default=None,
        type=float,
    )
    args = parser.parse_args()
    args.ctx = parse_ctx(args.ctx)
    if args.cfg_file is not None:
        cfg_from_file(args.cfg_file, target=cfg.MODEL)
    if args.load_dir is not None:
        cfg.MODEL.LOAD_DIR = args.load_dir
    if args.load_iter != -1:
        cfg.MODEL.LOAD_ITER = args.load_iter
    if args.lr is not None:
        cfg.MODEL.TEST.ONLINE.LR = args.lr
    if args.wd is not None:
        cfg.MODEL.TEST.ONLINE.WD = args.wd
    if args.grad_clip is not None:
        cfg.MODEL.TEST.ONLINE.GRAD_CLIP = args.grad_clip
    if args.mode is not None:
        cfg.MODEL.TEST.MODE = args.mode
    if args.finetune is not None:
        cfg.MODEL.TEST.FINETUNE = args.finetune != 0
    if args.finetune_min_mse is not None:
        cfg.MODEL.TEST.ONLINE.FINETUNE_MIN_MSE = args.finetune_min_mse
    cfg.MODEL.SAVE_DIR = args.save_dir
    logging.info(args)
    return args
Exemplo n.º 8
0
def parse_args():
    parser = argparse.ArgumentParser(
        description="Train the SST nowcasting model")
    parser.add_argument(
        "--batch_size",
        dest="batch_size",
        help="batchsize of the training process",
        default=None,
        type=int,
    )
    parser.add_argument(
        "--cfg",
        dest="cfg_file",
        help="Optional configuration file",
        default=None,
        type=str,
    )
    parser.add_argument("--save_dir",
                        help="The saving directory",
                        required=True,
                        type=str)
    parser.add_argument(
        "--ctx",
        dest="ctx",
        help=
        "Running Context. E.g `--ctx gpu` or `--ctx gpu0,gpu1` or `--ctx cpu`",
        type=str,
        default="gpu",
    )
    parser.add_argument("--lr",
                        dest="lr",
                        help="learning rate",
                        default=None,
                        type=float)
    parser.add_argument("--wd",
                        dest="wd",
                        help="weight decay",
                        default=None,
                        type=float)
    parser.add_argument(
        "--grad_clip",
        dest="grad_clip",
        help="gradient clipping threshold",
        default=None,
        type=float,
    )
    args = parser.parse_args()
    args.ctx = parse_ctx(args.ctx)
    if args.cfg_file is not None:
        cfg_from_file(args.cfg_file, target=cfg.MODEL)
    if args.batch_size is not None:
        cfg.MODEL.TRAIN.BATCH_SIZE = args.batch_size
    if args.lr is not None:
        cfg.MODEL.TRAIN.LR = args.lr
    if args.wd is not None:
        cfg.MODEL.TRAIN.WD = args.wd
    if args.grad_clip is not None:
        cfg.MODEL.TRAIN.GRAD_CLIP = args.grad_clip
    if args.wd is not None:
        cfg.MODEL.TRAIN.WD = args.wd
    cfg.MODEL.SAVE_DIR = args.save_dir
    logging.info(args)
    return args