Skip to content

Commit 3c5b86d

Browse files
author
Miguel Alonso Jr
committed
Fixed failing python tests.
1 parent 565568c commit 3c5b86d

File tree

13 files changed

+38
-45
lines changed

13 files changed

+38
-45
lines changed

ml-agents-envs/mlagents_envs/rpc_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ def process_pixels(
122122
image = Image.open(image_fp)
123123
# Normally Image loads lazily, load() forces it to do loading in the timer scope.
124124
image.load()
125-
image_arrays.append(np.moveaxis(np.array(image, dtype=np.float32) / 255.0, -1, 0))
125+
image_arrays.append(
126+
np.moveaxis(np.array(image, dtype=np.float32) / 255.0, -1, 0)
127+
)
126128

127129
# Look for the next header, starting from the current stream location
128130
try:

ml-agents/mlagents/trainers/tests/mock_brain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def setup_test_behavior_specs(
212212
action_spec = ActionSpec.create_discrete(tuple(vector_action_space))
213213
else:
214214
action_spec = ActionSpec.create_continuous(vector_action_space)
215-
observation_shapes = [(84, 84, 3)] * int(use_visual) + [(vector_obs_space,)]
215+
observation_shapes = [(3, 84, 84)] * int(use_visual) + [(vector_obs_space,)]
216216
obs_spec = create_observation_specs_with_shapes(observation_shapes)
217217
behavior_spec = BehaviorSpec(obs_spec, action_spec)
218218
return behavior_spec
Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
{
2-
"param_1": {
3-
"lesson_num": 2
4-
},
5-
"param_2": {
6-
"lesson_num": 0
7-
},
8-
"param_3": {
9-
"lesson_num": 0
10-
},
112
"metadata": {
123
"stats_format_version": "0.3.0",
13-
"mlagents_version": "0.29.0",
14-
"torch_version": "1.8.1"
4+
"mlagents_version": "0.31.0.dev0",
5+
"torch_version": "1.11.0+cu102"
156
}
16-
}
7+
}

ml-agents/mlagents/trainers/tests/simple_test_envs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from mlagents.trainers.tests.dummy_config import create_observation_specs_with_shapes
2121

2222
OBS_SIZE = 1
23-
VIS_OBS_SIZE = (20, 20, 3)
23+
VIS_OBS_SIZE = (3, 20, 20)
2424
VAR_LEN_SIZE = (10, 5)
2525
STEP_SIZE = 0.2
2626

ml-agents/mlagents/trainers/tests/test_rpc_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def generate_compressed_data(in_array: np.ndarray) -> bytes:
6969
num_images = (num_channels + 2) // 3
7070
# Split the input image into batches of 3 channels.
7171
for i in range(num_images):
72-
sub_image = image_arr[3 * i: 3 * i + 3, ...]
72+
sub_image = image_arr[3 * i : 3 * i + 3, ...]
7373
if (i == num_images - 1) and (num_channels % 3) != 0:
7474
# Pad zeros
7575
zero_shape = list(in_array.shape)

ml-agents/mlagents/trainers/tests/torch_entities/test_encoders.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_vector_encoder(mock_normalizer):
7373
mock_normalizer_inst.copy_from.assert_called_with(mock_normalizer_inst)
7474

7575

76-
@pytest.mark.parametrize("image_size", [(36, 36, 3), (84, 84, 4), (256, 256, 5)])
76+
@pytest.mark.parametrize("image_size", [(3, 36, 36), (4, 84, 84), (5, 256, 256)])
7777
@pytest.mark.parametrize(
7878
"vis_class",
7979
[
@@ -86,7 +86,7 @@ def test_vector_encoder(mock_normalizer):
8686
)
8787
def test_visual_encoder(vis_class, image_size):
8888
num_outputs = 128
89-
enc = vis_class(image_size[0], image_size[1], image_size[2], num_outputs)
89+
enc = vis_class(image_size[1], image_size[2], image_size[0], num_outputs)
9090
# Note: NCHW not NHWC
9191
sample_input = torch.ones((1, image_size[0], image_size[1], image_size[2]))
9292
encoding = enc(sample_input)
@@ -106,17 +106,17 @@ def test_visual_encoder(vis_class, image_size):
106106
@pytest.mark.slow
107107
def test_visual_encoder_trains(vis_class, size):
108108
torch.manual_seed(0)
109-
image_size = (size, size, 1)
109+
image_size = (1, size, size)
110110
batch = 100
111111

112112
inputs = torch.cat(
113113
[torch.zeros((batch,) + image_size), torch.ones((batch,) + image_size)], dim=0
114114
)
115115
target = torch.cat([torch.zeros((batch,)), torch.ones((batch,))], dim=0)
116-
enc = vis_class(image_size[0], image_size[1], image_size[2], 1)
116+
enc = vis_class(image_size[1], image_size[2], image_size[0], 1)
117117
optimizer = torch.optim.Adam(enc.parameters(), lr=0.001)
118118

119-
for _ in range(15):
119+
for _ in range(25):
120120
prediction = enc(inputs)[:, 0]
121121
loss = torch.mean((target - prediction) ** 2)
122122
optimizer.zero_grad()

ml-agents/mlagents/trainers/tests/torch_entities/test_hybrid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_hybrid_ppo(action_size):
3333
PPO_TORCH_CONFIG,
3434
hyperparameters=new_hyperparams,
3535
network_settings=new_network_settings,
36-
max_steps=10000,
36+
max_steps=20000,
3737
)
3838
check_environment_trains(env, {BRAIN_NAME: config}, success_threshold=0.9)
3939

@@ -90,7 +90,7 @@ def test_hybrid_sac(action_size):
9090
buffer_init_steps=0,
9191
)
9292
config = attr.evolve(
93-
SAC_TORCH_CONFIG, hyperparameters=new_hyperparams, max_steps=4000
93+
SAC_TORCH_CONFIG, hyperparameters=new_hyperparams, max_steps=8000
9494
)
9595
check_environment_trains(env, {BRAIN_NAME: config}, success_threshold=0.9)
9696

