Пример #1
0
def detect(ibs, gpath_list, tree_path_list, **kwargs):
    """
    Args:
        gpath_list (list of str): the list of image paths that need detection
        tree_path_list (list of str): the list of trees to load for detection

    Kwargs (optional): refer to the PyRF documentation for configuration settings

    Returns:
        iter
    """
    # Get scales from detect config, if not specified
    if 'scale_list' not in kwargs.keys():
        kwargs['scale_list'] = list(
            map(float, ibs.cfg.detect_cfg.scale_list.split(',')))
        assert all(
            [isinstance(scale, float) for scale in kwargs['scale_list']])

    verbose = kwargs.get('verbose', ut.VERBOSE)
    if verbose:
        print(
            '[randomforest.detect()] Detecting with %d trees with scale_list=%r'
            % (
                len(tree_path_list),
                kwargs['scale_list'],
            ))

    # Run detection
    detector = pyrf.Random_Forest_Detector(verbose=verbose)
    forest = detector.forest(tree_path_list)
    results_iter = detector.detect(forest, gpath_list, **kwargs)
    return results_iter
Пример #2
0
def train_gpath_list(ibs,
                     train_pos_cpath_list,
                     train_neg_cpath_list,
                     trees_path=None,
                     **kwargs):
    """
    Args:
        train_pos_cpath_list (list of str): the list of positive image paths
            for training
        train_neg_cpath_list (list of str): the list of negative image paths
            for training
        trees_path (str): the path that the trees will be saved into (along
            with temporary training inventory folders that are deleted once
            training is finished)
        species (str, optional): the species that should be used to assign to
            the newly trained trees

    Kwargs (optional): refer to the PyRF documentation for configuration settings

    Returns:
        None
    """
    if trees_path is None:
        trees_path = join(ibs.get_treesdir(), 'generic')
    # Train trees
    detector = pyrf.Random_Forest_Detector()
    detector.train(train_pos_cpath_list, train_neg_cpath_list, trees_path,
                   **kwargs)
Пример #3
0
def compute_forgroundness(fpath1, kpts1, species='zebra_plains'):
    """
    hack in foregroundness
    """
    import pyrf
    import vtool as vt
    from os.path import exists
    # hack for getting a model (not entirely ibeis independent)
    trees_path = ut.get_app_resource_dir('ibeis', 'detectmodels', 'rf',
                                         species)
    tree_fpath_list = ut.glob(trees_path, '*.txt')
    detector = pyrf.Random_Forest_Detector()
    # TODO; might need to downsample
    forest = detector.forest(tree_fpath_list, verbose=False)
    gpath_list = [fpath1]
    output_gpath_list = [
        gpath + '.' + species + '.probchip.png' for gpath in gpath_list
    ]
    detectkw = {
        'scale_list': [1.15, 1.0, 0.85, 0.7, 0.55, 0.4, 0.25, 0.1],
        'output_gpath_list': output_gpath_list,
        'mode': 1,  # mode one outputs probimage
    }
    results_iter = detector.detect(forest, gpath_list, **detectkw)
    results_list = list(results_iter)  # NOQA
    probchip_list = [
        vt.imread(gpath, grayscale=True) if exists(gpath) else None
        for gpath in output_gpath_list
    ]
    #vtpatch.get_warped_patches()
    fgweights_list = []
    kpts_list = [kpts1]
    for probchip, kpts in zip(probchip_list, kpts_list):
        patch_list = [
            vt.get_warped_patch(probchip, kp)[0].astype(np.float32) / 255.0
            for kp in kpts
        ]
        weight_list = [
            vt.gaussian_average_patch(patch) for patch in patch_list
        ]
        #weight_list = [patch.sum() / (patch.size) for patch in patch_list]
        weights = np.array(weight_list, dtype=np.float32)
        fgweights_list.append(weights)
    fgweights = fgweights_list[0]
    detector.free_forest(forest)
    return fgweights