File size: 26,677 Bytes
da2e2ac |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"https://raw.githubusercontent.com/autonomousvision/navsim/main/assets/navsim_transparent.png\" alt=\"drawing\" width=\"800\"/>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# NAVSIM Visualization Tutorial\n",
"\n",
"This notebook will introduce some basic plots to visualize the driving scenes in NAVSIM. All plots are created with `matplotlib` and are easy to customize for your application.\n",
"\n",
"## Table of Contents\n",
"1. [Config](#config)\n",
"2. [Birds-Eye-View](#bev)\n",
"3. [Cameras](#camera)\n",
"4. [Creating custom plots](#custom)\n",
"5. [Creating GIFs](#gifs)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Config <a name=\"config\"></a>\n",
"\n",
"NAVSIM offers two types of plots: \n",
"- Birds-Eye-View (BEV) plots or \n",
"- Camera plots. \n",
"\n",
"The LiDAR sensor can be visualized either in BEV or in camera images. All plots have a global configuration in [`navsim/visualization/config.py`](https://github.com/autonomousvision/navsim/blob/main/navsim/navsim/visualization/config.py). In this Python file, you can configure all colors or dimensions. The LiDAR point cloud can be colored in any colormap, showing the distance to the ego vehicle or the height of each point. In this tutorial, we first instantiate a `SceneFilter` and `SceneLoader` from the mini split."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-26T07:14:29.701597200Z",
"start_time": "2024-04-26T07:14:21.878449900Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Loading logs: 100%|ββββββββββ| 64/64 [00:06<00:00, 9.71it/s]\n"
]
}
],
"source": [
"from hydra.core.global_hydra import GlobalHydra\n",
"import os\n",
"from pathlib import Path\n",
"\n",
"import hydra\n",
"from hydra.utils import instantiate\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"from navsim.common.dataloader import SceneLoader\n",
"from navsim.common.dataclasses import SceneFilter, SensorConfig\n",
"GlobalHydra.instance().clear()\n",
"os.environ['OPENSCENE_DATA_ROOT'] = '/mnt/g/navsim/'\n",
"os.environ['NUPLAN_MAPS_ROOT'] = '/mnt/g/navsim/maps'\n",
"os.environ['NUPLAN_MAP_VERSION'] = \"nuplan-maps-v1.0\"\n",
"os.environ['NAVSIM_EXP_ROOT'] = '/mnt/g/navsim_exp'\n",
"os.environ['NAVSIM_DEVKIT_ROOT'] = '/mnt/f/e2e/navsim_ours'\n",
"\n",
"SPLIT = \"mini\" # [\"mini\", \"test\", \"trainval\"]\n",
"FILTER = \"all_scenes\"\n",
"\n",
"hydra.initialize(config_path=\"../navsim/planning/script/config/common/scene_filter\")\n",
"cfg = hydra.compose(config_name=FILTER)\n",
"scene_filter: SceneFilter = instantiate(cfg)\n",
"openscene_data_root = Path(os.getenv(\"OPENSCENE_DATA_ROOT\"))\n",
"\n",
"scene_loader = SceneLoader(\n",
" openscene_data_root / f\"navsim_logs/{SPLIT}\",\n",
" openscene_data_root / f\"sensor_blobs/{SPLIT}\",\n",
" scene_filter,\n",
" sensor_config=SensorConfig.build_all_sensors(),\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Birds-Eye-View <a name=\"bev\"></a>\n",
"\n",
"The Birds-Eye-View (BEV) visualization in NAVSIM is useful for overviewing the map, bounding-box annotations, or the LiDAR point cloud. In standard setting, the BEV plot includes a 64m $\\times$ 64m frame centered at the rear axle of the ego vehicle (excluding LiDAR for simplicity). First, we take a random token and load a scene to visualize."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-26T07:14:46.461456200Z",
"start_time": "2024-04-26T07:14:46.382458900Z"
}
},
"outputs": [
{
"ename": "TypeError",
"evalue": "stat: path should be string, bytes, os.PathLike or integer, not NoneType",
"output_type": "error",
"traceback": [
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
"\u001B[0;31mTypeError\u001B[0m Traceback (most recent call last)",
"Cell \u001B[0;32mIn[4], line 2\u001B[0m\n\u001B[1;32m 1\u001B[0m token \u001B[38;5;241m=\u001B[39m np\u001B[38;5;241m.\u001B[39mrandom\u001B[38;5;241m.\u001B[39mchoice(scene_loader\u001B[38;5;241m.\u001B[39mtokens)\n\u001B[0;32m----> 2\u001B[0m scene \u001B[38;5;241m=\u001B[39m \u001B[43mscene_loader\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mget_scene_from_token\u001B[49m\u001B[43m(\u001B[49m\u001B[43mtoken\u001B[49m\u001B[43m)\u001B[49m\n",
"File \u001B[0;32m/mnt/f/e2e/navsim_ours/navsim/common/dataloader.py:100\u001B[0m, in \u001B[0;36mSceneLoader.get_scene_from_token\u001B[0;34m(self, token)\u001B[0m\n\u001B[1;32m 98\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21mget_scene_from_token\u001B[39m(\u001B[38;5;28mself\u001B[39m, token: \u001B[38;5;28mstr\u001B[39m) \u001B[38;5;241m-\u001B[39m\u001B[38;5;241m>\u001B[39m Scene:\n\u001B[1;32m 99\u001B[0m \u001B[38;5;28;01massert\u001B[39;00m token \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mtokens\n\u001B[0;32m--> 100\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[43mScene\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mfrom_scene_dict_list\u001B[49m\u001B[43m(\u001B[49m\n\u001B[1;32m 101\u001B[0m \u001B[43m \u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mscene_frames_dicts\u001B[49m\u001B[43m[\u001B[49m\u001B[43mtoken\u001B[49m\u001B[43m]\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 102\u001B[0m \u001B[43m \u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_sensor_blobs_path\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 103\u001B[0m \u001B[43m \u001B[49m\u001B[43mnum_history_frames\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_scene_filter\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mnum_history_frames\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 104\u001B[0m \u001B[43m \u001B[49m\u001B[43mnum_future_frames\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_scene_filter\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mnum_future_frames\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 105\u001B[0m \u001B[43m \u001B[49m\u001B[43msensor_config\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_sensor_config\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 106\u001B[0m \u001B[43m \u001B[49m\u001B[43m)\u001B[49m\n",
"File \u001B[0;32m/mnt/f/e2e/navsim_ours/navsim/common/dataclasses.py:389\u001B[0m, in \u001B[0;36mScene.from_scene_dict_list\u001B[0;34m(cls, scene_dict_list, sensor_blobs_path, num_history_frames, num_future_frames, sensor_config)\u001B[0m\n\u001B[1;32m 379\u001B[0m \u001B[38;5;28;01massert\u001B[39;00m \u001B[38;5;28mlen\u001B[39m(scene_dict_list) \u001B[38;5;241m>\u001B[39m\u001B[38;5;241m=\u001B[39m \u001B[38;5;241m0\u001B[39m, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mScene list is empty!\u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[1;32m 381\u001B[0m scene_metadata \u001B[38;5;241m=\u001B[39m SceneMetadata(\n\u001B[1;32m 382\u001B[0m log_name\u001B[38;5;241m=\u001B[39mscene_dict_list[num_history_frames \u001B[38;5;241m-\u001B[39m \u001B[38;5;241m1\u001B[39m][\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mlog_name\u001B[39m\u001B[38;5;124m\"\u001B[39m],\n\u001B[1;32m 383\u001B[0m scene_token\u001B[38;5;241m=\u001B[39mscene_dict_list[num_history_frames \u001B[38;5;241m-\u001B[39m \u001B[38;5;241m1\u001B[39m][\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mscene_token\u001B[39m\u001B[38;5;124m\"\u001B[39m],\n\u001B[0;32m (...)\u001B[0m\n\u001B[1;32m 387\u001B[0m num_future_frames\u001B[38;5;241m=\u001B[39mnum_future_frames,\n\u001B[1;32m 388\u001B[0m )\n\u001B[0;32m--> 389\u001B[0m map_api \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;43mcls\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_build_map_api\u001B[49m\u001B[43m(\u001B[49m\u001B[43mscene_metadata\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mmap_name\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 391\u001B[0m frames: List[Frame] \u001B[38;5;241m=\u001B[39m []\n\u001B[1;32m 392\u001B[0m \u001B[38;5;28;01mfor\u001B[39;00m frame_idx \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28mrange\u001B[39m(\u001B[38;5;28mlen\u001B[39m(scene_dict_list)):\n",
"File \u001B[0;32m/mnt/f/e2e/navsim_ours/navsim/common/dataclasses.py:335\u001B[0m, in \u001B[0;36mScene._build_map_api\u001B[0;34m(cls, map_name)\u001B[0m\n\u001B[1;32m 330\u001B[0m \u001B[38;5;129m@classmethod\u001B[39m\n\u001B[1;32m 331\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21m_build_map_api\u001B[39m(\u001B[38;5;28mcls\u001B[39m, map_name: \u001B[38;5;28mstr\u001B[39m) \u001B[38;5;241m-\u001B[39m\u001B[38;5;241m>\u001B[39m AbstractMap:\n\u001B[1;32m 332\u001B[0m \u001B[38;5;28;01massert\u001B[39;00m (\n\u001B[1;32m 333\u001B[0m map_name \u001B[38;5;129;01min\u001B[39;00m MAP_LOCATIONS\n\u001B[1;32m 334\u001B[0m ), \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mThe map name \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mmap_name\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m is invalid, must be in \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mMAP_LOCATIONS\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m--> 335\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[43mget_maps_api\u001B[49m\u001B[43m(\u001B[49m\u001B[43mNUPLAN_MAPS_ROOT\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43mnuplan-maps-v1.0\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mmap_name\u001B[49m\u001B[43m)\u001B[49m\n",
"File \u001B[0;32m~/anaconda3/envs/navsim/lib/python3.9/site-packages/nuplan/common/maps/nuplan_map/map_factory.py:60\u001B[0m, in \u001B[0;36mget_maps_api\u001B[0;34m(map_root, map_version, map_name)\u001B[0m\n\u001B[1;32m 51\u001B[0m \u001B[38;5;129m@lru_cache\u001B[39m(maxsize\u001B[38;5;241m=\u001B[39m\u001B[38;5;241m32\u001B[39m)\n\u001B[1;32m 52\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21mget_maps_api\u001B[39m(map_root: \u001B[38;5;28mstr\u001B[39m, map_version: \u001B[38;5;28mstr\u001B[39m, map_name: \u001B[38;5;28mstr\u001B[39m) \u001B[38;5;241m-\u001B[39m\u001B[38;5;241m>\u001B[39m NuPlanMap:\n\u001B[1;32m 53\u001B[0m \u001B[38;5;250m \u001B[39m\u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[1;32m 54\u001B[0m \u001B[38;5;124;03m Get a NuPlanMap object corresponding to a particular set of parameters.\u001B[39;00m\n\u001B[1;32m 55\u001B[0m \u001B[38;5;124;03m :param map_root: The root folder for the map data.\u001B[39;00m\n\u001B[0;32m (...)\u001B[0m\n\u001B[1;32m 58\u001B[0m \u001B[38;5;124;03m :return: The loaded NuPlanMap object.\u001B[39;00m\n\u001B[1;32m 59\u001B[0m \u001B[38;5;124;03m \"\"\"\u001B[39;00m\n\u001B[0;32m---> 60\u001B[0m maps_db \u001B[38;5;241m=\u001B[39m \u001B[43mget_maps_db\u001B[49m\u001B[43m(\u001B[49m\u001B[43mmap_root\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mmap_version\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 61\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m NuPlanMap(maps_db, map_name\u001B[38;5;241m.\u001B[39mreplace(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m.gpkg\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m\"\u001B[39m))\n",
"File \u001B[0;32m~/anaconda3/envs/navsim/lib/python3.9/site-packages/nuplan/common/maps/nuplan_map/map_factory.py:48\u001B[0m, in \u001B[0;36mget_maps_db\u001B[0;34m(map_root, map_version)\u001B[0m\n\u001B[1;32m 40\u001B[0m \u001B[38;5;129m@lru_cache\u001B[39m(maxsize\u001B[38;5;241m=\u001B[39m\u001B[38;5;241m2\u001B[39m)\n\u001B[1;32m 41\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21mget_maps_db\u001B[39m(map_root: \u001B[38;5;28mstr\u001B[39m, map_version: \u001B[38;5;28mstr\u001B[39m) \u001B[38;5;241m-\u001B[39m\u001B[38;5;241m>\u001B[39m GPKGMapsDB:\n\u001B[1;32m 42\u001B[0m \u001B[38;5;250m \u001B[39m\u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[1;32m 43\u001B[0m \u001B[38;5;124;03m Get a maps_db from disk.\u001B[39;00m\n\u001B[1;32m 44\u001B[0m \u001B[38;5;124;03m :param map_root: The root folder for the map data.\u001B[39;00m\n\u001B[1;32m 45\u001B[0m \u001B[38;5;124;03m :param map_version: The version of the map to load.\u001B[39;00m\n\u001B[1;32m 46\u001B[0m \u001B[38;5;124;03m :return; The loaded MapsDB object.\u001B[39;00m\n\u001B[1;32m 47\u001B[0m \u001B[38;5;124;03m \"\"\"\u001B[39;00m\n\u001B[0;32m---> 48\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[43mGPKGMapsDB\u001B[49m\u001B[43m(\u001B[49m\u001B[43mmap_root\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mmap_root\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mmap_version\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mmap_version\u001B[49m\u001B[43m)\u001B[49m\n",
"File \u001B[0;32m~/anaconda3/envs/navsim/lib/python3.9/site-packages/nuplan/database/maps_db/gpkg_mapsdb.py:72\u001B[0m, in \u001B[0;36mGPKGMapsDB.__init__\u001B[0;34m(self, map_version, map_root)\u001B[0m\n\u001B[1;32m 69\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_map_version \u001B[38;5;241m=\u001B[39m map_version\n\u001B[1;32m 70\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_map_root \u001B[38;5;241m=\u001B[39m map_root\n\u001B[0;32m---> 72\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_blob_store \u001B[38;5;241m=\u001B[39m \u001B[43mBlobStoreCreator\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mcreate_mapsdb\u001B[49m\u001B[43m(\u001B[49m\u001B[43mmap_root\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_map_root\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 73\u001B[0m version_file \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_blob_store\u001B[38;5;241m.\u001B[39mget(\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;132;01m{\u001B[39;00m\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_map_version\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m.json\u001B[39m\u001B[38;5;124m\"\u001B[39m) \u001B[38;5;66;03m# get blob and save to disk\u001B[39;00m\n\u001B[1;32m 74\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_metadata \u001B[38;5;241m=\u001B[39m json\u001B[38;5;241m.\u001B[39mload(version_file)\n",
"File \u001B[0;32m~/anaconda3/envs/navsim/lib/python3.9/site-packages/nuplan/database/common/blob_store/creator.py:54\u001B[0m, in \u001B[0;36mBlobStoreCreator.create_mapsdb\u001B[0;34m(cls, map_root, verbose)\u001B[0m\n\u001B[1;32m 42\u001B[0m \u001B[38;5;250m\u001B[39m\u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[1;32m 43\u001B[0m \u001B[38;5;124;03mCreate Maps DB blob storage.\u001B[39;00m\n\u001B[1;32m 44\u001B[0m \n\u001B[0;32m (...)\u001B[0m\n\u001B[1;32m 47\u001B[0m \u001B[38;5;124;03m:return: Blob storage created.\u001B[39;00m\n\u001B[1;32m 48\u001B[0m \u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[1;32m 49\u001B[0m conf \u001B[38;5;241m=\u001B[39m RemoteConfig(\n\u001B[1;32m 50\u001B[0m http_root_url\u001B[38;5;241m=\u001B[39mos\u001B[38;5;241m.\u001B[39mgetenv(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mNUPLAN_MAPS_ROOT_HTTP_URL\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m\"\u001B[39m),\n\u001B[1;32m 51\u001B[0m s3_root_url\u001B[38;5;241m=\u001B[39mos\u001B[38;5;241m.\u001B[39mgetenv(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mNUPLAN_MAPS_ROOT_S3_URL\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m\"\u001B[39m),\n\u001B[1;32m 52\u001B[0m )\n\u001B[0;32m---> 54\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mcls\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mcreate\u001B[49m\u001B[43m(\u001B[49m\u001B[43mmap_root\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mconf\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mverbose\u001B[49m\u001B[43m)\u001B[49m\n",
"File \u001B[0;32m~/anaconda3/envs/navsim/lib/python3.9/site-packages/nuplan/database/common/blob_store/creator.py:76\u001B[0m, in \u001B[0;36mBlobStoreCreator.create\u001B[0;34m(cls, data_root, conf, verbose)\u001B[0m\n\u001B[1;32m 74\u001B[0m \u001B[38;5;28;01melif\u001B[39;00m NUPLAN_DATA_STORE \u001B[38;5;241m==\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mlocal\u001B[39m\u001B[38;5;124m\"\u001B[39m:\n\u001B[1;32m 75\u001B[0m logger\u001B[38;5;241m.\u001B[39mdebug(\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mUsing local disk store at \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mdata_root\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m with no remote store\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m---> 76\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[43mLocalStore\u001B[49m\u001B[43m(\u001B[49m\u001B[43mdata_root\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 77\u001B[0m \u001B[38;5;66;03m# Default to S3 if environment variable is empty or not set.\u001B[39;00m\n\u001B[1;32m 78\u001B[0m \u001B[38;5;28;01melif\u001B[39;00m NUPLAN_DATA_STORE \u001B[38;5;241m==\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124ms3\u001B[39m\u001B[38;5;124m\"\u001B[39m:\n",
"File \u001B[0;32m~/anaconda3/envs/navsim/lib/python3.9/site-packages/nuplan/database/common/blob_store/local_store.py:22\u001B[0m, in \u001B[0;36mLocalStore.__init__\u001B[0;34m(self, root_dir)\u001B[0m\n\u001B[1;32m 17\u001B[0m \u001B[38;5;250m\u001B[39m\u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[1;32m 18\u001B[0m \u001B[38;5;124;03mInitialize LocalStore.\u001B[39;00m\n\u001B[1;32m 19\u001B[0m \u001B[38;5;124;03m:param root_dir: Root directory containing the data.\u001B[39;00m\n\u001B[1;32m 20\u001B[0m \u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[1;32m 21\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_root_dir \u001B[38;5;241m=\u001B[39m root_dir\n\u001B[0;32m---> 22\u001B[0m \u001B[38;5;28;01massert\u001B[39;00m \u001B[43mos\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mpath\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43misdir\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_root_dir\u001B[49m\u001B[43m)\u001B[49m, \u001B[38;5;124m'\u001B[39m\u001B[38;5;132;01m%s\u001B[39;00m\u001B[38;5;124m does not exist!\u001B[39m\u001B[38;5;124m'\u001B[39m \u001B[38;5;241m%\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_root_dir\n\u001B[1;32m 23\u001B[0m \u001B[38;5;28;01massert\u001B[39;00m os\u001B[38;5;241m.\u001B[39maccess(\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_root_dir, os\u001B[38;5;241m.\u001B[39mR_OK \u001B[38;5;241m|\u001B[39m os\u001B[38;5;241m.\u001B[39mX_OK), \u001B[38;5;124m'\u001B[39m\u001B[38;5;124mcan not read from \u001B[39m\u001B[38;5;132;01m%s\u001B[39;00m\u001B[38;5;124m'\u001B[39m \u001B[38;5;241m%\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_root_dir\n",
"File \u001B[0;32m~/anaconda3/envs/navsim/lib/python3.9/genericpath.py:42\u001B[0m, in \u001B[0;36misdir\u001B[0;34m(s)\u001B[0m\n\u001B[1;32m 40\u001B[0m \u001B[38;5;250m\u001B[39m\u001B[38;5;124;03m\"\"\"Return true if the pathname refers to an existing directory.\"\"\"\u001B[39;00m\n\u001B[1;32m 41\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[0;32m---> 42\u001B[0m st \u001B[38;5;241m=\u001B[39m \u001B[43mos\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mstat\u001B[49m\u001B[43m(\u001B[49m\u001B[43ms\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 43\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m (\u001B[38;5;167;01mOSError\u001B[39;00m, \u001B[38;5;167;01mValueError\u001B[39;00m):\n\u001B[1;32m 44\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;01mFalse\u001B[39;00m\n",
"\u001B[0;31mTypeError\u001B[0m: stat: path should be string, bytes, os.PathLike or integer, not NoneType"
]
}
],
"source": [
"token = np.random.choice(scene_loader.tokens)\n",
"scene = scene_loader.get_scene_from_token(token)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The function `plot_bev_frame` takes a `Scene` and index of the step to visualize (history or future). "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from navsim.visualization.plots import plot_bev_frame\n",
"\n",
"frame_idx = scene.scene_metadata.num_history_frames - 1 # current frame\n",
"fig, ax = plot_bev_frame(scene, frame_idx)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The function `plot_bev_with_agent` visualizes the trajectory of an <span style=\"color:#DE7061\">agent</span> in comparison to the <span style=\"color:#59a14f\">human vehicle operator</span> at the current frame. This notebook shows an example of the naive `ConstantVelocityAgent`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from navsim.visualization.plots import plot_bev_with_agent\n",
"from navsim.agents.constant_velocity_agent import ConstantVelocityAgent\n",
"\n",
"agent = ConstantVelocityAgent()\n",
"fig, ax = plot_bev_with_agent(scene, agent)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Cameras <a name=\"bev\"></a>\n",
"\n",
"The agents in NAVSIM have access to eight cameras surrounding the vehicle. The function `plot_cameras_frame` shows the cameras in a 3 $\\times$ 3 grid with cameras in each direction of the ego-vehicle and the BEV plot in the center. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from navsim.visualization.plots import plot_cameras_frame\n",
"\n",
"fig, ax = plot_cameras_frame(scene, frame_idx)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"With `plot_cameras_frame_with_annotations`, you can visualize the bounding-box annotations in the camera images."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from navsim.visualization.plots import plot_cameras_frame_with_annotations\n",
"\n",
"fig, ax = plot_cameras_frame_with_annotations(scene, frame_idx)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"With `plot_cameras_frame_with_lidar`, you can visualize the LiDAR point cloud in the camera images."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from navsim.visualization.plots import plot_cameras_frame_with_lidar\n",
"\n",
"fig, ax = plot_cameras_frame_with_lidar(scene, frame_idx)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating custom plots <a name=\"custom\"></a>\n",
"\n",
"The plots in NAVSIM use `matplotlib` and either add elements to a `plt.Axes` object or return the full `plt.Figure`. Functions in [`navsim/visualization/`](https://github.com/autonomousvision/navsim/blob/main/navsim/navsim/visualization) can be re-used to create custom plots. In this example, we create a plot for the bounding-box annotations and the LiDAR point cloud."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from navsim.visualization.plots import configure_bev_ax\n",
"from navsim.visualization.bev import add_annotations_to_bev_ax, add_lidar_to_bev_ax\n",
"\n",
"\n",
"fig, ax = plt.subplots(1, 1, figsize=(6, 6))\n",
"\n",
"ax.set_title(\"Custom plot\")\n",
"\n",
"add_annotations_to_bev_ax(ax, scene.frames[frame_idx].annotations)\n",
"add_lidar_to_bev_ax(ax, scene.frames[frame_idx].lidar)\n",
"\n",
"# configures frame to BEV view\n",
"configure_bev_ax(ax)\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating GIFs <a name=\"gifs\"></a>\n",
"\n",
"You can transform frame-wise plots into short animated GIFs. Give any function to `frame_plot_to_gif`, which takes a `Scene` and `frame_idx` as input (ie. `plot_cameras_frame_with_annotations`)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from navsim.visualization.plots import frame_plot_to_gif\n",
"\n",
"frame_indices = [idx for idx in range(len(scene.frames))] # all frames in scene\n",
"file_name = f\"./{token}.gif\"\n",
"images = frame_plot_to_gif(file_name, plot_cameras_frame_with_annotations, scene, frame_indices)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "navsim",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.19"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|