def filter(self, observation: ObservationType, update_internal_state: bool = True) -> ObservationType: # scipy works only with uint8 observation = observation.astype('uint8') # rescale if isinstance(self.output_observation_space, ImageObservationSpace): observation = scipy.misc.imresize( observation, tuple(self.output_observation_space.shape), interp=self.rescaling_interpolation_type.value) else: new_observation = [] for i in range(self.output_observation_space.shape[ self.output_observation_space.channels_axis]): new_observation.append( scipy.misc.imresize( observation.take( i, self.output_observation_space.channels_axis), tuple(self.planar_map_output_shape), interp=self.rescaling_interpolation_type.value)) new_observation = np.array(new_observation) observation = new_observation.swapaxes( 0, self.output_observation_space.channels_axis) return observation
def filter(self, observation: ObservationType, update_internal_state: bool=True) -> ObservationType: observation = observation.astype('uint8') # rescale if isinstance(self.output_observation_space, ImageObservationSpace): observation = resize(observation, tuple(self.output_observation_space.shape), anti_aliasing=False, preserve_range=True).astype('uint8') else: new_observation = [] for i in range(self.output_observation_space.shape[self.output_observation_space.channels_axis]): new_observation.append(resize(observation.take(i, self.output_observation_space.channels_axis), tuple(self.planar_map_output_shape), preserve_range=True).astype('uint8')) new_observation = np.array(new_observation) observation = new_observation.swapaxes(0, self.output_observation_space.channels_axis) return observation
def filter(self, observation: ObservationType, update_internal_state: bool=True) -> ObservationType: # scale to 0-1 observation = (observation - self.input_low) / (self.input_high - self.input_low) # scale to 0-255 observation *= 255 observation = observation.astype('uint8') return observation
def filter(self, observation: ObservationType, update_internal_state: bool = True) -> ObservationType: # scipy works only with uint8 observation = observation.astype('uint8') # rescale observation = scipy.misc.imresize( observation, self.rescale_factor, interp=self.rescaling_interpolation_type.value) return observation
def filter(self, observation: ObservationType, update_internal_state: bool = True) -> ObservationType: observation = observation.astype('uint8') rescaled_output_size = tuple( [int(self.rescale_factor * dim) for dim in observation.shape[:2]]) if len(observation.shape) == 3: rescaled_output_size += (3, ) # rescale observation = resize(observation, rescaled_output_size, anti_aliasing=False, preserve_range=True).astype('uint8') return observation
def filter(self, observation: ObservationType, update_internal_state: bool = True) -> ObservationType: # Divide the raw lidar data into sectors and take the min from raw lidar data in each sector observation = np.min(observation.reshape( -1, int(observation.shape[0] / self._num_sectors)), axis=1) # Clip the observation data to clipping distance. np.minimum(observation, self._clipping_dist, out=observation) # Discretize the observation sector data observation = np.floor(observation / self._discrete_range).astype( np.int) # One hot encode the discretized observation sector data one_hot_encode = np.zeros( (observation.size, self._num_values_per_sector + 1)) one_hot_encode[np.arange(observation.size), observation] = 1 # Get rid of last column as it means lidar didn't detect anything one_hot_encode = np.delete(one_hot_encode, -1, axis=1) result = one_hot_encode.reshape(-1).astype(float) return result
def filter(self, observation: ObservationType, update_internal_state: bool = True) -> ObservationType: observation = np.min(observation.reshape(-1, NUMBER_OF_LIDAR_SECTORS), axis=1) return (observation < SECTOR_LIDAR_CLIPPING_DIST).astype(float)
def filter(self, observation: ObservationType, update_internal_state: bool = True) -> ObservationType: return observation.squeeze(axis=self.axis)