Пример #1
0
    def onShow(self, checked: bool):
        """Respond to the 'show' button.  Set the current image as
        input data to the controller.  This causes the activations
        (and the classification result) to be displayed in the
        'Activations' panel.
        """
        if not self._toolbox:
            return

        #image = self._maximization.get_snapshot()
        image = self._imageView.getImage()

        if image is None:
            return

        #a,b = self._maximization.get_min(), self._maximization.get_max()
        #image2 = (image-a)*255/(b-a)
        description = ("Artificial input generated to maximize "
                       f"activation of unit {self._config.UNIT_INDEX} "
                       f"in layer {self._config.LAYER_KEY} "
                       f"of network {self._config.NETWORK_KEY}")
        # FIXME[check]: could we use self._maximization.description here?
        # FIXME[hack]: label is only self._config.UNIT_INDEX, if the
        # network is a classifier an we have selected the last
        # (i.e. output) layer.
        data = Data()
        data.array = image
        data.image = True
        data.description = description
        data.label = self._config.UNIT_INDEX
        self._toolbox.set_input(data)
Пример #2
0
    def _read_frame_at(self, data: Data, time: float):
        """Fetch a video frame at a given timepoint from this
        :py:class:`Video`.

        Arguments
        ---------
        time: float
            The temporal position (point in time) of the frame
            to fetch in seconds (fractions may be given).
        """
        data.array = self._backend.read_frame(time=time)
        data.index = self._backend.frame
Пример #3
0
    def _get_index(self, data: Data, index: int, **kwargs) -> None:
        """Implementation of the :py:class:`Indexed` datasource interface.
        The index will be interpreted as frame number.

        Arguments
        ---------
        index: int
            The frame number of the frame to fetch from the video.
            If no frame is given, the next frame of the video will
            be fetched (advancing the frame number by 1).
        """
        data.array = self._backend[index]
        data.frame = self._backend.frame
        data.index = index or data.frame
        data.time = self._backend.time
Пример #4
0
    def _get_random(self,
                    data: Data,
                    shape: Tuple[int, ...] = None,
                    distribution: str = None,
                    **kwargs) -> None:
        # pylint: disable=arguments-differ
        """Generate a random datapoint. Parameters can be given as arguments
        or will be taken from object attributes.

        Arguments
        ---------
        shape: tuple
            The shape of the data to be generated.

        distribution: str
            The distribution (either `uniform` or `normal`).
        """
        shape = shape or self.shape
        distribution = distribution or self.distribution
        data.array = (np.random.rand(
            *shape) if distribution == 'uniform' else np.random.randn(*shape))