Пример #1
0
def vis_voxels(model_id, edge_length_threshold, filled, shuffle=False):
    from mayavi import mlab
    from util3d.mayavi_vis import vis_voxels
    from shapenet.core import cat_desc_to_id
    from template_ffd.inference.voxels import get_voxel_dataset
    from template_ffd.data.voxels import get_gt_voxel_dataset
    from template_ffd.model import load_params
    from template_ffd.data.ids import get_example_ids
    cat_id = cat_desc_to_id(load_params(model_id)['cat_desc'])
    gt_ds = get_gt_voxel_dataset(cat_id, filled)
    inf_ds = get_voxel_dataset(model_id, edge_length_threshold)
    example_ids = get_example_ids(cat_id, 'eval')
    if shuffle:
        example_ids = list(example_ids)
        example_ids.shuffle

    with gt_ds:
        with inf_ds:
            for example_id in example_ids:
                gt = gt_ds[example_id].data
                inf = inf_ds[example_id].data
                vis_voxels(gt, color=(0, 0, 1))
                mlab.figure()
                vis_voxels(inf, color=(0, 1, 0))
                mlab.show()
Пример #2
0
def vis_voxels(model_id, edge_length_threshold, filled, shuffle=False):
    from mayavi import mlab
    from util3d.mayavi_vis import vis_voxels
    from shapenet.core import cat_desc_to_id
    from template_ffd.inference.voxels import get_voxel_dataset
    from template_ffd.data.voxels import get_gt_voxel_dataset
    from template_ffd.model import load_params
    from template_ffd.data.ids import get_example_ids
    cat_id = cat_desc_to_id(load_params(model_id)['cat_desc'])
    gt_ds = get_gt_voxel_dataset(cat_id, filled)
    inf_ds = get_voxel_dataset(model_id, edge_length_threshold)
    example_ids = get_example_ids(cat_id, 'eval')
    if shuffle:
        example_ids = list(example_ids)
        example_ids.shuffle

    with gt_ds:
        with inf_ds:
            for example_id in example_ids:
                gt = gt_ds[example_id].data
                inf = inf_ds[example_id].data
                vis_voxels(gt, color=(0, 0, 1))
                mlab.figure()
                vis_voxels(inf, color=(0, 1, 0))
                mlab.show()
Пример #3
0
    def get_lazy_dataset(self):
        cat_id = cat_desc_to_id(load_params(self._model_id)['cat_desc'])
        example_ids = get_example_ids(cat_id, 'eval')
        inferred_dataset = get_voxel_dataset(
            self._model_id, self._edge_length_threshold, self._voxel_config,
            filled=self._filled, example_ids=example_ids)

        gt_dataset = get_gt_voxel_dataset(cat_id, filled=self._filled)

        voxel_datasets = Dataset.zip(inferred_dataset, gt_dataset)
        voxel_datasets = voxel_datasets.subset(example_ids)

        def map_fn(v):
            return intersection_over_union(v[0].data, v[1].data)

        iou_dataset = voxel_datasets.map(map_fn)
        return iou_dataset
Пример #4
0
    def get_lazy_dataset(self):
        from template_ffd.inference.predictions import \
            get_selected_template_idx_dataset
        builder = get_builder(self._model_id)
        template_ids = builder.template_ids

        gt_ds = get_gt_voxel_dataset(
            builder.cat_id, filled=self._filled, auto_save=True,
            example_ids=template_ids)
        gt_ds = gt_ds.map(lambda v: v.data)
        with gt_ds:
            template_voxels = tuple(gt_ds[tid] for tid in template_ids)

        selected_ds = get_selected_template_idx_dataset(self._model_id)
        selected_ds = selected_ds.map(lambda i: template_voxels[i])

        return Dataset.zip(selected_ds, gt_ds).map(
            lambda v: intersection_over_union(*v))
Пример #5
0
    def get_lazy_dataset(self):
        cat_id = cat_desc_to_id(load_params(self._model_id)['cat_desc'])
        example_ids = get_example_ids(cat_id, 'eval')
        inferred_dataset = get_voxel_dataset(self._model_id,
                                             self._edge_length_threshold,
                                             self._voxel_config,
                                             filled=self._filled,
                                             example_ids=example_ids)

        gt_dataset = get_gt_voxel_dataset(cat_id, filled=self._filled)

        voxel_datasets = Dataset.zip(inferred_dataset, gt_dataset)
        voxel_datasets = voxel_datasets.subset(example_ids)

        def map_fn(v):
            return intersection_over_union(v[0].data, v[1].data)

        iou_dataset = voxel_datasets.map(map_fn)
        return iou_dataset
Пример #6
0
    def get_lazy_dataset(self):
        from template_ffd.inference.predictions import \
            get_selected_template_idx_dataset
        builder = get_builder(self._model_id)
        template_ids = builder.template_ids

        gt_ds = get_gt_voxel_dataset(builder.cat_id,
                                     filled=self._filled,
                                     auto_save=True,
                                     example_ids=template_ids)
        gt_ds = gt_ds.map(lambda v: v.data)
        with gt_ds:
            template_voxels = tuple(gt_ds[tid] for tid in template_ids)

        selected_ds = get_selected_template_idx_dataset(self._model_id)
        selected_ds = selected_ds.map(lambda i: template_voxels[i])

        return Dataset.zip(selected_ds,
                           gt_ds).map(lambda v: intersection_over_union(*v))
Пример #7
0
    def get_lazy_dataset(self):
        cat_id = cat_desc_to_id(load_params(self._model_id)['cat_desc'])
        if not isinstance(cat_id, (list, tuple)):
            cat_id = [cat_id]
        inferred_dataset = get_voxel_dataset(self._model_id,
                                             self._edge_length_threshold,
                                             self._voxel_config,
                                             filled=self._filled)

        gt_dataset = get_gt_voxel_dataset(cat_id, filled=self._filled)
        gt_dataset = gt_dataset.map_keys(lambda key: key[:2])

        with inferred_dataset:
            keys = tuple(inferred_dataset.keys())

        voxel_datasets = Dataset.zip(inferred_dataset, gt_dataset)
        voxel_datasets = voxel_datasets.subset(keys)

        def map_fn(v):
            return intersection_over_union(v[0].dense_data(),
                                           v[1].dense_data())

        iou_dataset = voxel_datasets.map(map_fn)
        return iou_dataset