motional / nuplan-devkit

The devkit of the nuPlan dataset.
https://www.nuplan.org
Other
662 stars 126 forks source link

RasterIO fail to read the given map.gpkg file #299

Closed TL-QZ closed 1 year ago

TL-QZ commented 1 year ago

Describe the bug

Greetings, I encountered this RasterIO bug while trying to load drivable area raster map using the map class in "scenario.map_api" ("nuplan.common.maps.nuplan_map.nuplan_map.NuPlanMap" class) . It seems the driverable_area raster layer is only provided for "us-nv-las-vegas-strip" via. a 'drivable_area.npy.npz' file. This file is not provided for other 3 maps (Singapore, Boston and Pittsburgh). The class then automatically tries to load the drivable raster layer by reading from the 'map.gpkg' file using the RasterIO package. But it seems the RasterIO package used in your provided code framework won't be able to read the gpkg file.

Setup

system setup OS: Ubuntu 20.04.4 LTS conda environment: setup by following the provided nuplan setup procedure

Steps To Reproduce

Steps to reproduce the behavior:

  1. while the dataloader try to load an instance on NON Las Vegas instance and calling the following
  2. def get_features_from_scenario(self, scenario: AbstractScenario): map_api = scenario.map_api raster_map = map_api.get_raster_map_layer(SemanticMapLayer.DRIVABLE_AREA)
  3. The NuPlan map class with try to load the .npz file but if no such file exist, it will try to open the 'map.gpkg' file using nuplan.database.maps_db.gpkg_mapsdb.GPKGMapsDB._get_map_dataset() function and causes this error while doing 'rasterio.open(path_on_disk)', where "path_on_disk = '/common/home/ql236/nuplan/dataset/maps/us-ma-boston/9.12.1817/map.gpkg'"

Stack Trace

Traceback (most recent call last):
Exception has occurred: RuntimeError
Caught RuntimeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "rasterio/_base.pyx", line 308, in rasterio._base.DatasetBase.__init__
  File "rasterio/_base.pyx", line 219, in rasterio._base.open_dataset
  File "rasterio/_err.pyx", line 221, in rasterio._err.exc_wrap_pointer
rasterio._err.CPLE_OpenFailedError: '/common/home/ql236/nuplan/dataset/maps/us-ma-boston/9.12.1817/map.gpkg' not recognized as a supported file format.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/common/home/ql236/nuplan-devkit-master/nuplan/planning/training/preprocessing/feature_preprocessor.py", line 93, in compute_features
    all_features, all_feature_cache_metadata = self._compute_all_features(scenario, self._feature_builders)
  File "/common/home/ql236/nuplan-devkit-master/nuplan/planning/training/preprocessing/feature_preprocessor.py", line 122, in _compute_all_features
    feature, feature_metadata_entry = compute_or_load_feature(
  File "/common/home/ql236/nuplan-devkit-master/nuplan/planning/training/preprocessing/utils/utils_cache.py", line 69, in compute_or_load_feature
    feature = builder.get_features_from_scenario(scenario)
  File "/common/home/ql236/nuplan-devkit-master/nuplan/planning/training/preprocessing/feature_builders/muse_feature_builder.py", line 104, in get_features_from_scenario
    return self._compute_feature(sampled_past_ego_states, sampled_past_observations, time_stamps, map_api, fut_ego_states)
  File "/common/home/ql236/nuplan-devkit-master/nuplan/planning/training/preprocessing/feature_builders/muse_feature_builder.py", line 188, in _compute_feature
    local_ic, local_map, local_homo = build_local_map(self.num_past_poses, all_traj, map_api,self.map_size,compute_homo)
  File "/common/home/ql236/nuplan-devkit-master/nuplan/planning/training/preprocessing/features/muse/muse_utils.py", line 9, in build_local_map
    raster_map = map_api.get_raster_map_layer(SemanticMapLayer.DRIVABLE_AREA)
  File "/common/home/ql236/nuplan-devkit-master/nuplan/common/maps/nuplan_map/nuplan_map.py", line 107, in get_raster_map_layer
    return self._load_raster_layer(layer_id)
  File "/common/home/ql236/nuplan-devkit-master/nuplan/common/maps/nuplan_map/nuplan_map.py", line 282, in _load_raster_layer
    map_layer: MapLayer = self._maps_db.load_layer(self._map_name, layer_name)
  File "/common/home/ql236/nuplan-devkit-master/nuplan/database/maps_db/gpkg_mapsdb.py", line 173, in load_layer
    layer_data = self._get_layer_matrix(location, layer_name)
  File "/common/home/ql236/nuplan-devkit-master/nuplan/database/maps_db/gpkg_mapsdb.py", line 426, in _get_layer_matrix
    self._save_layer_matrix(location=location, layer_name=layer_name)
  File "/common/home/ql236/nuplan-devkit-master/nuplan/database/maps_db/gpkg_mapsdb.py", line 438, in _save_layer_matrix
    with self.get_layer_dataset(location, layer_name) as layer_dataset:
  File "/common/home/ql236/nuplan-devkit-master/nuplan/database/maps_db/gpkg_mapsdb.py", line 313, in get_layer_dataset
    with self._get_map_dataset(location) as map_dataset:
  File "/common/home/ql236/nuplan-devkit-master/nuplan/database/maps_db/gpkg_mapsdb.py", line 303, in _get_map_dataset
    return rasterio.open(path_on_disk)
  File "/common/home/ql236/miniconda3/envs/nuplan/lib/python3.9/site-packages/rasterio/env.py", line 451, in wrapper
    return f(*args, **kwds)
  File "/common/home/ql236/miniconda3/envs/nuplan/lib/python3.9/site-packages/rasterio/__init__.py", line 304, in open
    dataset = DatasetReader(path, driver=driver, sharing=sharing, **kwargs)
  File "rasterio/_base.pyx", line 310, in rasterio._base.DatasetBase.__init__
rasterio.errors.RasterioIOError: '/common/home/ql236/nuplan/dataset/maps/us-ma-boston/9.12.1817/map.gpkg' not recognized as a supported file format.

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

I want to ask if I could change the function here and use other package like geoPanda to read the map file and get the raster layer. Will that cause my submission not be able to run in your test environment?

Or should I get the drivable area from the vector map ?

Or if there is any workaround suggested will be appreciated?

i understand similar issue has been rased in #248 and #235 but there were no usable solution from those two previously raised issues. Thanks in advance for your help.

patk-motional commented 1 year ago

Hi @tommieeee,

I was able to recreate the issue. Can you limit to working with the las vegas until we can find a fix?

TL-QZ commented 1 year ago

Yes, I was able to create a work around to bypass this error for now to work on other parts of my training pipeline. Thank you for the speedy response. Please let me know if there is any update on this issue.

And just to add a note that the las vegas drivable area raster map seems to be correct with the map itself and the transformation matrix and other meta data.

patk-motional commented 1 year ago

Hi @tommieeee,

Can you try installing rasterio==1.3.3?

pip install rasterio==1.3.3
TL-QZ commented 1 year ago

Hi @patk-motional,

It seems to be working. Thank you for your help! I will close this issue for now.

Thanks again, T