Skip to content

Commit

Permalink
Fixing Spelling error in 'appned' and adding test (facebookresearch#280)
Browse files Browse the repository at this point in the history
fix for facebookresearch#278 reported by @saketd403. and added test for test_observations_to_image
  • Loading branch information
mathfac authored Jan 19, 2020
1 parent a1ef13a commit 44c8be1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
7 changes: 3 additions & 4 deletions habitat/utils/visualizations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ def draw_collision(view: np.ndarray, alpha: float = 0.4) -> np.ndarray:
Returns:
A view with collision effect drawn.
"""
size = view.shape[0]
strip_width = size // 20
mask = np.ones((size, size))
strip_width = view.shape[0] // 20
mask = np.ones(view.shape)
mask[strip_width:-strip_width, strip_width:-strip_width] = 0
mask = mask == 1
view[mask] = (alpha * np.array([255, 0, 0]) + (1.0 - alpha) * view)[mask]
Expand Down Expand Up @@ -174,7 +173,7 @@ def observations_to_image(observation: Dict, info: Dict) -> np.ndarray:
observation_size = observation["depth"].shape[0]
depth_map = (observation["depth"].squeeze() * 255).astype(np.uint8)
depth_map = np.stack([depth_map for _ in range(3)], axis=2)
egocentric_view.appned(depth_map)
egocentric_view.append(depth_map)

assert (
len(egocentric_view) > 0
Expand Down
33 changes: 33 additions & 0 deletions test/test_visual_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3

# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import numpy as np

from habitat.utils.visualizations.utils import observations_to_image


def test_observations_to_image():
observations = {
"rgb": np.random.rand(200, 400, 3),
"depth": np.random.rand(200, 400, 1),
}
info = {
"collisions": {"is_collision": True},
"top_down_map": {
"map": np.random.randint(low=0, high=255, size=(300, 300)),
"fog_of_war_mask": np.random.randint(
low=0, high=1, size=(300, 300)
),
"agent_map_coord": (10, 10),
"agent_angle": np.random.random(),
},
}
image = observations_to_image(observations, info)
assert image.shape == (
200,
1000,
3,
), "Resulted image resolution doesn't match."

0 comments on commit 44c8be1

Please sign in to comment.