Skip to content

Commit d2868a7

Browse files
committed
cam fill value option
1 parent d23d01d commit d2868a7

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

exts/nav_tasks/nav_tasks/mdp/observations/camera_observations.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222

2323

2424
def camera_image(
25-
env: ManagerBasedEnv, sensor_cfg: SceneEntityCfg, data_type: str = "distance_to_image_plane", flatten: bool = False
25+
env: ManagerBasedEnv,
26+
sensor_cfg: SceneEntityCfg,
27+
data_type: str = "distance_to_image_plane",
28+
flatten: bool = False,
29+
nan_fill_value: float | None = None,
2630
) -> torch.Tensor:
2731
"""Camera image Observations.
2832
@@ -34,6 +38,7 @@ def camera_image(
3438
sensor_cfg: The name of the sensor.
3539
data_type: The type of data to extract from the sensor. Default is "distance_to_image_plane".
3640
flatten: If True, the image will be flattened to 1D. Default is False.
41+
nan_fill_value: The value to fill nan/inf values with. If None, the maximum distance of the sensor will be used.
3742
3843
Returns:
3944
The image data."""
@@ -43,8 +48,9 @@ def camera_image(
4348
img = sensor.data.output[data_type].clone()
4449

4550
if data_type == "distance_to_image_plane":
46-
img[torch.isnan(img)] = sensor.cfg.max_distance
47-
img[torch.isinf(img)] = sensor.cfg.max_distance
51+
if nan_fill_value is None:
52+
nan_fill_value = sensor.cfg.max_distance
53+
img = torch.nan_to_num(img, nan=nan_fill_value, posinf=nan_fill_value, neginf=0.0)
4854

4955
# if type torch.uint8, convert to float and scale between 0 and 1
5056
if img.dtype == torch.uint8:

0 commit comments

Comments
 (0)