예제 #1
0
    def _load_all_scene_paths(task):
        """
        Parses scene paths into dictionaries that organize it by scenes
        suitable for cross validation.
        """
        scene_im_paths = ub.AutoDict()
        scene_gt_paths = ub.AutoDict()

        keys = task._preprocessing_keys()

        for scene, key in it.product(task.scene_ids, keys):
            im_dpath = task.datasubdir('im' + key, scene)
            gt_dpath = task.datasubdir('gt' + key, scene)

            im_paths = imutil.load_image_paths(im_dpath, ext='.png')
            gt_paths = imutil.load_image_paths(gt_dpath, ext='.png')

            im_paths = list(map(abspath, im_paths))
            gt_paths = list(map(abspath, gt_paths))

            scene_im_paths[scene][key] = im_paths
            scene_gt_paths[scene][key] = gt_paths

        scene_im_paths = scene_im_paths.to_dict()
        scene_gt_paths = scene_gt_paths.to_dict()
        return scene_im_paths, scene_gt_paths
예제 #2
0
    def extend_data_from(task, other, force=False):
        """
        Map the images / groundtruth from another similar task to this one

        >>> from clab.tasks import *
        >>> other = CamVid(repo=expanduser('~/sseg/SegNet'))
        >>> task = DivaV1(clean=2)
        >>> force = False
        """
        src_fpaths = other.all_gt_paths()
        dst_dir = task.datasubdir('extern', other.name)
        dst_fpaths = [join(dst_dir, p) for p in fnameutil.dumpsafe(src_fpaths)]

        need_convert = True

        if not force:
            existing_fpaths = imutil.load_image_paths(dst_dir, ext='.png')
            existing_fpaths == dst_fpaths

            try:
                existing_fpaths = fnameutil.align_paths(
                    dst_fpaths, existing_fpaths)
            except Exception:
                pass
            else:
                dst_fpaths = existing_fpaths
                need_convert = False

        if need_convert:
            from_other_label = task.convert_labels_from(other)
            for src_fpath, dst_fpath in ub.ProgIter(
                    zip(src_fpaths, dst_fpaths),
                    length=len(src_fpaths),
                    label='converting ' + other.name):
                src_gt = cv2.imread(src_fpath, flags=cv2.IMREAD_UNCHANGED)
                dst_gt = from_other_label[src_gt]
                cv2.imwrite(dst_fpath, dst_gt)

        im_fpaths = other.all_im_paths()
        task.extern_train_im_paths += im_fpaths
        task.extern_train_gt_paths += dst_fpaths

        assert fnameutil.check_aligned(
            task.extern_train_im_paths,
            task.extern_train_gt_paths), ('should be aligned. unknown error')
예제 #3
0
 def _load_image_paths(task, subdir):
     assert task.repo is not None
     assert exists(task.repo), 'repo must exist'
     dpath = join(task.repo, subdir)
     assert exists(dpath), 'repo subdir must exist'
     return imutil.load_image_paths(dpath, ext='.png')