Beispiel #1
0
        if 'test' in cfg.data:
            cfg.data.test.data_dir = args.data_dir

    # init distributed env first, since logger depends on the dist info.
    if args.launcher == 'none':
        distributed = False
    else:
        distributed = True
        init_dist(args.launcher, **cfg.dist_params)

    # init logger before other steps
    logger = get_root_logger(log_level=cfg.log_level)

    # set random seeds
    if args.seed is not None:
        logger.info('Set random seed to {}'.format(args.seed))
        set_random_seed(args.seed)

    model = build_model(cfg.model)
    fp16_cfg = cfg.get('fp16', None)
    if fp16_cfg is not None:
        wrap_fp16_model(model)
    test_dataset = build_dataset(cfg.data.val)

    test_network(model,
                 test_dataset,
                 cfg=cfg,
                 distributed=distributed,
                 logger=logger,
                 progress=args.progress)
Beispiel #2
0
    else:
        load_from = args.checkpoint

    if load_from is None:
        chkpt_list = [load_from]
    elif os.path.isdir(load_from):
        chkpt_list = [
            os.path.join(load_from, fn) for fn in os.listdir(load_from)
            if fn.endswith('.pth') and not fn.startswith('latest')
        ]
    elif os.path.isfile(load_from):
        chkpt_list = [load_from]
    else:
        raise FileNotFoundError("Cannot find {}".format(args.checkpoint))

    cfg.work_dir = os.path.join(cfg.work_dir, 'clip_retrieval')

    # build a dataloader
    model = build_model(cfg.model,
                        default_args=dict(train_cfg=None, test_cfg=None))
    train_dataset = build_dataset(cfg.data.train)
    test_dataset = build_dataset(cfg.data.test)

    results = test_clip_retrieval(model,
                                  train_dataset,
                                  test_dataset,
                                  cfg,
                                  chkpt_list,
                                  logger=logger,
                                  progress=args.progress)
Beispiel #3
0
        init_dist(args.launcher, **cfg.dist_params)
    # create work_dir
    mmcv.mkdir_or_exist(os.path.abspath(cfg.work_dir))
    # dump config
    cfg.dump(os.path.join(cfg.work_dir, os.path.basename(args.cfg)))

    # init logger before other steps
    logger = get_root_logger(log_level=cfg.log_level)
    env_info_dict = collect_env()
    env_info = '\n'.join([f'{k}: {v}' for k, v in env_info_dict.items()])
    dash_line = '-' * 60 + '\n'
    logger.info('Environment info:\n' + dash_line + env_info + '\n' +
                dash_line)
    logger.info(f'Distributed training: {distributed}')
    logger.info(f'Config:\n{cfg.pretty_text}')

    # set random seeds
    if args.seed is not None:
        logger.info('Set random seed to {}'.format(args.seed))
        set_random_seed(args.seed)

    model = build_model(cfg.model)
    train_dataset = build_dataset(cfg.data.train)

    train_network(model,
                  train_dataset,
                  cfg,
                  distributed=distributed,
                  validate=args.validate,
                  logger=logger)
Beispiel #4
0
    args = parse_args()
    cfg = Config.fromfile(args.cfg)
    # update configs according to CLI args
    cfg.gpus = args.gpus
    cfg.data.videos_per_gpu = args.batchsize
    if 'pretrained' in cfg['model']['backbone']:
        cfg['model']['backbone']['pretrained'] = None
    if args.work_dir is not None:
        cfg.work_dir = args.work_dir
    if args.data_dir is not None:
        if 'test' in cfg.data:
            cfg.data.test.root_dir = args.data_dir
    if args.checkpoint is not None:
        chkpt_list = [args.checkpoint]
    else:
        chkpt_list = [os.path.join(cfg.work_dir, fn)
                      for fn in os.listdir(cfg.work_dir) if fn.endswith('.pth')]

    # init logger before other steps
    logger = get_root_logger(log_level=cfg.log_level)

    # build a dataloader
    model = build_model(cfg.model, default_args=dict(train_cfg=cfg.train_cfg, test_cfg=cfg.test_cfg))
    dataset = build_dataset(cfg.data.test)
    results = test_recognizer(model,
                              dataset,
                              cfg,
                              chkpt_list,
                              logger=logger,
                              progress=args.progress)