Esempio n. 1
0
    def sample(self, obj_name: Optional[str] = None) -> SceneParameters:
        """Returns a new SceneParameters with random values.

        If you create your own biased sampled dataset by inheriting from this class,
        you might want to change the order of how attributes are set.
        For example, if you want that ``obj_rotation_pitch`` should depend on the
        ``arm_position``then you should also sample the ``arm_position`` first.
        However, it is highly recommended to sample the object name first, as
        the sampling of the attribute might be dependent on the label
        (see the explanation of distributions in class description)

        Attrs:
            obj_name: Overides the sampled obj_name with the given namen. Usally only useful for
                manual sampling. Not recommeded when samplign larger sets.
        """
        params = SceneParameters()
        self.sample_obj_name(params)
        # The name flag allows to overide the sampling result. The sampling is still executed to
        # trigger any custom functionality that might be implented in subclasses.
        if obj_name and params.obj_name != obj_name:
            params.obj_name = obj_name

        self.sample_arm_position(params)
        self.sample_labeling_error(params)
        self.sample_spherical(params)
        self.sample_bending(params)
        self.sample_rotation(params)
        self.sample_fliplr(params)
        self.sample_position(params)
        self.sample_color(params)
        params.check_values()
        return params
Esempio n. 2
0
    def sample_arm_position(self,
                            params: SceneParameters,
                            intervention: bool = False):
        """Samples the ``arm_position``.

        Attrs:
            params: SceneParameters for which the arm_position is sampled and updated in place.
            intervention: Flag whether interventional sampling is applied. Details: see class docu.
        """
        obj_name = self._sample_name() if intervention else params.obj_name
        params.arm_position = float(self._sample(obj_name, self.arm_position))
        params.mark_sampled('arm_position')
Esempio n. 3
0
    def sample_position_y(self,
                          params: SceneParameters,
                          intervention: bool = False):
        """Samples ``position_y`` of the object.

        Attrs:
            params: SceneParameters for which the position is sampled and updated in place.
            intervention: Flag whether interventional sampling is applied. Details: see class docu.
        """
        obj_name = self._sample_name() if intervention else params.obj_name
        params.position_y = self._sample(obj_name, self.position_y)
        params.mark_sampled('position_y')
Esempio n. 4
0
    def sample_fliplr(self,
                      params: SceneParameters,
                      intervention: bool = False):
        """Samples the ``fliplr``.

        Attrs:
            params: SceneParameters for which the fliping (left/right) is sampled and updated.
            intervention: Flag whether interventional sampling is applied. Details: see class docu.
        """
        obj_name = self._sample_name() if intervention else params.obj_name
        params.fliplr = self._sample(obj_name, self.fliplr)
        params.mark_sampled('fliplr')
Esempio n. 5
0
    def sample_obj_rotation_yaw(self,
                                params: SceneParameters,
                                intervention: bool = False):
        """Samples the ``obj_rotation_yaw``.

        Attrs:
            params: SceneParameters for which the rotation is sampled and updated in place.
            intervention: Flag whether interventional sampling is applied. Details: see class docu.
        """
        obj_name = self._sample_name() if intervention else params.obj_name
        params.obj_rotation_yaw = self._sample(obj_name, self.obj_rotation_yaw)
        params.mark_sampled('obj_rotation_yaw')
Esempio n. 6
0
    def sample_bending(self,
                       params: SceneParameters,
                       intervention: bool = False):
        """Samples the ``bending``.

        Attrs:
            params: SceneParameters for which the bone roation is sampled and updated in place.
            intervention: Flag whether interventional sampling is applied. Details: see class docu.
        """
        obj_name = self._sample_name() if intervention else params.obj_name
        params.bending = self._sample(obj_name, self.bending)
        params.mark_sampled('bending')
Esempio n. 7
0
    def sample_spherical(self,
                         params: SceneParameters,
                         intervention: bool = False):
        """Samples the ``spherical``..

        Attrs:
            params: SceneParameters for which the spherical attribute is sampled and updated.
            intervention: Flag whether interventional sampling is applied. Details: see class docu.
        """
        obj_name = self._sample_name() if intervention else params.obj_name
        params.spherical = self._sample(obj_name, self.spherical)
        params.mark_sampled('spherical')
Esempio n. 8
0
    def sample_labeling_error(self,
                              params: SceneParameters,
                              intervention: bool = False):
        """Samples the ``labeling_error``.

        Attrs:
            params: SceneParameters for which the labeling_error is sampled and updated in place.
            intervention: Flag whether interventional sampling is applied. Details: see class docu.
        """
        obj_name = self._sample_name() if intervention else params.obj_name
        params.labeling_error = self._sample(obj_name, self.labeling_error)
        params.mark_sampled('labeling_error')
Esempio n. 9
0
    def sample_bg_color(self,
                        params: SceneParameters,
                        intervention: bool = False):
        """Samples the ``bg_color_rgba`` and ``bg_color``.

        Attrs:
            params: SceneParameters for which the labeling_error is sampled and updated in place.
            intervention: Flag whether interventional sampling is applied. Details: see class docu.
        """
        obj_name = self._sample_name() if intervention else params.obj_name
        params.bg_color = float(self._sample(obj_name, self.bg_color))
        params.bg_color_rgba = tuple(self._bg_cmap(params)(
            params.bg_color))  # type: ignore
        params.mark_sampled('bg_color')
Esempio n. 10
0
    def sample_obj_color(self,
                         params: SceneParameters,
                         intervention: bool = False):
        """Samples the ``obj_color`` and ``obj_color_rgba``.

        Attrs:
            params: SceneParameters for which the obj_color is sampled and updated in place.
            intervention: Flag whether interventional sampling is applied. Details: see class docu.
        """
        obj_name = self._sample_name() if intervention else params.obj_name
        if params.arm_position > 0.45 and params.arm_position < 0.55:
            obj_name = obj_name + "_edge"
        params.obj_color = float(self._sample(obj_name, self.obj_color))
        params.obj_color_rgba = tuple(
            self._object_cmap(params)(params.obj_color))  # type: ignore
        params.mark_sampled('obj_color')
Esempio n. 11
0
def _render_files(param_file: str, save_location: str, save_blender_file: str):
    with open(param_file) as fparam:
        for line in fparam.readlines():
            params = SceneParameters.load(json.loads(line))
            scene = Scene(params)
            image_fname = os.path.join(save_location, params.filename)

            mask_fname = os.path.join(save_location, params.mask_filename)
            scene.render(
                image_fname,
                mask_fname,
            )

            if save_blender_file == "True":
                scene.save_blender_file(
                    os.path.join(save_location, f"{params.id}.blender"))
Esempio n. 12
0
 def sample_obj_name(self, params: SceneParameters):
     """Samples the ``obj_name``."""
     params.obj_name = self._sample(None, self.obj_name)
     params.mark_sampled('obj_name')