def get_args_parser(): parser = ArgumentParser(prog='baseline tracker') parser.add_argument('--checkpoint', type=str, default="", help="checkpoint model for inference") parser.add_argument('--search_size', type=int, default=255, help="size of the template image") postprocess_parser = ArgumentParser(prog='post process') postprocess_parser.add_argument('--score_threshold', type=float, default=0.05, help='the lower score threshold to identify a target (score_target > threshold) ') postprocess_parser.add_argument('--window_steps', type=int, default=3, help='the pyramid factor to gradually reduce the widow effect') postprocess_parser.add_argument('--window_factor', type=float, default=0.4, help='the factor of the hanning window for heatmap post process') postprocess_parser.add_argument('--tracking_size_penalty_k', type=float, default=0.04, help='the factor to penalize the change of size') postprocess_parser.add_argument('--tracking_size_lpf', type=float, default=0.8, help='the factor of the lpf for size tracking') postprocess_parser.add_argument('--multi_frame', type=bool, default=False, help="(Deprecated) use multi frame for encoder (template images)") parser.add_argument('--postprocess', action=ActionParser(parser=postprocess_parser)) # TrTr parser.add_argument('--model', action=ActionParser(parser=trtr_args_parser())) return parser
def get_config_parser(): parser = ArgumentParser() parser.add_argument( "--producer", action=ActionParser(parser=Producer.get_config_parser())) parser.add_argument( "--transformer", action=ActionParser(parser=Transformer.get_config_parser())) return parser
def get_args_parser(): parser = ArgumentParser(prog='trtr') parser.add_argument('--device', default='cuda', help='device to use for inference') # Modle Parameters parser.add_argument( '--transformer_mask', type=bool, default=False, help="whether masking padding area to zero in attention mechanism") # Loss parser.add_argument( '--aux_loss', type=bool, default=True, help="whether use auxiliary decoding losses (loss at each layer)") parser.add_argument('--loss_mask', type=bool, default=False, help="whether use mask for heamtmap loss") parser.add_argument( '--reg_loss_coef', type=float, default=1, help="weight (coeffficient) about bbox offset reggresion loss") parser.add_argument( '--wh_loss_coef', type=float, default=1, help="weight (coeffficient) about bbox width/height loss") # Backbone parser.add_argument('--backbone', action=ActionParser(parser=backbone_args_parser())) # Position Embedding parser.add_argument( '--position_embedding', type=str, default='sine', choices=('sine', 'learned'), help="Type of positional embedding to use on top of the image features" ) # Transformer parser.add_argument('--transformer', action=ActionParser(parser=transformer_args_parser())) return parser
def test_ActionParser_nested_dash_names(self): p1 = ArgumentParser(error_handler=None) p1.add_argument('--op1-like') p2 = ArgumentParser(error_handler=None) p2.add_argument('--op2-like', action=ActionParser(parser=p1)) self.assertEqual( p2.parse_args(['--op2-like.op1-like=a']).op2_like.op1_like, 'a') p3 = ArgumentParser(error_handler=None) p3.add_argument('--op3', action=ActionParser(parser=p2)) self.assertEqual( p3.parse_args(['--op3.op2-like.op1-like=b']).op3.op2_like.op1_like, 'b')
def test_ActionParser_required(self): p1 = ArgumentParser() p1.add_argument('--op1', required=True) p2 = ArgumentParser(error_handler=None) p2.add_argument('--op2', action=ActionParser(parser=p1)) p2.parse_args(['--op2.op1=1']) self.assertRaises(ParserError, lambda: p2.parse_args([]))
def test_ActionParser_conflict(self): parser_lv2 = ArgumentParser() parser_lv2.add_argument('--op') parser = ArgumentParser(error_handler=None) parser.add_argument('--inner.op') self.assertRaises( ValueError, lambda: parser.add_argument('--inner', action=ActionParser(parser_lv2)))
def test_default_help_formatter(self): parser = ArgumentParser(prog='app', default_env=True) parser.add_argument('--cfg', help='Config in yaml/json.', action=ActionConfigFile) parser.add_argument('--v1', help='Option v1.', default='v1', required=True) parser.add_argument('--v2', type=int, help='Option v2.') parser.add_argument('--g1.v3', help='Option v3.', default='v3') parser.add_argument('--v4', choices=['A', 'B'], help='Option v4.') parser2 = ArgumentParser() parser2.add_argument('--v4') parser.add_argument('--g2', action=ActionParser(parser=parser2)) parser.add_argument('--v5', action=ActionYesNo, default=True, help='Option v5.') out = StringIO() parser.print_help(out) outval = out.getvalue() self.assertIn('--print_config', outval) self.assertIn('--cfg CFG', outval) self.assertIn('APP_CFG', outval) self.assertIn('Config in yaml/json.', outval) self.assertIn('--v1 V1', outval) self.assertIn('APP_V1', outval) self.assertIn('Option v1. (required, default: v1)', outval) self.assertIn('--v2 V2', outval) self.assertIn('APP_V2', outval) self.assertIn('Option v2. (type: int, default: null)', outval) self.assertIn('--g1.v3 V3', outval) self.assertIn('APP_G1__V3', outval) self.assertIn('Option v3. (default: v3)', outval) self.assertIn('--v4 {A,B}', outval) self.assertIn('APP_V4', outval) self.assertIn('Option v4. (default: null)', outval) self.assertIn('--g2.v4 V4', outval) self.assertIn('APP_G2__V4', outval) self.assertIn('--v5, --no_v5', outval) self.assertIn('APP_V5', outval) self.assertIn('Option v5. (type: bool, default: True)', outval)
def test_ActionParser_action_groups(self): def get_parser_lv2(): parser_lv2 = ArgumentParser(description='parser_lv2 description') parser_lv2.add_argument('--a1', help='lv2_a1 help') group_lv2 = parser_lv2.add_argument_group( description='group_lv2 description') group_lv2.add_argument('--a2', help='lv2_a2 help') return parser_lv2 parser_lv2 = get_parser_lv2() parser = ArgumentParser() parser.add_argument('--lv2', action=ActionParser(parser_lv2)) out = StringIO() parser.print_help(out) outval = out.getvalue() self.assertIn('parser_lv2 description', outval) self.assertIn('group_lv2 description', outval) self.assertIn('--lv2.a1 A1', outval) parser_lv2 = get_parser_lv2() parser = ArgumentParser() parser.add_argument( '--lv2', title='ActionParser title', description='ActionParser description', action=ActionParser(parser_lv2), ) out = StringIO() parser.print_help(out) outval = out.getvalue() self.assertIn('ActionParser title', outval) self.assertIn('ActionParser description', outval)
def get_args_parser(): parser = ArgumentParser(prog='benchmark dataset inference') # tracking parser.add_argument('--use_baseline_tracker', action='store_true', help='whether use baseline(offline) tracker') parser.add_argument('--external_tracker', type=str, default='', choices=('', 'atom', 'dimp', 'prdimp'), help='if not empty, the external tracker will be used') parser.add_argument('--dataset_path', type=str, default='', help='path of datasets') parser.add_argument('--dataset', type=str, default='VOT2018', choices=('VOT2018', 'VOT2019', 'VOT2020', 'OTB', 'UAV', 'NFS', 'TrackingNet', 'LaSOT', 'GOT-10k'), help='the name of benchmark') parser.add_argument('--video', type=str, default='', help='eval one special video') parser.add_argument('--vis', action='store_true', help='whether visualzie result') parser.add_argument('--debug_vis', action='store_true', help='whether visualize the debug result') parser.add_argument('--model_name', type=str, default='trtr', help='the name of tracker') parser.add_argument('--result_path', type=str, default='results', help='the path to store trackingresults') parser.add_argument('--save_image_num_per_video', type=int, default=1, help='save the tracking result as image, please choose value larger than 1, or 0 for saving every frame') parser.add_argument('--repetition', default=1, type=int) parser.add_argument('--min_lost_rate_for_repeat', default=0.1, type=float) # change for different benchmark parser.add_argument('--tracker', action=ActionParser(parser=tracker_args_parser())) # yaml config file for all parameters parser.add_argument('--cfg_file', action=ActionConfigFile) return parser
def test_ActionParser_failures(self): parser_lv2 = ArgumentParser() parser_lv2.add_argument('--op') parser = ArgumentParser(error_handler=None) parser.add_argument('--inner', action=ActionParser(parser=parser_lv2)) self.assertRaises( Exception, lambda: parser.add_argument('--bad', action=ActionParser)) self.assertRaises( ValueError, lambda: parser.add_argument('--bad', action=ActionParser(parser=parser))) self.assertRaises( ValueError, lambda: parser.add_argument( '--bad', type=str, action=ActionParser(ArgumentParser()))) self.assertRaises( ValueError, lambda: parser.add_argument( '-b', '--bad', action=ActionParser(ArgumentParser()))) self.assertRaises(ParserError, lambda: parser.parse_args(['--inner=1'])) self.assertRaises(ValueError, lambda: ActionParser()) self.assertRaises(ValueError, lambda: ActionParser(parser=object))
def test_ActionParser(self): parser_lv3 = ArgumentParser(prog='lv3', default_env=False) parser_lv3.add_argument('--opt3', default='opt3_def') parser_lv2 = ArgumentParser(prog='lv2', default_env=False) parser_lv2.add_argument('--opt2', default='opt2_def') parser_lv2.add_argument('--inner3', action=ActionParser(parser=parser_lv3)) parser = ArgumentParser(prog='lv1', default_env=True, error_handler=None) parser.add_argument('--opt1', default='opt1_def') parser.add_argument('--inner2', action=ActionParser(parser=parser_lv2)) tmpdir = os.path.join(self.tmpdir, 'subdir') os.mkdir(tmpdir) yaml_main_file = os.path.join(tmpdir, 'main.yaml') yaml_inner2_file = os.path.join(tmpdir, 'inner2.yaml') yaml_inner3_file = os.path.join(tmpdir, 'inner3.yaml') with open(yaml_main_file, 'w') as output_file: output_file.write('opt1: opt1_yaml\ninner2: inner2.yaml\n') with open(yaml_inner2_file, 'w') as output_file: output_file.write('opt2: opt2_yaml\ninner3: inner3.yaml\n') with open(yaml_inner3_file, 'w') as output_file: output_file.write('opt3: opt3_yaml\n') ## Check defaults cfg = parser.get_defaults() self.assertEqual('opt1_def', cfg.opt1) self.assertEqual('opt2_def', cfg.inner2.opt2) self.assertEqual('opt3_def', cfg.inner2.inner3.opt3) ## Check ActionParser with parse_path expected = { 'opt1': 'opt1_yaml', 'inner2': { 'opt2': 'opt2_yaml', 'inner3': { 'opt3': 'opt3_yaml' } } } cfg = parser.parse_path(yaml_main_file, with_meta=False) self.assertEqual(expected, cfg.as_dict()) with open(yaml_main_file, 'w') as output_file: output_file.write(parser.dump(cfg)) cfg2 = parser.parse_path(yaml_main_file, with_meta=False) self.assertEqual(expected, cfg2.as_dict()) ## Check ActionParser inner environment variables self.assertEqual( 'opt2_env', parser.parse_env({ 'LV1_INNER2__OPT2': 'opt2_env' }).inner2.opt2) self.assertEqual( 'opt3_env', parser.parse_env({ 'LV1_INNER2__INNER3__OPT3': 'opt3_env' }).inner2.inner3.opt3) expected = { 'opt1': 'opt1_def', 'inner2': { 'opt2': 'opt2_def', 'inner3': { 'opt3': 'opt3_yaml' } } } cfg = parser.parse_env({'LV1_INNER2__INNER3': yaml_inner3_file}, with_meta=False) self.assertEqual(expected, cfg.as_dict()) parser.parse_env({'LV1_INNER2': yaml_inner2_file}) self.assertEqual( 'opt2_yaml', parser.parse_env({ 'LV1_INNER2': yaml_inner2_file }).inner2.opt2) ## Check ActionParser as argument path expected = { 'opt1': 'opt1_arg', 'inner2': { 'opt2': 'opt2_yaml', 'inner3': { 'opt3': 'opt3_yaml' } } } cfg = parser.parse_args( ['--opt1', 'opt1_arg', '--inner2', yaml_inner2_file], with_meta=False) self.assertEqual(expected, cfg.as_dict()) expected = { 'opt1': 'opt1_def', 'inner2': { 'opt2': 'opt2_arg', 'inner3': { 'opt3': 'opt3_yaml' } } } cfg = parser.parse_args( ['--inner2.opt2', 'opt2_arg', '--inner2.inner3', yaml_inner3_file], with_meta=False) self.assertEqual(expected, cfg.as_dict()) expected = { 'opt1': 'opt1_def', 'inner2': { 'opt2': 'opt2_def', 'inner3': { 'opt3': 'opt3_arg' } } } cfg = parser.parse_args([ '--inner2.inner3', yaml_inner3_file, '--inner2.inner3.opt3', 'opt3_arg' ], with_meta=False) self.assertEqual(expected, cfg.as_dict()) ## Check ActionParser as argument string expected = {'opt2': 'opt2_str', 'inner3': {'opt3': 'opt3_str'}} cfg = parser.parse_args(['--inner2', json.dumps(expected)], with_meta=False) self.assertEqual(expected, cfg.as_dict()['inner2']) expected = {'opt3': 'opt3_str'} cfg = parser.parse_args( ['--inner2.inner3', json.dumps(expected)], with_meta=False) self.assertEqual(expected, cfg.as_dict()['inner2']['inner3']) ## Check ActionParser with ActionConfigFile parser.add_argument('--cfg', action=ActionConfigFile) expected = { 'opt1': 'opt1_yaml', 'inner2': { 'opt2': 'opt2_yaml', 'inner3': { 'opt3': 'opt3_yaml' } } } cfg = parser.parse_args(['--cfg', yaml_main_file], with_meta=False) delattr(cfg, 'cfg') self.assertEqual(expected, cfg.as_dict()) cfg = parser.parse_args([ '--cfg', yaml_main_file, '--inner2.opt2', 'opt2_arg', '--inner2.inner3.opt3', 'opt3_arg' ]) self.assertEqual('opt2_arg', cfg.inner2.opt2) self.assertEqual('opt3_arg', cfg.inner2.inner3.opt3)
def get_args_parser(): parser = ArgumentParser('training') # training parser.add_argument('--device', default='cuda', help='device to use for inference') parser.add_argument('--output_dir', default='', help='path where to save, empty for no saving') parser.add_argument('--resume', default='', help='resume from checkpoint') parser.add_argument('--seed', default=42, type=int) parser.add_argument('--batch_size', default=2, type=int) parser.add_argument('--epochs', default=50, type=int) parser.add_argument('--lr', default=1e-4, type=float, help='learning rate for network excluding backbone') parser.add_argument( '--lr_backbone', default=1e-5, type=float, help='learning rate for backbone, 0 to freeze backbone') parser.add_argument('--weight_decay', default=1e-4, type=float) parser.add_argument('--lr_drop', default=6, type=int) parser.add_argument('--lr_gamma', default=0.5, type=float) parser.add_argument('--clip_max_norm', default=0.1, type=float, help='gradient clipping max norm') parser.add_argument('--start_epoch', default=0, type=int, metavar='N') # dataset parser.add_argument('--num_workers', default=2, type=int) # distributed training parameters parser.add_argument('--world_size', default=1, type=int, help='number of distributed processes') parser.add_argument('--dist_url', default='env://', help='url used to set up distributed training') parser.add_argument('--model_save_step', default=50, type=int, help='step to save model') parser.add_argument('--benchmark_test_step', default=1, type=int, help='step to test benchmark') parser.add_argument('--benchmark_start_epoch', default=0, type=int, help='epoch to start benchmark') # Dataset parser.add_argument('--dataset', action=ActionParser(parser=dataset_args_parser())) # TrTr parser.add_argument('--model', action=ActionParser(parser=trtr_args_parser())) # yaml config file for all parameters parser.add_argument('--cfg_file', action=ActionConfigFile) return parser