Ejemplo n.º 1
0
def get_resnet_config():
    """Define config of an additional object. In this case 'resnet'"""
    config = Configuration('resnet')
    config.add_param('foo', True, 'Test variable')
    config.add_param('bar', False, 'Another variable')
    config.add_param('mixed', 555.5, 'Yet another variable')
    config.add_param('maybe_alist_of_float', 1., 'some potential list',
                     'maybe_list')
    return config
Ejemplo n.º 2
0
    def __init__(self):
        super(PandaTableConfiguration, self).__init__()

        # specific scene configuration
        self.add_param('scene_setup.blend_file', '~/gfx/modeling/robottable_empty.blend',
                       'Path to .blend file with modeled scene')
        self.add_param('scene_setup.environment_textures', '$AMIRA_DATASETS/OpenImagesV4/Images',
                       'Path to background images / environment textures')
        self.add_param('scene_setup.cameras',
                       ['Camera', 'StereoCamera.Left', 'StereoCamera.Right', 'Camera.FrontoParallel.Left',
                        'Camera.FrontoParallel.Right'], 'Cameras to render')
        self.add_param('scene_setup.forward_frames', 25, 'Number of frames in physics forward-simulation')

        # scenario: target objects
        self.add_param('scenario_setup.target_objects', [],
                       'List of objects to drop in the scene for which annotated info are stored')
        self.add_param('scenario_setup.distractor_objects', [],
                       'List of objects to drop in the scene for which info are NOT stored'
                       'List of objects visible in the scene but of which infos are not stored')
        self.add_param('scenario_setup.textured_objects', [],
                       'List of objects whose texture is randomized during rendering')
        self.add_param('scenario_setup.objects_textures', '', 'Path to images for object textures')

        # multiview configuration (if implemented)
        self.add_param('multiview_setup.mode', '',
                       'Selected mode to generate view points, i.e., random, bezier, viewsphere')
        self.add_param('multiview_setup.mode_config', Configuration(), 'Mode specific configuration')
        self.add_param('multiview_setup.offset', True,
                       'If False, multi views are not offset with initial camera location. Default: True')

        # specific debug config
        self.add_param('debug.plot', False, 'If True, in debug mode, enable simple visual debug')
        self.add_param('debug.plot_axis', False, 'If True, in debug-plot mode, plot camera coordinate systems')
        self.add_param('debug.scatter', False, 'If True, in debug mode-plot, enable scatter plot')
        self.add_param('debug.save_to_blend', False, 'If True, in debug mode, log to .blend files')
Ejemplo n.º 3
0
def get_subconfig(net_type):
    """
    Define configuration for an object. In this case a network names 'retina'
    """
    if not (net_type == 'retina'):
        raise RuntimeError(f"Unsupported network type {net_type}")

    # default retina configuration
    config = Configuration('retina')
    config.add_param('setting', 111, 'some standard setting')
    config.add_param('maybe_alist_of_int', 0, 'some potential list',
                     'maybe_list')
    config.add_param('empty_list', [], 'some empty list', 'maybe_list')

    # nested configuration for resnet
    config.add_param('resnet', get_resnet_config(), 'resnet help')

    return config
Ejemplo n.º 4
0
    def __init__(self):
        super(WorkstationScenariosConfiguration, self).__init__()

        # specific scene configuration
        self.add_param('scene_setup.blend_file', '$AMIRA_DATA_GFX/modeling/workstation_scenarios.blend',
                       'Path to .blend file with modeled scene')
        self.add_param('scene_setup.environment_textures', '$AMIRA_DATASETS/OpenImagesV4/Images',
                       'Path to background images / environment textures')
        self.add_param('scene_setup.cameras', ['CameraLeft', 'Camera', 'CameraRight'], 'Cameras to render')
        self.add_param('scene_setup.forward_frames', 15, 'Number of frames in physics forward-simulation')

        # specific parts configuration. This is just a dummy entry for purposes
        # of demonstration and help message generation
        # self.add_param(
        #     'parts.example_dummy',
        #     '/path/to/example_dummy.blend',
        #     'Path to additional blender files containing invidual parts. Format: partname = /path/to/blendfile.blend')
        # self.add_param(
        #     'parts.ply.example_dummy',
        #     '/path/to/example_dummy.ply',
        #     'Path to PLY files containing part "example_dummy". Format: ply.partname = /path/to/blendfile.ply')
        # self.add_param(
        #     'parts.ply_scale.example_dummy',
        #     [1.0, 1.0, 1.0],
        #     'Scaling factor in X, Y, Z dimensions of part "example_dummy". Format must be a list of 3 floats.')

        # specific scenario configuration
        self.add_param('scenario_setup.scenario', 0, 'Scenario to render')
        self.add_param('scenario_setup.target_objects', [],
                       'List of objects to drop in the scene for which annotated info are stored')
        self.add_param('scenario_setup.distractor_objects', [],
                       'List of objects to drop in the scene for which info are NOT stored')
        self.add_param('scenario_setup.abc_objects', [], 'List of all ABC-Dataset objects to drop in environment')
        self.add_param('scenario_setup.num_abc_colors', 3, 'Number of random metallic materials to generate')
    
        # multiview configuration (if implemented)
        self.add_param('multiview_setup.mode', '',
                       'Selected mode to generate view points, i.e., random, bezier, viewsphere')
        self.add_param('multiview_setup.mode_config', Configuration(), 'Mode specific configuration')
        self.add_param('multiview_setup.offset', True,
                       'If False, multi views are not offset with initial camera location. Default: True')
        
        # specific debug config
        self.add_param('debug.plot', False, 'If True, in debug mode, enable simple visual debug')
        self.add_param('debug.plot_axis', False, 'If True, in debug-plot mode, plot camera coordinate systems')
        self.add_param('debug.scatter', False, 'If True, in debug mode-plot, enable scatter plot')
        self.add_param('debug.save_to_blend', False, 'If True, in debug mode, log to .blend files')
