[Navsim] visualization

ad_official·2025년 2월 23일
0

[AD] dataset

목록 보기
12/12



0. 들어가기 전에

Scene

  • Scene 객체는 하나의 주행 시나리오 전체를 담고 있는 컨테이너
  • 이 객체에는
    • 여러 프레임(시간 순서대로 정렬된 센서 데이터, 이미지, LiDAR 정보 등)과
    • 각 프레임에 해당하는 주석(바운딩 박스, 객체 정보 등), 그리고
    • 시나리오 전반에 걸친 메타데이터(토큰, 타임스탬프, 주행 상황 정보 등)가 포함
  • 즉, Scene 객체를 통해 자율 주행 알고리즘은 특정 시나리오의 전체 정보를 한 번에 불러와서 시뮬레이션, 평가, 혹은 시각화에 활용할 수 있어.


SceneFilter

  • 주행 장면(시나리오)을 선별하는 역할을 합니다.
  • 예를 들어, 여러 로그나 토큰 중에서 평가나 학습에 적합한 장면들만 골라내는 기준을 설정합니다.


SceneLoader

  • 이 필터 기준(SceneFilter)에 따라, 실제 데이터(센서 데이터, 주석 정보 등)를 디스크에서 읽어와서 하나의 "Scene" 객체로 만들어주는 역할
  • 즉, SceneFilter가 "어떤 장면을 사용할지" 결정하면, SceneLoader는 "그 장면의 구체적인 데이터를 어떻게 불러올지" 담당



1. Config

  • navsim은 2가지 plots을 제공함
    • BEV
    • camera
  • LiDAR sensor 은 BEV / camera plot 모두에서 visualize 가능하다!
  • 모든 plot은 navsim/visualization/config.py 에 global configuration을 가지고 있다.
    • 모든 colors와 dimensions를 configure 할 수 있다.
    • lidar point cloud
      • 자차와의 거리에 따라 색깔 바뀌거나,
      • 각 포인트의 높이에 따라 색깔 바뀌거나



2. Birds-Eye-View

  • BB annotation / Lidar pcl 등을 볼 수 있음
  • 기본 세팅
    • 자차 뒷바퀴 기준 64 m by 64 m 영역
    • Lidar pcl은 기본적으로 제외
  • scene (여러 프레임) 에 agent를 함꼐 그리고 싶으면, 아래와 같이 해라.
    • TODO: agent는 매번 움직일텐데, 이를 어떻게 반영할까?
from navsim.visualization.plots import plot_bev_with_agent
from navsim.agents.constant_velocity_agent import ConstantVelocityAgent

token = np.random.choice(scene_loader.tokens)
scene = scene_loader.get_scene_from_token(token)

agent = ConstantVelocityAgent()
fig, ax = plot_bev_with_agent(scene, agent)
plt.show()



3. Cameras

  • 3 by 3 화면으로 구성한다.
    • 중앙은: BEV plot
    • 나머지 8개: 카메라
from navsim.visualization.plots import plot_cameras_frame

fig, ax = plot_cameras_frame(scene, frame_idx)
plt.show()
  • camera image에 bounding box annotation과 함꼐 보고싶으면
from navsim.visualization.plots import plot_cameras_frame_with_annotations

fig, ax = plot_cameras_frame_with_annotations(scene, frame_idx)
plt.show()
  • camera image에 lidar pointcloud와 함꼐 보고싶으면
from navsim.visualization.plots import plot_cameras_frame_with_lidar

fig, ax = plot_cameras_frame_with_lidar(scene, frame_idx)
plt.show()



4. Creating custom plots

4.1. 들어가기 전에, 참고

import matplotlib.pyplot as plt

# 하나의 플롯 생성: fig는 Figure 객체, ax는 단일 Axes 객체
# 하나의 플롯만 생성하면 ax는 단일 Axes 객체
fig, ax = plt.subplots(1, 1, figsize=(6, 6))

# 여러 개의 플롯 생성 예시 (2행 2열)
# 여러 서브 플롯을 생성하면 ax는 Axes 객체들의 배열(리스트나 numpy 배열)
fig, axs = plt.subplots(2, 2, figsize=(10, 8))

Figure (plt.Figure)

  • Figure는 전체 그림(캔버스)
  • 하나의 Figure 안에는 여러 개의 Axes(서브 플롯)나 기타 그림 요소(제목, 범례, 색상바 등)가 들어갈 수 있습니다.

Axes (plt.Axes)

  • Axes는 실제 데이터를 시각화하는 영역
  • 보통 하나의 Axes는 하나의 플롯(예: 선 그래프, 산점도, 막대 그래프 등)을 나타냄
  • 중요한 점은 "Axes"가 단순히 x축, y축만을 의미하는 것이 아니라,
    • 그래프 전체의 데이터 영역, 축, 레이블, 제목 등을 모두 포함하는 컨테이너라는 것


4.2. BEV(bounding box+lidar)

from navsim.visualization.plots import configure_bev_ax
from navsim.visualization.bev import add_annotations_to_bev_ax, add_lidar_to_bev_ax


fig, ax = plt.subplots(1, 1, figsize=(6, 6))

ax.set_title("Custom plot")

add_annotations_to_bev_ax(ax, scene.frames[frame_idx].annotations)
add_lidar_to_bev_ax(ax, scene.frames[frame_idx].lidar)

# configures frame to BEV view
configure_bev_ax(ax)

plt.show()



5. Creating GIFs

from navsim.visualization.plots import plot_cameras_frame_with_annotations
from navsim.visualization.plots import frame_plot_to_gif
"""
fig, ax = plot_cameras_frame_with_annotations(scene, frame_idx)
plt.show()
"""
frame_indices = [idx for idx in range(len(scene.frames))]  # all frames in scene
file_name = f"./{token}.gif"
images = frame_plot_to_gif(file_name, plot_cameras_frame_with_annotations, scene, frame_indices)



6. 내가 원하는 그림

  • BEV map
from navsim.visualization.plots import plot_bev_with_agent
from navsim.agents.constant_velocity_agent import ConstantVelocityAgent
"""
agent = ConstantVelocityAgent()
fig, ax = plot_bev_with_agent(scene, agent)
plt.show()
"""
from navsim.visualization.plots import frame_plot_to_gif
frame_indices = [idx for idx in range(len(scene.frames))]  # all frames in scene
file_name = f"./{token}.gif"
images = frame_plot_to_gif(file_name, plot_cameras_frame_with_annotations, scene, frame_indices)


코드 점검

  • N개의 시나리오(scene)을 모두 테스트한다.
  • 근데 CPU core 개수만큼 나눠서 병렬로 테스트한다.
  • visualize 결과
    • 현재는 시나리오의 첫 프레임만 그릴 수 있게 되어 있다.
    • TODO: 이를 매 프레임으로 바꿔주는걸 해보자.


이를 매 프레임으로 바꿔주는걸 해보자.

profile
ad_official

0개의 댓글