Ejemplo n.º 1
0
def get_ds(cat_desc, regime='e'):
    view_index = 5
    edge_length_threshold = 0.02

    cat_id = cat_desc_to_id(cat_desc)
    model_id = '%s_%s' % (regime, cat_desc)

    image_ds = RenderConfig().get_dataset(cat_id, view_index)
    cloud_ds = get_cloud_manager(
        model_id, pre_sampled=True, n_samples=n_samples).get_lazy_dataset()
    mesh_ds = get_inferred_mesh_dataset(
        model_id, edge_length_threshold=edge_length_threshold)
    gt_mesh_ds = get_mesh_dataset(cat_id)
    voxel_ds = get_voxel_dataset(
        model_id, edge_length_threshold=edge_length_threshold, filled=False)
    selected_template_ds = get_selected_template_idx_dataset(model_id)

    template_meshes = []
    with gt_mesh_ds:
        for template_id in get_template_ids(cat_id):
            mesh = gt_mesh_ds[template_id]
            template_meshes.append(
                {k: np.array(mesh[k]) for k in ('vertices', 'faces')})

    template_mesh_ds = selected_template_ds.map(lambda i: template_meshes[i])

    return Dataset.zip(
        image_ds, gt_mesh_ds, cloud_ds, mesh_ds, voxel_ds, template_mesh_ds)
Ejemplo n.º 2
0
def get_ds(cat_desc, regime='e'):
    view_index = 5
    edge_length_threshold = 0.02

    cat_id = cat_desc_to_id(cat_desc)
    model_id = '%s_%s' % (regime, cat_desc)

    image_ds = RenderConfig().get_dataset(cat_id, view_index)
    cloud_ds = get_cloud_manager(
        model_id, pre_sampled=True, n_samples=n_samples).get_lazy_dataset()
    mesh_ds = get_inferred_mesh_dataset(
        model_id, edge_length_threshold=edge_length_threshold)
    gt_mesh_ds = get_mesh_dataset(cat_id)
    voxel_ds = get_voxel_dataset(
        model_id, edge_length_threshold=edge_length_threshold, filled=False)
    selected_template_ds = get_selected_template_idx_dataset(model_id)

    template_meshes = []
    with gt_mesh_ds:
        for template_id in get_template_ids(cat_id):
            mesh = gt_mesh_ds[template_id]
            template_meshes.append(
                {k: np.array(mesh[k]) for k in ('vertices', 'faces')})

    template_mesh_ds = selected_template_ds.map(lambda i: template_meshes[i])

    return Dataset.zip(
        image_ds, gt_mesh_ds, cloud_ds, mesh_ds, voxel_ds, template_mesh_ds)
Ejemplo n.º 3
0
def create_split_mesh(
        cat_desc, edge_length_threshold, overwrite=False,
        start_threshold=None):
    """Create split mesh data for templates."""
    from shapenet.core import cat_desc_to_id
    from shapenet.core.meshes.config import get_mesh_config
    from template_ffd.templates.ids import get_template_ids
    cat_id = cat_desc_to_id(cat_desc)
    example_ids = get_template_ids(cat_id)
    config = get_mesh_config(edge_length_threshold)
    init = None if start_threshold is None else get_mesh_config(
        start_threshold)
    config.create_cat_data(cat_id, example_ids, overwrite, init)
Ejemplo n.º 4
0
def create_split_mesh(cat_desc,
                      edge_length_threshold,
                      overwrite=False,
                      start_threshold=None):
    """Create split mesh data for templates."""
    from shapenet.core import cat_desc_to_id
    from shapenet.core.meshes.config import get_mesh_config
    from template_ffd.templates.ids import get_template_ids
    cat_id = cat_desc_to_id(cat_desc)
    example_ids = get_template_ids(cat_id)
    config = get_mesh_config(edge_length_threshold)
    init = None if start_threshold is None else get_mesh_config(
        start_threshold)
    config.create_cat_data(cat_id, example_ids, overwrite, init)
Ejemplo n.º 5
0
 def create_split(self, cat_id, overwrite=False):
     import random
     from shapenet.core import get_example_ids
     from template_ffd.templates.ids import get_template_ids
     if not overwrite and self.has_split(cat_id):
         return
     template_ids = set(get_template_ids(cat_id))
     example_ids = get_example_ids(cat_id)
     example_ids = [i for i in example_ids if i not in template_ids]
     example_ids.sort()
     random.seed(self._seed)
     random.shuffle(example_ids)
     train_ids, eval_ids = _train_eval_partition(example_ids,
                                                 self._train_prop)
     train_ids.sort()
     eval_ids.sort()
     for mode, ids in (('train', train_ids), ('eval', eval_ids)):
         with open(self.get_txt_path(cat_id, mode), 'w') as fp:
             fp.writelines(('%s\n' % i for i in ids))
Ejemplo n.º 6
0
 def create_split(self, cat_id, overwrite=False):
     import random
     from shapenet.core import get_example_ids
     from template_ffd.templates.ids import get_template_ids
     if not overwrite and self.has_split(cat_id):
         return
     template_ids = set(get_template_ids(cat_id))
     example_ids = get_example_ids(cat_id)
     example_ids = [i for i in example_ids if i not in template_ids]
     example_ids.sort()
     random.seed(self._seed)
     random.shuffle(example_ids)
     train_ids, eval_ids = _train_eval_partition(
         example_ids, self._train_prop)
     train_ids.sort()
     eval_ids.sort()
     for mode, ids in (('train', train_ids), ('eval', eval_ids)):
         with open(self.get_txt_path(cat_id, mode), 'w') as fp:
             fp.writelines(('%s\n' % i for i in ids))
Ejemplo n.º 7
0
def get_hist_data(model_id, n_bins, mode):
    from shapenet.core import cat_desc_to_id
    from template_ffd.templates.ids import get_template_ids
    from template_ffd.model import load_params
    from template_ffd.inference.predictions import get_predictions_dataset
    cat_id = cat_desc_to_id(load_params(model_id)['cat_desc'])
    n_templates = len(get_template_ids(cat_id))

    counts = np.zeros((n_bins, ), dtype=np.int32)
    argmax_counts = np.zeros((n_templates, ), dtype=np.int32)

    with get_predictions_dataset(model_id) as dataset:
        for example_id in dataset:
            probs = np.array(dataset[example_id]['probs'])
            counts[int(np.max(probs) * n_bins)] += 1
            # prob_indices = np.array(0.999*probs * n_bins, dtype=np.int32)
            # for pi in prob_indices:
            #     counts[pi] += 1
            argmax_counts[np.argmax(probs)] += 1

    counts = counts / np.sum(counts)
    argmax_counts = argmax_counts / np.sum(argmax_counts)
    return counts, argmax_counts
Ejemplo n.º 8
0
 def template_ids(self):
     template_ids = get_template_ids(self.cat_id)
     idxs = self.params.get('template_idxs')
     if idxs:
         template_ids = tuple(template_ids[i] for i in idxs)
     return template_ids
def _get_cat_template_ids(cat_id, template_idxs):
    from template_ffd.templates.ids import get_template_ids
    template_ids = get_template_ids(cat_id)
    if template_idxs is not None:
        template_ids = tuple(template_ids[i] for i in template_idxs)
    return tuple((cat_id, t) for t in template_ids)