Commit f8fccea4 authored by Benjamin's avatar Benjamin
Browse files

replace camera width/height with single resolution + add env tutial pynb

parent 47464ae7
...@@ -60,7 +60,7 @@ We offer two packages: ...@@ -60,7 +60,7 @@ We offer two packages:
<!--In case you wish to create a conda environment you can do so by running the below command from the `animalai` folder: <!--In case you wish to create a conda environment you can do so by running the below command from the `animalai` folder:
``` ```
conda env create -f conda_isntall.yaml conda env create -f conda_isntall.yaml
```--> ```-->ni
- We also provide a package that can be used as a starting point for training, and which is required to run most of the - We also provide a package that can be used as a starting point for training, and which is required to run most of the
example scripts found in the `examples/` folder. It contains an extension of example scripts found in the `examples/` folder. It contains an extension of
......
import json
import jsonpickle
import yaml import yaml
import copy
from typing import List from typing import List
from animalai.communicator_objects import ( from animalai.communicator_objects import (
......
...@@ -39,15 +39,12 @@ class AnimalAIEnvironment(UnityEnvironment): ...@@ -39,15 +39,12 @@ class AnimalAIEnvironment(UnityEnvironment):
play: bool = False, play: bool = False,
arenas_configurations: ArenaConfig = None, arenas_configurations: ArenaConfig = None,
inference: bool = False, inference: bool = False,
camera_width: int = None, resolution: int = None,
camera_height: int = None,
grayscale: bool = False, grayscale: bool = False,
side_channels: Optional[List[SideChannel]] = None, side_channels: Optional[List[SideChannel]] = None,
): ):
args = self.executable_args( args = self.executable_args(n_arenas, play, resolution, grayscale)
n_arenas, play, camera_height, camera_width, grayscale
)
self.play = play self.play = play
self.inference = inference self.inference = inference
self.timeout = 10 if play else 60 self.timeout = 10 if play else 60
...@@ -126,6 +123,7 @@ class AnimalAIEnvironment(UnityEnvironment): ...@@ -126,6 +123,7 @@ class AnimalAIEnvironment(UnityEnvironment):
def close(self): def close(self):
if self.play: if self.play:
self.communicator.close() self.communicator.close()
if self.proc1:
self.proc1.kill() self.proc1.kill()
else: else:
super().close() super().close()
...@@ -134,8 +132,7 @@ class AnimalAIEnvironment(UnityEnvironment): ...@@ -134,8 +132,7 @@ class AnimalAIEnvironment(UnityEnvironment):
def executable_args( def executable_args(
n_arenas: int = 1, n_arenas: int = 1,
play: bool = False, play: bool = False,
camera_height: int = 84, resolution: int = 84,
camera_width: int = 84,
grayscale: bool = False, grayscale: bool = False,
) -> List[str]: ) -> List[str]:
args = ["--playerMode"] args = ["--playerMode"]
...@@ -145,12 +142,9 @@ class AnimalAIEnvironment(UnityEnvironment): ...@@ -145,12 +142,9 @@ class AnimalAIEnvironment(UnityEnvironment):
args.append("0") args.append("0")
args.append("--numberOfArenas") args.append("--numberOfArenas")
args.append(str(n_arenas)) args.append(str(n_arenas))
if camera_width: if resolution:
args.append("--cameraWidth") args.append("--resolution")
args.append(str(camera_width)) args.append(str(resolution))
if camera_height:
args.append("--cameraHeight")
args.append(str(camera_height))
if grayscale: if grayscale:
args.append("--grayscale") args.append("--grayscale")
return args return args
...@@ -32,9 +32,7 @@ def test_basic_initialization(mock_communicator, mock_launcher, mock_reset): ...@@ -32,9 +32,7 @@ def test_basic_initialization(mock_communicator, mock_launcher, mock_reset):
discrete_action=True, visual_inputs=1, num_agents=32, vec_obs_size=2 discrete_action=True, visual_inputs=1, num_agents=32, vec_obs_size=2
) )
env = AnimalAIEnvironment( env = AnimalAIEnvironment(file_name=" ", n_arenas=32, resolution=126,)
file_name=" ", n_arenas=32, camera_height=126, camera_width=512
)
assert env.get_agent_groups() == ["RealFakeBrain"] assert env.get_agent_groups() == ["RealFakeBrain"]
mock_launcher.assert_called_once() mock_launcher.assert_called_once()
launcher_args, _ = mock_launcher.call_args launcher_args, _ = mock_launcher.call_args
...@@ -44,9 +42,7 @@ def test_basic_initialization(mock_communicator, mock_launcher, mock_reset): ...@@ -44,9 +42,7 @@ def test_basic_initialization(mock_communicator, mock_launcher, mock_reset):
"0", "0",
"--numberOfArenas", "--numberOfArenas",
"32", "32",
"--cameraWidth", "--resolution",
"512",
"--cameraHeight",
"126", "126",
] ]
env.close() env.close()
......
...@@ -18,8 +18,7 @@ def create_environment_factory_aai( ...@@ -18,8 +18,7 @@ def create_environment_factory_aai(
start_port: int, start_port: int,
n_arenas_per_env: int, n_arenas_per_env: int,
arenas_configurations: ArenaConfig, arenas_configurations: ArenaConfig,
camera_width: Optional[int], resolution: Optional[int],
camera_height: Optional[int],
) -> Callable[[int, List[SideChannel]], BaseEnv]: ) -> Callable[[int, List[SideChannel]], BaseEnv]:
if env_path is not None: if env_path is not None:
launch_string = AnimalAIEnvironment.validate_environment_path(env_path) launch_string = AnimalAIEnvironment.validate_environment_path(env_path)
...@@ -53,8 +52,7 @@ def create_environment_factory_aai( ...@@ -53,8 +52,7 @@ def create_environment_factory_aai(
# docker_training=docker_training, # docker_training=docker_training,
n_arenas=n_arenas_per_env, n_arenas=n_arenas_per_env,
arenas_configurations=arenas_configurations, arenas_configurations=arenas_configurations,
camera_width=camera_width, resolution=resolution,
camera_height=camera_height,
side_channels=side_channels, side_channels=side_channels,
) )
......
...@@ -23,8 +23,7 @@ class RunOptionsAAI(NamedTuple): ...@@ -23,8 +23,7 @@ class RunOptionsAAI(NamedTuple):
height: int = 84 height: int = 84
n_arenas_per_env: int = 1 n_arenas_per_env: int = 1
arena_config: ArenaConfig = None arena_config: ArenaConfig = None
camera_width: int = 84 resolution: int = 84
camera_height: int = 84
""" """
trainer_config: Hyperparameters for your training model trainer_config: Hyperparameters for your training model
...@@ -46,6 +45,5 @@ class RunOptionsAAI(NamedTuple): ...@@ -46,6 +45,5 @@ class RunOptionsAAI(NamedTuple):
height: The height of the executable window of the environment(s) height: The height of the executable window of the environment(s)
n_arenas_per_env: Number of arenas (number of agents) per env environment instance n_arenas_per_env: Number of arenas (number of agents) per env environment instance
arena_config: Configuration file for the training arenas arena_config: Configuration file for the training arenas
camera_width: Width for the visual observation camera of the agent resolution: Resolution for the visual observation camera of the agent (NxN if resolution=N)
camera_height: Height for the visual observation camera of the agent
""" """
...@@ -60,8 +60,7 @@ def run_training_aai(run_seed: int, options: RunOptionsAAI) -> None: ...@@ -60,8 +60,7 @@ def run_training_aai(run_seed: int, options: RunOptionsAAI) -> None:
port, port,
options.n_arenas_per_env, options.n_arenas_per_env,
options.arena_config, options.arena_config,
options.camera_width, options.resolution,
options.camera_height,
) )
engine_config = EngineConfig( engine_config = EngineConfig(
options.width, options.width,
......
!ArenaConfig
arenas:
0: !Arena
pass_mark: -0.5
t: 250
items:
- !Item
name: Agent
positions:
- !Vector3 {x: 1, y: 0, z: 1}
rotations: [225]
- !Item
name: GoodGoalMulti
positions:
- !Vector3 {x: 39, y: 0, z: 39}
sizes:
- !Vector3 {x: .5, y: .5, z: .5}
\ No newline at end of file
!ArenaConfig
arenas:
0: !Arena
pass_mark: 4
t: 250
items:
- !Item
name: GoodGoalMulti
positions:
sizes:
- !Vector3 {x: 1, y: 1, z: 1}
- !Vector3 {x: 1, y: 1, z: 1}
- !Vector3 {x: 1, y: 1, z: 1}
- !Vector3 {x: 1, y: 1, z: 1}
- !Vector3 {x: 1, y: 1, z: 1}
\ No newline at end of file
!ArenaConfig
arenas:
0: !Arena
pass_mark: 0
t: 250
items:
- !Item
name: Agent
positions:
- !Vector3 {x: 20, y: 0, z: 5}
rotations: [0]
- !Item
name: Wall
positions:
- !Vector3 {x: 10, y: 0, z: 10.25}
- !Vector3 {x: 30, y: 0, z: 10.25}
- !Vector3 {x: 17.78, y: 0, z: 30}
- !Vector3 {x: 22.22, y: 0, z: 30}
rotations: [45, 135, 258.7, 101.3]
colors:
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
sizes:
- !Vector3 {x: 27.75, y: 5, z: .5}
- !Vector3 {x: 27.75, y: 5, z: .5}
- !Vector3 {x: 20, y: 5, z: .5}
- !Vector3 {x: 20, y: 5, z: .5}
- !Item
name: GoodGoal
positions:
- !Vector3 {x: 10, y: 0, z: 30}
sizes:
- !Vector3 {x: 1, y: 1, z: 1}
- !Item
name: BadGoal
positions:
- !Vector3 {x: 30, y: 0, z: 30}
sizes:
- !Vector3 {x: 1, y: 1, z: 1}
\ No newline at end of file
!ArenaConfig
arenas:
0: !Arena
pass_mark: 0
t: 250
items:
- !Item
name: Wall
positions:
- !Vector3 {x: 9.5, y: 0, z: 19}
- !Vector3 {x: 30.5, y: 0, z: 19}
rotations: [0,0]
sizes:
- !Vector3 {x: 19, y: 3, z: 38}
- !Vector3 {x: 19, y: 3, z: 38}
colors:
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !Item
name: GoodGoal
positions:
- !Vector3 {x: 1, y: 0, z: 39}
sizes:
- !Vector3 {x: 1, y: 1, z: 1}
- !Item
name: Agent
positions:
- !Vector3 {x: 20, y: 0, z: 1}
\ No newline at end of file
!ArenaConfig
arenas:
0: !Arena
pass_mark: 1
t: 500
items:
- !Item
name: Wall #Non-diag arms
positions:
- !Vector3 {x: 18, y: 0, z: 7.5}
- !Vector3 {x: 22, y: 0, z: 7.5}
- !Vector3 {x: 18, y: 0, z: 32.5}
- !Vector3 {x: 22, y: 0, z: 32.5}
- !Vector3 {x: 7.5, y: 0, z: 18}
- !Vector3 {x: 7.5, y: 0, z: 22}
- !Vector3 {x: 32.5, y: 0, z: 18}
- !Vector3 {x: 32.5, y: 0, z: 22}
rotations: [0,0,0,0,0,0,0,0]
sizes:
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 15, y: 3, z: 0.1}
- !Vector3 {x: 15, y: 3, z: 0.1}
- !Vector3 {x: 15, y: 3, z: 0.1}
- !Vector3 {x: 15, y: 3, z: 0.1}
colors:
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !Item
name: Wall #Non-diag backplates
positions:
- !Vector3 {x: 20, y: 0, z: 25.5}
- !Vector3 {x: 20, y: 0, z: 14.5}
- !Vector3 {x: 0.5, y: 0, z: 20}
- !Vector3 {x: 20, y: 0, z: 0.5}
- !Vector3 {x: 20, y: 0, z: 39.5}
- !Vector3 {x: 39.5, y: 0, z: 20}
rotations: [0,0,90,0,0,90]
sizes:
- !Vector3 {x: 3.9, y: 3, z: 1}
- !Vector3 {x: 3.9, y: 3, z: 1}
- !Vector3 {x: 3.9, y: 3, z: 1}
- !Vector3 {x: 3.9, y: 3, z: 1}
- !Vector3 {x: 3.9, y: 3, z: 1}
- !Vector3 {x: 3.9, y: 3, z: 1}
colors:
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !Item
name: Wall #Diag arms
positions:
- !Vector3 {x: 12.61, y: 0, z: 30.4}
- !Vector3 {x: 9.7, y: 0, z: 27.39}
- !Vector3 {x: 30.3, y: 0, z: 12.61}
- !Vector3 {x: 27.39, y: 0, z: 9.6}
- !Vector3 {x: 12.61, y: 0, z: 9.6}
- !Vector3 {x: 9.7, y: 0, z: 12.61}
- !Vector3 {x: 27.39, y: 0, z: 30.4}
- !Vector3 {x: 30.3, y: 0, z: 27.39}
rotations: [135,135,135,135,45,45,45,45]
sizes:
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 0.1, y: 3, z: 15}
colors:
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !Item
name: Wall #Diag Blocks
positions:
- !Vector3 {x: 16.045, y: 0, z: 24.005}
- !Vector3 {x: 23.955, y: 0, z: 15.995}
- !Vector3 {x: 16.045, y: 0, z: 15.995}
- !Vector3 {x: 23.955, y: 0, z: 24.005}
rotations: [135,315,45,225]
sizes:
- !Vector3 {x: 4, y: 3, z: 1}
- !Vector3 {x: 4, y: 3, z: 1}
- !Vector3 {x: 4, y: 3, z: 1}
- !Vector3 {x: 4, y: 3, z: 1}
colors:
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !Item
name: Wall #Diag backplates
positions:
- !Vector3 {x: 6, y: 0, z: 6}
- !Vector3 {x: 34, y: 0, z: 6}
- !Vector3 {x: 6, y: 0, z: 34}
- !Vector3 {x: 34, y: 0, z: 34}
rotations: [45,135,134,45]
sizes:
- !Vector3 {x: 4, y: 3, z: 1}
- !Vector3 {x: 4, y: 3, z: 1}
- !Vector3 {x: 4, y: 3, z: 1}
- !Vector3 {x: 4, y: 3, z: 1}
colors:
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !Item
name: GoodGoalMulti
positions:
- !Vector3 {x: 2, y: 0, z: 20}
- !Vector3 {x: 38, y: 0, z: 20}
sizes:
- !Vector3 {x: 1, y: 1, z: 1}
- !Vector3 {x: 1, y: 1, z: 1}
- !Item
name: Agent
positions:
- !Vector3 {x: 20, y: 0, z: 20}
\ No newline at end of file
!ArenaConfig
arenas:
0: !Arena
pass_mark: 2
t: 500
items:
- !Item
name: Wall
positions:
- !Vector3 {x: 20, y: 0, z: 22.5}
rotations: [0]
sizes:
- !Vector3 {x: 40, y: .6, z: 35}
colors:
- !RGB {r: 0, g: 0, b: 255}
- !Item
name: Ramp
positions:
- !Vector3 {x: 20, y: .6, z: 22.5}
rotations: [180]
sizes:
- !Vector3 {x: 40, y: 2, z: 35}
colors:
- !RGB {r: 255, g: 0, b: 255}
- !Item
name: Agent
positions:
- !Vector3 {x: 5, y: 0, z: 2.5}
rotations: [60]
- !Item
name: GoodGoal
positions:
- !Vector3 {x: 19, y: 3, z: 9}
sizes:
- !Vector3 {x: 3, y: 3, z: 3}
- !Item
name: GoodGoal
positions:
- !Vector3 {x: 38, y: 0, z: 2.5}
sizes:
- !Vector3 {x: 1, y: 1, z: 1}
!ArenaConfig
arenas:
0: !Arena
pass_mark: 0
t: 250
items:
- !Item
name: CylinderTunnelTransparent
positions:
- !Vector3 {x: 20, y: 0, z: 20}
- !Vector3 {x: 30, y: 0, z: 20}
- !Vector3 {x: 10, y: 0, z: 20}
rotations: [90,90,90]
sizes:
- !Vector3 {x: 10, y: 10, z: 10}
- !Vector3 {x: 10, y: 10, z: 10}
- !Vector3 {x: 10, y: 10, z: 10}
- !Item
name: GoodGoal
positions:
- !Vector3 {x: 20, y: 0, z: 20}
sizes:
- !Vector3 {x: 1, y: 1, z: 1}
- !Item
name: Agent
positions:
- !Vector3 {x: 20, y: 0, z: 1}
rotations: [0]
\ No newline at end of file
!ArenaConfig
arenas:
0: !Arena
pass_mark: 0
t: 250
items:
- !Item
name: Wall
positions:
- !Vector3 {x: 20, y: 0, z: 30}
rotations: [0]
sizes:
- !Vector3 {x: 40, y: 0.5, z: 20}
colors:
- !RGB {r: 0, g: 0, b: 255}
- !Item
name: Ramp
positions:
- !Vector3 {x: 35, y: 0, z: 18}
sizes:
- !Vector3 {x: 4, y: 0.5, z: 4}
rotations: [180]
colors:
- !RGB {r: 255, g: 0, b: 255}
- !Item
name: GoodGoal
positions:
- !Vector3 {x: 20, y: 0.5, z: 35}
sizes:
- !Vector3 {x: 1, y: 1, z: 1}
- !Item
name: Agent
positions:
- !Vector3 {x: 5, y: 0, z: 5}
rotations: [45]
\ No newline at end of file
!ArenaConfig
arenas:
0: !Arena
pass_mark: 0
t: 250
items:
- !Item
name: Cardbox1
positions:
- !Vector3 {x: 20, y: 0, z: 2.5}
- !Vector3 {x: 20, y: 0, z: 7.5}