How to use the perception.Image function in Perception

To help you get started, we’ve selected a few Perception examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BerkeleyAutomation / perception / perception / models / keras_wrappers.py View on Github external
x = self._preprocess_input(x)
                for x_name in self.x_names:
                    batch_x[x_name][batch_ind,...] = x[x_name]
                batch_y[batch_ind,...] = to_categorical(y[self.y_name],
                                                        num_classes=self.num_classes)
                batch_ind += 1

        # subsample data
        for x_name in self.x_names:
            batch_x[x_name] = batch_x[x_name][:batch_ind,...]
        batch_y = batch_y[:batch_ind]

        # optionally, save images
        if self.save_to_dir:
            for x_name, x_tensor in batch_x.iteritems():
                if Image.can_convert(x_tensor[0]):
                    for i, x in enumerate(x_tensor):
                        filename = '{prefix}_{index}_{hash}.{format}'.format(prefix=self.save_prefix,
                                                                             index=i,
                                                                             hash=np.random.randint(1e4),
                                                                             format='npy')
                        np.save(filename, x)

        return batch_x, batch_y
github BerkeleyAutomation / perception / perception / models / keras_wrappers.py View on Github external
image_noise_width = min(x.shape[1], x.shape[1] / self.image_gaussian_corrcoef)
                image_noise_channels = x.shape[2]
                image_num_px = image_noise_height * image_noise_width
                for c in range(image_noise_channels):
                    image_noise = ss.norm.rvs(scale=self.image_gaussian_sigma, size=image_num_px)
                    image_noise = image_noise.reshape(image_noise_height, image_noise_width)
                    image_noise = sm.imresize(image_noise, size=float(max(self.image_gaussian_corrcoef, 1)), interp='bilinear', mode='F')
                    x[:,:,c] += image_noise.astype(x.dtype)
            else:
                data_noise = ss.norm.rvs(scale=self.data_gaussian_sigma,
                                         size=x.shape[0])
                x += data_noise.astype(x.dtype)
            x_dict[x_name] = x

        for x_name, x in x_dict.iteritems():
            if Image.can_convert(x):
                num_vals = x.shape[0] * x.shape[1] * x.shape[2]
                num_drop = int(self.image_dropout_rate * num_vals)
                dropout_ind = np.random.choice(num_vals,
                                               size=num_drop)
                dropout_ind = np.unravel_index(dropout_ind, x.shape)
                x[dropout_ind[0], dropout_ind[1], dropout_ind[2]] = 0
            else:
                num_vals = x.shape[0]
                num_drop = int(self.data_dropout_rate * num_vals)
                dropout_ind = np.random.choice(num_vals,
                                               size=num_drop)
                x[dropout_ind] = 0
            x_dict[x_name] = x

        return x_dict
github BerkeleyAutomation / perception / perception / primesense_sensor.py View on Github external
----------
        num_img : int
            The number of consecutive frames to process.

        Returns
        -------
        :obj:`DepthImage`
            The min DepthImage collected from the frames.
        """
        depths = []

        for _ in range(num_img):
            _, depth, _ = self.frames()
            depths.append(depth)

        return Image.min_images(depths)
github BerkeleyAutomation / perception / perception / primesense_sensor.py View on Github external
def min_depth_img(self, num_img=1):
        """Collect a series of depth images and return the min of the set.

        Parameters
        ----------
        num_img : int
            The number of consecutive frames to process.

        Returns
        -------
        :obj:`DepthImage`
            The min DepthImage collected from the frames.
        """
        depths = self._read_depth_images(num_img)

        return Image.min_images(depths)