Skip to content

Commit

Permalink
update edt loading to consider creation time
Browse files Browse the repository at this point in the history
  • Loading branch information
hzheng40 committed May 3, 2024
1 parent 0f995f9 commit 0c82a66
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions gym/f110_gym/envs/track/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pathlib
from dataclasses import dataclass
from typing import Tuple, Optional
import os

import numpy as np
import yaml
Expand Down Expand Up @@ -130,11 +131,17 @@ def from_track_name(track: str):
occupancy_map[occupancy_map <= 128] = 0.0
occupancy_map[occupancy_map > 128] = 255.0

# if exists, load edt
if (track_dir / f"{track}_map.npy").exists():
# if exists and it has been created for the current map image, load edt
map_filepath = (track_dir / map_filename).absolute()
track_filepath = map_filepath.with_suffix("")
edt_filepath = track_dir / f"{track}_map.npy"
if edt_filepath.exists() and os.path.getmtime(edt_filepath) >= os.path.getmtime(map_filepath):
edt = np.load(track_dir / f"{track}_map.npy")
else:
edt = None
from scipy.ndimage import distance_transform_edt as edt
resolution = track_spec.resolution
edt = resolution * edt(occupancy_map)
np.save(track_filepath, edt)

# if exists, load centerline
if (track_dir / f"{track}_centerline.csv").exists():
Expand Down

0 comments on commit 0c82a66

Please sign in to comment.