ml-agents/mlagents/trainers/tests/torch_entities/test_networks.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ def test_networkbody_lstm():
7474
def test_networkbody_visual():
7575
torch.manual_seed(1)
7676
vec_obs_size = 4
77-
obs_size = (84, 84, 3)
77+
obs_size = (3, 84, 84)
7878
network_settings = NetworkSettings()
7979
obs_shapes = [(vec_obs_size,), obs_size]
8080

8181
networkbody = NetworkBody(
8282
create_observation_specs_with_shapes(obs_shapes), network_settings
8383
)
8484
optimizer = torch.optim.Adam(networkbody.parameters(), lr=3e-3)
85-
sample_obs = 0.1 * torch.ones((1, 84, 84, 3), dtype=torch.float32)
85+
sample_obs = 0.1 * torch.ones((1, 3, 84, 84), dtype=torch.float32)
8686
sample_vec_obs = torch.ones((1, vec_obs_size), dtype=torch.float32)
8787
obs = [sample_vec_obs] + [sample_obs]
8888
loss = 1
@@ -200,7 +200,7 @@ def test_multinetworkbody_visual(with_actions):
200200
act_size = 2
201201
n_agents = 3
202202
obs_size = 4
203-
vis_obs_size = (84, 84, 3)
203+
vis_obs_size = (3, 84, 84)
204204
network_settings = NetworkSettings()
205205
obs_shapes = [(obs_size,), vis_obs_size]
206206
action_spec = ActionSpec(act_size, tuple(act_size for _ in range(act_size)))
@@ -209,7 +209,7 @@ def test_multinetworkbody_visual(with_actions):
209209
)
210210
optimizer = torch.optim.Adam(networkbody.parameters(), lr=3e-3)
211211
sample_obs = [
212-
[0.1 * torch.ones((1, obs_size))] + [0.1 * torch.ones((1, 84, 84, 3))]
212+
[0.1 * torch.ones((1, obs_size))] + [0.1 * torch.ones((1, 3, 84, 84))]
213213
for _ in range(n_agents)
214214
]
215215
# simulate baseline in POCA
@@ -273,7 +273,7 @@ def test_valuenetwork():
273273
@pytest.mark.parametrize("lstm", [True, False])
274274
def test_actor_critic(lstm, shared):
275275
obs_size = 4
276-
vis_obs_size = (84, 84, 3)
276+
vis_obs_size = (3, 84, 84)
277277
network_settings = NetworkSettings(
278278
memory=NetworkSettings.MemorySettings() if lstm else None, normalize=True
279279
)
@@ -291,14 +291,14 @@ def test_actor_critic(lstm, shared):
291291
critic = ValueNetwork(stream_names, obs_spec, network_settings)
292292
if lstm:
293293
sample_vis_obs = torch.ones(
294-
(network_settings.memory.sequence_length, 84, 84, 3), dtype=torch.float32
294+
(network_settings.memory.sequence_length, 3, 84, 84), dtype=torch.float32
295295
)
296296
sample_obs = torch.ones((network_settings.memory.sequence_length, obs_size))
297297
memories = torch.ones(
298298
(1, network_settings.memory.sequence_length, actor.memory_size)
299299
)
300300
else:
301-
sample_vis_obs = 0.1 * torch.ones((1, 84, 84, 3), dtype=torch.float32)
301+
sample_vis_obs = 0.1 * torch.ones((1, 3, 84, 84), dtype=torch.float32)
302302
sample_obs = torch.ones((1, obs_size))
303303
memories = torch.tensor([])
304304
# memories isn't always set to None, the network should be able to

