Beispiel #1
0
def _get_lazy_evaluation_dataset_single(inf_cloud_ds, cat_id, n_samples,
                                        eval_fn):
    def sample_fn(cloud):
        return sample_points(np.array(cloud), n_samples)

    example_ids = get_example_ids(cat_id, 'eval')

    normalization_ds = get_normalization_params_dataset(cat_id)
    gt_cloud_ds = get_point_cloud_dataset(
        cat_id, n_samples, example_ids=example_ids).map(sample_fn)

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

    normalization_ds = normalization_ds.map_keys(lambda key: key[:2])
    gt_cloud_ds = gt_cloud_ds.map_keys(lambda key: key[:2])

    zipped = Dataset.zip(inf_cloud_ds, gt_cloud_ds,
                         normalization_ds).subset(keys, check_present=False)

    def map_fn(data):
        inf_cloud, gt_cloud, norm_params = data
        inf_cloud = normalized(inf_cloud, **norm_params)
        gt_cloud = normalized(gt_cloud, **norm_params)
        return eval_fn(inf_cloud, gt_cloud)

    dataset = zipped.map(map_fn)
    return dataset
def get_lazy_evaluation_dataset(inf_cloud_ds, cat_id, n_samples, eval_fn):
    example_ids = get_example_ids(cat_id, 'eval')

    def sample_fn(cloud):
        return sample_points(np.array(cloud), n_samples)

    normalization_ds = get_normalization_params_dataset(cat_id)
    gt_cloud_ds = get_point_cloud_dataset(
        cat_id, n_samples, example_ids=example_ids).map(sample_fn)
    zipped = Dataset.zip(inf_cloud_ds, gt_cloud_ds, normalization_ds)

    def map_fn(data):
        inf_cloud, gt_cloud, norm_params = data
        inf_cloud = normalized(inf_cloud, **norm_params)
        gt_cloud = normalized(gt_cloud, **norm_params)
        return eval_fn(inf_cloud, gt_cloud)

    return zipped.map(map_fn)
Beispiel #3
0
    def get_lazy_dataset(self):
        from shapenet.core.point_clouds import get_point_cloud_dataset
        from util3d.point_cloud import sample_points
        from template_ffd.model import get_builder
        from template_ffd.inference.predictions import get_predictions_dataset
        builder = get_builder(self._model_id)
        cat_id = builder.cat_id
        template_ids = builder.template_ids
        clouds = []

        def sample_fn(cloud):
            return sample_points(np.array(cloud), self._n_samples)

        gt_clouds = get_point_cloud_dataset(
            cat_id, builder.n_samples).map(sample_fn)
        with gt_clouds:
            for example_id in template_ids:
                clouds.append(np.array(gt_clouds[example_id]))

        predictions = get_predictions_dataset(self._model_id)
        inf_cloud_ds = predictions.map(lambda i: clouds[i].copy())
        return _get_lazy_emd_dataset(inf_cloud_ds, cat_id, self._n_samples)
Beispiel #4
0
    def get_lazy_dataset(self):
        from shapenet.core.point_clouds import get_point_cloud_dataset
        from util3d.point_cloud import sample_points
        from template_ffd.model import get_builder
        from template_ffd.inference.predictions import get_predictions_dataset
        builder = get_builder(self._model_id)
        cat_id = builder.cat_id
        template_ids = builder.template_ids
        clouds = []

        def sample_fn(cloud):
            return sample_points(np.array(cloud), self._n_samples)

        gt_clouds = get_point_cloud_dataset(
            cat_id, builder.n_samples).map(sample_fn)
        with gt_clouds:
            for example_id in template_ids:
                clouds.append(np.array(gt_clouds[example_id]))

        predictions = get_predictions_dataset(self._model_id)
        inf_cloud_ds = predictions.map(lambda i: clouds[i].copy())
        return _get_lazy_emd_dataset(inf_cloud_ds, cat_id, self._n_samples)
Beispiel #5
0
#!/usr/bin/python
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import dids
from shapenet.core.point_clouds import get_point_cloud_dataset
from shapenet.core.meshes import get_mesh_dataset
from shapenet.core import cat_desc_to_id, get_test_train_split

cat_desc = 'plane'
cat_id = cat_desc_to_id(cat_desc)

cloud_ds = get_point_cloud_dataset(cat_id, 1024)
mesh_ds = get_mesh_dataset(cat_id)

zipped_ds = dids.Dataset.zip(mesh_ds, cloud_ds)


def vis(mesh, cloud):
    import numpy as np
    from util3d.mayavi_vis import vis_mesh, vis_point_cloud
    from mayavi import mlab
    vertices, faces = (np.array(mesh[k]) for k in ('vertices', 'faces'))
    vis_mesh(vertices, faces, color=(0, 0, 1), axis_order='xzy')
    vis_point_cloud(np.array(cloud),
                    color=(0, 1, 0),
                    scale_factor=0.01,
                    axis_order='xzy')
    mlab.show()
Beispiel #6
0
 def __init__(self, cat_id, n_samples, n_resamples):
     self._cat_id = cat_id
     self._n_samples = n_samples
     self._n_resamples = n_resamples
     self._dataset = get_point_cloud_dataset(cat_id, n_samples)
     self._dataset.open()
Beispiel #7
0
import numpy as np
from mayavi import mlab
from util3d.mayavi_vis import vis_point_cloud, vis_normals
from shapenet.core.point_clouds import get_point_cloud_dataset
from shapenet.core.point_clouds import get_cloud_normal_dataset
from shapenet.core import cat_desc_to_id

cat_desc = 'plane'
n_points = 16384
cat_id = cat_desc_to_id(cat_desc)

show_normals = True
if vis_normals:
    dataset = get_cloud_normal_dataset(cat_id, n_points)
else:
    dataset = get_point_cloud_dataset(cat_id, n_points)

with dataset:
    for example_id in dataset:
        data = dataset[example_id]
        s = random.sample(range(n_points), 1024)
        if show_normals:
            cloud = np.array(data['points'])
            normals = np.array(data['normals'])
            cloud = cloud[s]
            normals = normals[s]
        else:
            cloud = np.array(data)
            normals = None
            cloud = cloud[s]
        vis_point_cloud(cloud,
Beispiel #8
0
 def __init__(self, cat_id, n_samples, n_resamples):
     self._cat_id = cat_id
     self._n_samples = n_samples
     self._n_resamples = n_resamples
     self._dataset = get_point_cloud_dataset(cat_id, n_samples)
     self._dataset.open()