def main(_):
    from shapenet.core import to_cat_id
    from shapenet.core.renderings.renderings_manager import get_base_manager
    from shapenet.core.frustrum_voxels import create_frustrum_voxels
    from shapenet.core.frustrum_voxels import create_temp_frustrum_voxels
    from shapenet.core.voxels.config import get_config
    if FLAGS.src_voxel_dim is None:
        FLAGS.src_voxel_dim = FLAGS.voxel_dim

    voxel_config = get_config(
        FLAGS.src_voxel_dim, alt=False).filled(FLAGS.fill_alg)
    manager = get_base_manager(
        dim=FLAGS.dim, turntable=FLAGS.turntable,
        n_views=FLAGS.n_views)

    cats = FLAGS.cat
    if cats is None:
        from shapenet.r2n2 import get_cat_ids
        cats = get_cat_ids()

    for cat in cats:
        cat_id = to_cat_id(cat)
        args = manager, voxel_config, FLAGS.voxel_dim, cat_id
        if FLAGS.temp_only:
            create_temp_frustrum_voxels(*args, compression=FLAGS.compression)
        else:
            create_frustrum_voxels(*args, compression=FLAGS.compression)
Exemple #2
0
def main(_):
    from shapenet.core.voxels.config import get_config
    from shapenet.core.voxels.datasets import get_manager, convert
    from shapenet.core import to_cat_id
    config = get_config(FLAGS.voxel_dim, alt=FLAGS.alt)
    if FLAGS.cat is None:
        # from shapenet.r2n2 import get_cat_ids
        raise ValueError('Must provide at least one cat to convert.')
    if FLAGS.fill is not None:
        config = config.filled(FLAGS.fill)

    kwargs = dict(config=config, key=FLAGS.format)
    safe_update(kwargs, compression=FLAGS.compression, shape_key=FLAGS.shape)
    src_kwargs = dict()
    safe_update(src_kwargs,
                key=FLAGS.src_format,
                compression=FLAGS.src_compression,
                shape_key=FLAGS.src_shape)

    for cat in FLAGS.cat:
        dst = get_manager(cat_id=to_cat_id(cat), **kwargs)
        convert(dst,
                overwrite=FLAGS.overwrite,
                delete_src=FLAGS.delete_src,
                **src_kwargs)
def main(_):
    from shapenet.core.renderings.renderings_manager import get_base_manager
    from shapenet.core import to_cat_id
    from shapenet.core.objs import try_extract_models
    cat_ids = [to_cat_id(c) for c in FLAGS.cat]
    for cat_id in cat_ids:
        try_extract_models(cat_id)

    manager = get_base_manager(
        dim=FLAGS.dim,
        turntable=FLAGS.turntable,
        n_views=FLAGS.n_views,
    )
    manager.render_all(cat_ids=cat_ids, verbose=FLAGS.verbose)
Exemple #4
0
def main(_):
    from shapenet.core.voxels.config import get_config
    from shapenet.core import to_cat_id
    from shapenet.r2n2 import get_cat_ids
    config = get_config(FLAGS.voxel_dim, alt=FLAGS.alt)
    fill = FLAGS.fill
    if fill is not None:
        config = config.filled(fill)
    if FLAGS.cat is None:
        cat_ids = get_cat_ids()
    else:
        cat_ids = [to_cat_id(c) for c in FLAGS.cat]
    if FLAGS.fill is not None:
        config = config.filled(FLAGS.fill)
    for cat_id in cat_ids:
        config.create_voxel_data(cat_id)
Exemple #5
0
def main(_):
    from shapenet.core.voxels.config import get_config
    from shapenet.core import to_cat_id
    from shapenet.core import get_example_ids
    config = get_config(FLAGS.voxel_dim, alt=FLAGS.alt)
    fill = FLAGS.fill
    if fill is not None:
        config = config.filled(fill)
    if FLAGS.cat is None:
        raise ValueError('Must provide at least one cat to convert.')
    if FLAGS.fill is not None:
        config = config.filled(FLAGS.fill)
    cat_id = to_cat_id(FLAGS.cat)
    example_ids = FLAGS.example_id
    if example_ids is None:
        example_ids = get_example_ids(cat_id)
    config.create_voxel_data(cat_id, example_ids)
Exemple #6
0
def main(_):
    from progress.bar import IncrementalBar
    import numpy as np
    from shapenet.core import to_cat_id
    from shapenet.core.renderings.renderings_manager import get_base_manager
    from shapenet.core.frustrum_voxels import get_frustrum_voxels_data
    from shapenet.core.frustrum_voxels import GROUP_KEY
    from shapenet.core.voxels.config import get_config
    from util3d.voxel import rle
    voxel_config = get_config(FLAGS.src_voxel_dim,
                              alt=False).filled('orthographic')
    manager = get_base_manager(dim=FLAGS.dim,
                               turntable=FLAGS.turntable,
                               n_views=FLAGS.n_views)

    cats = FLAGS.cat
    if cats is None:
        from shapenet.r2n2 import get_cat_ids
        cats = get_cat_ids()

    expected_length = FLAGS.voxel_dim**3

    for ci, cat in enumerate(cats):
        # if ci >= 3:
        #     continue
        cat_id = to_cat_id(cat)
        print('Checking cat %s: %d / %d' % (cat_id, ci + 1, len(cats)))
        with get_frustrum_voxels_data(manager.root_dir, voxel_config,
                                      FLAGS.voxel_dim, cat_id) as root:
            data = root[GROUP_KEY]
            ne, nr = data.shape[:2]
            bar = IncrementalBar(max=ne)
            for i in range(ne):
                bar.next()
                di = np.array(data[i])
                for j in range(nr):
                    actual_length = rle.length(di[j])
                    # actual_length = len(rle.rle_to_dense(di[j]))
                    if actual_length != expected_length:
                        raise ValueError(
                            'Incorrect length at %s, %d, %d\n'
                            'Expected %d, got %d' %
                            (cat_id, i, j, expected_length, actual_length))
            bar.finish()
from util3d.transform.frustrum import voxel_values_to_frustrum
from util3d.transform.nonhom import get_eye_to_world_transform
from util3d.voxel.binvox import DenseVoxels
from shapenet.core import get_example_ids, to_cat_id
from shapenet.core.renderings.renderings_manager import get_base_manager
from shapenet.core.voxels.config import get_config
from shapenet.core.voxels.datasets import get_dataset as get_voxel_dataset

import time


cat = 'plane'
voxel_dim = 64
ray_shape = (32,)*3
view_index = 0
cat_id = to_cat_id(cat)
config = get_config(voxel_dim, alt=False).filled('orthographic')
voxel_dataset = get_voxel_dataset(
    config, cat_id, id_keys=True, key='rle', compression='lzf')
image_manager = get_base_manager(dim=256)
n_renderings = image_manager.get_render_params()['n_renderings']
f = 32 / 35


example_ids = get_example_ids(cat_id)
with voxel_dataset:
    for example_id in example_ids:
        start = time.time()
        dense_data = voxel_dataset[example_id].dense_data()
        dense_data = dense_data[:, -1::-1]