示例#1
0
    def getState(self, observation, env_id=0):
        if getNChannels() > 3:
            observation = np.dstack((preprocessImage(observation[:, :, :3],
                                                     convert_to_rgb=False),
                                     preprocessImage(observation[:, :, 3:],
                                                     convert_to_rgb=False)))
        else:
            observation = preprocessImage(observation, convert_to_rgb=False)

        # Create 4D Tensor
        observation = observation.reshape(1, *observation.shape)
        # Channel first
        observation = np.transpose(observation, (0, 3, 2, 1))
        observation = th.from_numpy(observation).float().to(self.device)

        with th.no_grad():
            state = self.model.getStates(observation)[0]
        return state.to(th.device("cpu")).detach().numpy()
示例#2
0
 def getExtendedObservation(self):
     if getNChannels() > 3:
         self.multi_view = True
     self._observation = self.render("rgb_array")
     return self._observation