ml-agents/mlagents/trainers/tests/torch_entities/test_reward_providers/test_curiosity.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ def test_construction(behavior_spec: BehaviorSpec) -> None:
4747
create_observation_specs_with_shapes([(10,)]), ACTIONSPEC_CONTINUOUS
4848
),
4949
BehaviorSpec(
50-
create_observation_specs_with_shapes([(10,), (64, 66, 3), (84, 86, 1)]),
50+
create_observation_specs_with_shapes([(10,), (3, 64, 66), (1, 84, 86)]),
5151
ACTIONSPEC_CONTINUOUS,
5252
),
5353
BehaviorSpec(
54-
create_observation_specs_with_shapes([(10,), (64, 66, 1)]),
54+
create_observation_specs_with_shapes([(10,), (1, 64, 66)]),
5555
ACTIONSPEC_TWODISCRETE,
5656
),
5757
BehaviorSpec(
@@ -72,7 +72,7 @@ def test_factory(behavior_spec: BehaviorSpec) -> None:
7272
"behavior_spec",
7373
[
7474
BehaviorSpec(
75-
create_observation_specs_with_shapes([(10,), (64, 66, 3), (24, 26, 1)]),
75+
create_observation_specs_with_shapes([(10,), (3, 64, 66), (1, 24, 26)]),
7676
ACTIONSPEC_CONTINUOUS,
7777
),
7878
BehaviorSpec(
@@ -125,7 +125,7 @@ def test_continuous_action_prediction(behavior_spec: BehaviorSpec, seed: int) ->
125125
"behavior_spec",
126126
[
127127
BehaviorSpec(
128-
create_observation_specs_with_shapes([(10,), (64, 66, 3), (24, 26, 1)]),
128+
create_observation_specs_with_shapes([(10,), (3, 64, 66), (1, 24, 26)]),
129129
ACTIONSPEC_CONTINUOUS,
130130
),
131131
BehaviorSpec(

ml-agents/mlagents/trainers/tests/torch_entities/test_reward_providers/test_gail.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test_factory(behavior_spec: BehaviorSpec) -> None:
6161
"behavior_spec",
6262
[
6363
BehaviorSpec(
64-
create_observation_specs_with_shapes([(8,), (24, 26, 1)]),
64+
create_observation_specs_with_shapes([(8,), (1, 24, 26)]),
6565
ACTIONSPEC_CONTINUOUS,
6666
),
6767
BehaviorSpec(
@@ -116,7 +116,7 @@ def test_reward_decreases(
116116
"behavior_spec",
117117
[
118118
BehaviorSpec(
119-
create_observation_specs_with_shapes([(8,), (24, 26, 1)]),
119+
create_observation_specs_with_shapes([(8,), (1, 24, 26)]),
120120
ACTIONSPEC_CONTINUOUS,
121121
),
122122
BehaviorSpec(

0 commit comments

Comments
 (0)