Ejemplo n.º 5
0
def get_basic_config():
    """
    Define some default basic configuration
    """

    # global configuration
    config = Configuration()
    config.add_param('aint', 1, 'Some int')
    config.add_param('astr', 'a', 'Some string')
    config.add_param('afloat', 10.1, 'Some float')
    config.add_param('alist', ['a', 2, 4.3], 'Some list')
    config.add_param('adict', {'a': 1}, 'Some dict')

    config.add_param('training.network_type', 'dope', 'Network type')
    config.add_param('optimizer.learning_rate', 1.000, 'Learning Rate')
    config.a = '123'

    return config
def generate_multiview_cameras_locations(num_locations: int, mode: str,
                                         camera_names: list, **kw):
    """
    Generate multiple locations for multiple cameras according to selected mode.

    NOTE: cameras' locations will be offset from their initial location in the scene.
    This way, the location of a given camera setup (e.g., consisting of multiple cameras) is
    "rigidly" transformed (notice that cameras will in general rotate), in space.
    This allow to preserve relative locations within the given setup, e.g., parallel cameras.

    Args:
        num_locations(int): number of locations to generate
        mode(str): mode used to generate locations
        camera_names(list(str)): list of string with bpy objects camera names

    Keywords Args:
        config(Configuration/dict-like)
        offset(bool): if False, generated locations are not offset with original camera locations. Default: True

    Returns:
        locations(dict(array)): dictionary with list of locations for each camera
        original_locations(dict(array)): dictionary with original camera locations
    """
    def get_array_from_str(cfg, name, default):
        """
        Get array from a csv string or fallback to default

        Args:
            cfg(dict-like): configuration struct where to look
            name(str): config parameter to search for
            default(array-like): default array value

        Returns:
            array-like: found in cfg or default
        """
        p = cfg.get(name, default)
        if isinstance(p, str):
            if p == '':
                return default
            p = np.fromstring(p, sep=',')
        return p

    def get_list_from_str(cfg, name, default):
        import ast
        tmp = cfg.get(name, None)
        if tmp is None:
            return default
        alist = ast.literal_eval(tmp)
        return [np.array(v) for v in alist]

    # camera location
    original_locations = get_current_cameras_locations(camera_names)

    # define supported modes
    _available_modes = {
        'random': random_points,
        'bezier': points_on_bezier,
        'circle': points_on_circle,
        'wave': points_on_wave,
        'viewsphere': points_on_viewsphere,
        'piecewiselinear': points_on_piecewise_line,
    }

    # early check for selected mode
    if mode not in _available_modes.keys():
        raise ValueError(
            f'Selected mode {mode} not supported for multiview locations')

    # build dict with available config per each mode
    mode_cfg = kw.get('config',
                      Configuration())  # get user defined config (if any)
    _modes_cfgs = {
        'random': {
            'base_location':
            get_array_from_str(mode_cfg, 'base_location', np.zeros(3)),
            'scale':
            float(mode_cfg.get('scale', 1))
        },
        'bezier': {
            'p0': get_array_from_str(mode_cfg, 'p0', np.zeros(3)),
            'p1': get_array_from_str(mode_cfg, 'p1', np.random.randn(3)),
            'p2': get_array_from_str(mode_cfg, 'p2', np.random.randn(3)),
            'start': float(mode_cfg.get('start', 0)),
            'stop': float(mode_cfg.get('stop', 1))
        },
        'circle': {
            'radius': float(mode_cfg.get('radius', 1)),
            'center': get_array_from_str(mode_cfg, 'center', np.zeros(3))
        },
        'wave': {
            'radius': float(mode_cfg.get('radius', 1)),
            'center': get_array_from_str(mode_cfg, 'center', np.zeros(3)),
            'frequency': float(mode_cfg.get('frequency', 1)),
            'amplitude': float(mode_cfg.get('amplitude', 1))
        },
        'viewsphere': {
            'scale': float(mode_cfg.get('scale', 1)),
            'bias': tuple(get_array_from_str(mode_cfg, 'bias', [0, 0, 1.5]))
        },
        'piecewiselinear': {
            'control_points':
            get_list_from_str(mode_cfg, 'points',
                              [np.zeros(3), np.ones(3)])
        }
    }

    # generate locations according to selected mode
    locations = _available_modes[mode](num_locations, **_modes_cfgs[mode])

    # iterate over cameras
    cameras_locations = {}
    offset = kw.get('offset', True)
    for cam_name in camera_names:

        # log
        logger.info(
            f'Generating locations for {cam_name} according to {mode} mode')

        # get location
        # NOTE: need to copy otherwise we overwrite the array being mutable
        cameras_locations[cam_name] = np.copy(locations)
        if offset:
            cameras_locations[cam_name] += np.copy(
                original_locations[cam_name])

    return cameras_locations, original_locations