How to use the gfootball.env.observation_preprocessing function in gfootball

To help you get started, we’ve selected a few gfootball 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 google-research / football / gfootball / env / __init__.py View on Github external
def create_environment(env_name='',
                       stacked=False,
                       representation='extracted',
                       rewards='scoring',
                       write_goal_dumps=False,
                       write_full_episode_dumps=False,
                       render=False,
                       write_video=False,
                       dump_frequency=1,
                       logdir='',
                       extra_players=None,
                       number_of_left_players_agent_controls=1,
                       number_of_right_players_agent_controls=0,
                       channel_dimensions=(
                           observation_preprocessing.SMM_WIDTH,
                           observation_preprocessing.SMM_HEIGHT),
                       other_config_options={}):
  """Creates a Google Research Football environment.

  Args:
    env_name: a name of a scenario to run, e.g. "11_vs_11_stochastic".
      The list of scenarios can be found in directory "scenarios".
    stacked: If True, stack 4 observations, otherwise, only the last
      observation is returned by the environment.
      Stacking is only possible when representation is one of the following:
      "pixels", "pixels_gray" or "extracted".
      In that case, the stacking is done along the last (i.e. channel)
      dimension.
    representation: String to define the representation used to build
      the observation. It can be one of the following:
      'pixels': the observation is the rendered view of the football field
github google-research / football / gfootball / env / wrappers.py View on Github external
def observation(self, obs):
    return observation_preprocessing.generate_smm(
        obs, channel_dimensions=self._channel_dimensions,
        config=self.env.unwrapped._config)
github google-research / football / gfootball / env / wrappers.py View on Github external
def __init__(self, env,
               channel_dimensions=(observation_preprocessing.SMM_WIDTH,
                                   observation_preprocessing.SMM_HEIGHT)):
    gym.ObservationWrapper.__init__(self, env)
    self._channel_dimensions = channel_dimensions
    action_shape = np.shape(self.env.action_space)
    shape = (action_shape[0] if len(action_shape) else 1, channel_dimensions[1],
             channel_dimensions[0],
             len(
                 observation_preprocessing.get_smm_layers(
                     self.env.unwrapped._config)))
    self.observation_space = gym.spaces.Box(
        low=0, high=255, shape=shape, dtype=np.uint8)
github google-research / football / gfootball / env / players / ppo2_cnn.py View on Github external
def take_action(self, observation):
    assert len(observation) == 1, 'Multiple players control is not supported'

    observation = observation_preprocessing.generate_smm(observation)
    observation = self._stacker.get(observation)
    action = self._policy.step(observation)[0][0]
    actions = [football_action_set.action_set_dict[self._action_set][action]]
    return actions
github google-research / football / gfootball / env / wrappers.py View on Github external
def __init__(self, env, grayscale=True,
               channel_dimensions=(observation_preprocessing.SMM_WIDTH,
                                   observation_preprocessing.SMM_HEIGHT)):
    gym.ObservationWrapper.__init__(self, env)
    self._grayscale = grayscale
    self._channel_dimensions = channel_dimensions
    action_shape = np.shape(self.env.action_space)
    self.observation_space = gym.spaces.Box(
        low=0,
        high=255,
        shape=(action_shape[0] if len(action_shape) else 1,
               channel_dimensions[1], channel_dimensions[0],
               1 if grayscale else 3),
        dtype=np.uint8)
github google-research / football / gfootball / env / __init__.py View on Github external
def create_remote_environment(
    username,
    token,
    model_name='',
    track='',
    stacked=False,
    representation='raw',
    rewards='scoring',
    channel_dimensions=(
        observation_preprocessing.SMM_WIDTH,
        observation_preprocessing.SMM_HEIGHT),
    include_rendering=False):
  """Creates a remote Google Research Football environment.

  Args:
    username: User name.
    token: User token.
    model_name: A model identifier to be displayed on the leaderboard.
    track: which competition track to connect to.
    stacked: If True, stack 4 observations, otherwise, only the last
      observation is returned by the environment.
      Stacking is only possible when representation is one of the following:
      "pixels", "pixels_gray" or "extracted".
      In that case, the stacking is done along the last (i.e. channel)
      dimension.
    representation: See create_environment.representation comment.
github google-research / football / gfootball / env / wrappers.py View on Github external
def __init__(self, env,
               channel_dimensions=(observation_preprocessing.SMM_WIDTH,
                                   observation_preprocessing.SMM_HEIGHT)):
    gym.ObservationWrapper.__init__(self, env)
    self._channel_dimensions = channel_dimensions
    action_shape = np.shape(self.env.action_space)
    shape = (action_shape[0] if len(action_shape) else 1, channel_dimensions[1],
             channel_dimensions[0],
             len(
                 observation_preprocessing.get_smm_layers(
                     self.env.unwrapped._config)))
    self.observation_space = gym.spaces.Box(
        low=0, high=255, shape=shape, dtype=np.uint8)
github google-research / football / gfootball / env / wrappers.py View on Github external
def __init__(self, env, grayscale=True,
               channel_dimensions=(observation_preprocessing.SMM_WIDTH,
                                   observation_preprocessing.SMM_HEIGHT)):
    gym.ObservationWrapper.__init__(self, env)
    self._grayscale = grayscale
    self._channel_dimensions = channel_dimensions
    action_shape = np.shape(self.env.action_space)
    self.observation_space = gym.spaces.Box(
        low=0,
        high=255,
        shape=(action_shape[0] if len(action_shape) else 1,
               channel_dimensions[1], channel_dimensions[0],
               1 if grayscale else 3),
        dtype=np.uint8)
github google-research / football / gfootball / env / wrappers.py View on Github external
def __init__(self, env,
               channel_dimensions=(observation_preprocessing.SMM_WIDTH,
                                   observation_preprocessing.SMM_HEIGHT)):
    gym.ObservationWrapper.__init__(self, env)
    self._channel_dimensions = channel_dimensions
    action_shape = np.shape(self.env.action_space)
    shape = (action_shape[0] if len(action_shape) else 1, channel_dimensions[1],
             channel_dimensions[0],
             len(
                 observation_preprocessing.get_smm_layers(
                     self.env.unwrapped._config)))
    self.observation_space = gym.spaces.Box(
        low=0, high=255, shape=shape, dtype=np.uint8)