コード例 #1
0
def setup_folder(args, cfg, phase='train'):
    # setup_folder config
    cfg_path = osp.join(cfg.GENERAL.CFG_ROOT, args.job_group,
                        args.cfg_name + '.yml')
    merge_cfg_from_file(cfg_path)
    cfg.GENERAL.JOB_GROUP = args.job_group
    # setup_folder weights folder
    snapshot_dir = osp.join(cfg.GENERAL.WEIGHTS_ROOT, cfg.GENERAL.JOB_GROUP,
                            args.cfg_name)
    warn = False if cfg.GENERAL.JOB_GROUP == 'tests' or 'debug' else True
    if phase == 'train':
        create_if_not_exist(
            [cfg.GENERAL.WEIGHTS_ROOT, cfg.GENERAL.HISTORY_ROOT], warn=warn)
        create_if_not_exist([
            osp.join(cfg.GENERAL.WEIGHTS_ROOT, cfg.GENERAL.JOB_GROUP),
            osp.join(cfg.GENERAL.HISTORY_ROOT, cfg.GENERAL.JOB_GROUP)
        ],
                            warn=warn)
        create_if_not_exist(snapshot_dir, warn=warn)

    # setup_folder logger
    # TODO image logger another writer
    log_dir = osp.join(
        osp.join(cfg.LOG.ROOT_DIR,
                 cfg.GENERAL.JOB_GROUP + '_' + args.cfg_name))
    tb_writer = TBWriter(
        log_dir, {
            'phase': phase,
            'show_pr_curve': cfg.LOG.SHOW_PR_CURVE,
            'show_test_image': cfg.LOG.SHOW_TEST_IMAGE
        })
    setup_cuda(cfg, args.cuda, args.devices)
    return tb_writer, cfg_path, snapshot_dir, log_dir
コード例 #2
0
def test_vis():
    from lib.utils.config import cfg
    # TODO make this an API
    dataset = VOCDetection(cfg.DATASET.DATASET_DIR, [('2007', 'test')],
                           SSDAugmentation((300, 500), dataset_mean),
                           VOCAnnotationTransform())
    from lib.utils.visualize_utils import TBWriter
    tb_writer = TBWriter(log_dir, {'vis_list': [3, 4, 5, 6, 8]})

    # import random
    # img_idx = random.randint(0, len(data_loader.dataset)-1)
    # image, target = dataset.pull_item(img_index, tb_writer)
    for img_idx in range(len(dataset)):
        if img_idx > 5:
            break
        tb_writer.cfg['steps'] = img_idx
        image, target, extra = dataset.pull_item(img_idx, tb_writer)
        print(image.shape)
コード例 #3
0
def test_vis():
    dataset = COCODetection(
        COCO_ROOT, ('valminusminival2014', ),
        SSDAugmentation((300, 300), dataset_mean, use_base=True),
        COCOAnnotationTransform())

    from lib.utils.visualize_utils import TBWriter
    tb_writer = TBWriter(log_dir, {'epoch': 50, 'vis_list': [3, 4, 5, 6, 8]})

    # import random
    # img_idx = random.randint(0, len(dataset)-1)
    # image, target = dataset.pull_item(img_idx, tb_writer)

    for img_idx in range(len(dataset)):
        if img_idx > 5:
            break
        tb_writer.cfg['steps'] = img_idx
        image, target = dataset.pull_item(img_idx, tb_writer)
        print(image.shape)
コード例 #4
0
def setup_folder(args, cfg, phase='train'):
    # setup_folder config
    time_stamp = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
    cfg_path = args.cfg_name  #osp.join(cfg.GENERAL.CFG_ROOT, args.job_group, args.cfg_name+'.yml')
    args.cfg_name = os.path.basename(args.cfg_name)[:-4]
    merge_cfg_from_file(cfg_path)
    cfg.GENERAL.JOB_GROUP = args.job_group
    # setup_folder weights folder
    snapshot_dir = osp.join(cfg.GENERAL.WEIGHTS_ROOT, cfg.GENERAL.JOB_GROUP,
                            args.cfg_name)
    warn = False if cfg.GENERAL.JOB_GROUP == 'tests' or 'debug' else True
    if phase == 'train':
        create_if_not_exist(
            [cfg.GENERAL.WEIGHTS_ROOT, cfg.GENERAL.HISTORY_ROOT], warn=warn)
        create_if_not_exist([
            osp.join(cfg.GENERAL.WEIGHTS_ROOT, cfg.GENERAL.JOB_GROUP),
            osp.join(cfg.GENERAL.HISTORY_ROOT, cfg.GENERAL.JOB_GROUP)
        ],
                            warn=warn)
        create_if_not_exist(snapshot_dir, warn=warn)
        log_dir = osp.join(
            osp.join(
                cfg.LOG.ROOT_DIR, cfg.GENERAL.JOB_GROUP + '_' + args.cfg_name +
                '_' + time_stamp))

    elif phase == 'eval':
        log_dir = osp.join(
            osp.join(cfg.LOG.ROOT_DIR,
                     cfg.GENERAL.JOB_GROUP + '_' + args.cfg_name))
    # setup_folder logger
    # TODO image logger another writer
    tb_writer = None
    if args.save_log:
        tb_writer = TBWriter(
            log_dir, {
                'phase': phase,
                'show_pr_curve': cfg.LOG.SHOW_PR_CURVE,
                'show_test_image': cfg.LOG.SHOW_TEST_IMAGE,
                'show_pr_scalar': cfg.LOG.SHOW_PR_SCALAR,
                'show_maxconf_box': cfg.LOG.SHOW_MAXCONF_BOX
            })
    setup_cuda(cfg, args.cuda, args.devices, args.net_gpus, args.loss_gpu)
    return tb_writer, cfg_path, snapshot_dir, log_dir
コード例 #5
0
def test_vis():
    cfg_name = 'test_data_voc'
    cfg_path = osp.join(cfg.GENERAL.CFG_ROOT, 'tests', cfg_name+'.yml')
    merge_cfg_from_file(cfg_path)
    val_loader = dataset_factory(phase='train', cfg=cfg)
    dataset = val_loader.dataset
    log_dir = osp.join(osp.join(cfg.LOG.ROOT_DIR, 'tests' + '_' + cfg_name))

    # tb_writer = TBWriter(log_dir, {'aug_vis_list': [3, 4, 5, 6, 8]})
    tb_writer = TBWriter(log_dir, {'aug_vis_list': [4, 5, 8]})
    # tb_writer = None
    for img_idx in range(len(dataset)):
        # if img_idx >= 100:
        #     break
        tb_writer.cfg['aug'] = True
        tb_writer.cfg['steps'] = img_idx
        tb_writer.cfg['img_id'] = img_idx
        tb_writer.cfg['thick'] = 1
        image, target, extra = dataset.pull_item(img_idx, tb_writer)
        print(image.shape)
        tb_writer.writer.file_writer.flush()