๐ก ํ ์ค ์์ฝ#
BEVFormer๋ ์๊ณต๊ฐ ํธ๋์คํฌ๋จธ(Spatial-Temporal Transformer) ๊ตฌ์กฐ๋ฅผ ์ด์ฉํด ๋ช ์์ ๊น์ด ์ถ์ ์์ด ๋ค์ค ์นด๋ฉ๋ผ 2D ์ด๋ฏธ์ง์์ BEV(Bird’s-Eye-View) 3D ํํ์ ์ง์ ๊ตฌ์ถํ๊ณ , ์ด์ ํ๋ ์ BEV์ ego-motion ์ ๋ ฌ ๋ฐ ์ฌ๊ท์ ์ตํฉ์ ํตํด nuScenes ํ ์คํธ์ 56.9% NDS๋ก LiDAR๊ธ 3D ๊ฐ์ฒด ํ์ง ์ฑ๋ฅ์ ๋ฌ์ฑํ๋ค.
๐ ๊ฐ์ ๋ฐ ํต์ฌ ๊ธฐ์ฌ (Key Contributions)#
- ์ ์: Zhiqi Li, Wenhai Wang, Hongyang Li, Enze Xie, Chonghao Sima, Tong Lu, Yu Qiao, Jifeng Dai (Nanjing Univ., Shanghai AI Lab, HKU)
- ๋ฐํ๋ ๋: 2022 (arXiv:2203.17270, ECCV 2022)
- ์ฃผ์ ๊ธฐ์ฌ์ :
- Spatial Cross-Attention (SCA): ๊น์ด ์์ธก ์ค์ฐจ๋ฅผ ํผํ๊ธฐ ์ํด ๊ฐ BEV ์ฟผ๋ฆฌ ํฝ์ ์์ $N_z$๊ฐ ๋์ด ๋ฐฉํฅ์ 3D Pillar Anchor ์ ์ ์ํ๋งํ ํ, 2D ์นด๋ฉ๋ผ ํ๋ฉด์ผ๋ก ํฌ์ํ์ฌ Deformable Cross-Attention์ผ๋ก ๋ค์ค ์นด๋ฉ๋ผ ํน์ง์ ํตํฉ.
- Temporal Self-Attention (TSA): ๊ณผ๊ฑฐ ํ๋ ์์ BEV ํน์ง์ ์์ฐจ ์ด๋(Ego-motion) ํ๋ ฌ๋ก ๋ณด์ ยท์ ๋ ฌ(Warping)ํ ํ ํ์ฌ BEV ์ฟผ๋ฆฌ์ ์ตํฉํ์ฌ ์๋ ์ถ์ ๋ฐ ์ฌ๋ฌผ ๊ฐ๋ฆผ(Occlusion) ํด๊ฒฐ.
- ํตํฉ ๋ฉํฐํ์คํฌ 3D ํค๋: ํ๋์ BEV ์ธ์ฝ๋ ์ถ๋ ฅ์ผ๋ก 3D ๊ฐ์ฒด ํ์ง(Bounding Box)์ HD ๋งต ๋ถํ (Map Segmentation)์ ์ ๋ฐ ์ํ.
๐ฏ ๊ด๋ จ ์ฐ๊ตฌ ํ๋ฆ ๋ฐ ๊ธฐ์กด ํ๊ณ (Related Work & Motivation)#
๊ด๋ จ ์ฐ๊ตฌ ํ๋ฆ#
- DETR3D: 3D Object Query๋ฅผ ์ด๋ฏธ์ง์ ์ญํฌ์ํ์ฌ ํน์ง์ ํ๋ํ๋ BEV ํ๋ฉด ํํ์ด ๋ถ์์ ํจ.
- LSS (Lift-Splat-Shoot): ๊น์ด ๋ถํฌ๋ฅผ ์ถ์ ํ์ฌ 3D Frustum์ผ๋ก ์ฌ์ํ๋, ๊น์ด ์์ธก์ ์ค์ฐจ๊ฐ BEV ํน์ง ์๊ณก์ผ๋ก ๋์ ๋จ.
- BEVFormer: ๋ช ์์ ๊น์ด ์ถ์ ๋จ๊ณ๋ฅผ ์ ๊ฑฐํ๊ณ , 3D Pillar Anchor ์ํ๋ง๊ณผ ์๊ณต๊ฐ Transformer ์ดํ ์ ์ผ๋ก ๊น์ด ์ค์ฐจ ๋ฐ ์ฐ์ ํ๋ ์ ์ ๋ณด ๋๋ฝ ๋ฌธ์ ๋ฅผ ์๋ฒฝํ ํด๊ฒฐ.
๐ ๋ชฉ์ฐจ#
- Chapter 1: BEV Query ๋ฐ 3D Pillar ์ขํ๊ณ ์ ์
- Chapter 2: Spatial Cross-Attention (SCA) ๋ฐ ์นด๋ฉ๋ผ ์ญํฌ์ ์์
- Chapter 3: Temporal Self-Attention (TSA) ๋ฐ Ego-Motion ๋ณด์ ์ ๋ ฌ
- Chapter 4: 2D Deformable Attention ์์ ๋ฐ ๊ตฌํ
- Chapter 5: ์ฃผ์ ์คํ ๋ฐ ๊ฒฐ๊ณผ
- Chapter 6: ๊ฒฐ๋ก ๋ฐ ์์ฌ์
๐ ๏ธ Chapter 1: BEV Query ๋ฐ 3D Pillar ์ขํ๊ณ ์ ์#
1. ์์ฝ#
์์ฐจ(Ego) ๊ธฐ์ค 2D BEV ๊ทธ๋ฆฌ๋๋ฅผ $H \times W$ ๊ฒฉ์๋ก ๋ถํ ํ๊ณ , ๊ฐ ์ ๋ง๋ค ํ์ต ๊ฐ๋ฅํ ์ฟผ๋ฆฌ $Q_{x, y} \in \mathbb{R}^C$๋ฅผ ๋ฐฐ์นํฉ๋๋ค. 2D ์ฟผ๋ฆฌ ์ $(x, y)$๋ ๋์ด ์ถ ๋ฐฉํฅ $z \in [z_{\min}, z_{\max}]$๋ก ํ์ฅ๋์ด 3D Pillar ํํ์ ์ต์ปค ์ ๋ค์ ํ์ฑํฉ๋๋ค.
๐ ๏ธ Chapter 2: Spatial Cross-Attention (SCA)#
1. ์์ฝ#
BEV ์ฟผ๋ฆฌ $Q_p$์ ๋ํด $N_z$๊ฐ์ ๋์ด ์ต์ปค ์ ์ 3D ์์์ ์ ์ํ๊ณ , ์ด๋ฅผ 6๊ฐ ์นด๋ฉ๋ผ์ 2D ์์ผ๊ฐ์ผ๋ก ํฌ์ํฉ๋๋ค. ์ค์ ๋ก ํฌ์๋ ํํธ ์นด๋ฉ๋ผ ๋ทฐ $\mathcal{V}_{\text{hit}}$์ ์ด๋ฏธ์ง ํน์ง $F_t^i$์ ๋ํด Deformable Attention์ ์ํํฉ๋๋ค.
2. ์์ ๋ฐ ํ์ด์ฌ ์ฝ๋ ์ค๋ช #
3D Pillar $\to$ 2D ์นด๋ฉ๋ผ ํ๋ฉด ํฌ์ ๊ณต์#
$$z_{i,j} \begin{bmatrix} u_{i,j} \\ v_{i,j} \\ 1 \end{bmatrix} = \mathbf{P}_i \begin{bmatrix} x' \\ y' \\ z'_j \\ 1 \end{bmatrix} = \mathbf{K}_i \left( \mathbf{R}_i \begin{bmatrix} x' \\ y' \\ z'_j \end{bmatrix} + \mathbf{t}_i \right)$$$$\text{SCA}(Q_p, F_t) = \frac{1}{|\mathcal{V}_{\text{hit}}|} \sum_{i \in \mathcal{V}_{\text{hit}}} \sum_{j=1}^{N_z} \text{DeformAttn}\Big( Q_p, \ \mathcal{P}(p, i, j), \ F_t^i \Big)$$- $\mathcal{P}(p, i, j) = (u_{i,j}, v_{i,j})$: BEV ์ $p=(x, y)$์ $j$๋ฒ์งธ ๋์ด ์ต์ปค ์ ์ด $i$๋ฒ์งธ ์นด๋ฉ๋ผ์ ํฌ์๋ 2D ํฝ์ ์ขํ
- $\mathbf{P}_i$: $i$๋ฒ์งธ ์นด๋ฉ๋ผ์ $3 \times 4$ ํฌ์ ํ๋ ฌ
import torch
def project_bev_pillar_to_camera(
bev_grid_coords: torch.Tensor, # (H, W, 2) BEV 2D ๊ทธ๋ฆฌ๋ ์ขํ (x, y)
anchor_heights: torch.Tensor, # (Nz,) ๋์ด ์ต์ปค ๊ฐ๋ค (์: -5m ~ 3m ์ฌ์ด 4๊ฐ ์ )
P_cam: torch.Tensor, # (3, 4) 3D World to 2D Image ํฌ์ ํ๋ ฌ
img_shape: tuple # (H_img, W_img)
) -> tuple:
"""
BEV ์ฟผ๋ฆฌ ํฝ์
์ 3D Pillar ๋์ด ์ต์ปค์ ๋ค์ 2D ์นด๋ฉ๋ผ ํฝ์
์ขํ๋ก ํฌ์
"""
H, W, _ = bev_grid_coords.shape
Nz = len(anchor_heights)
H_img, W_img = img_shape
# 1. (H, W, Nz, 3) 3D Pillar ์ขํ ์์ฑ (x, y, z)
bev_x = bev_grid_coords[..., 0].unsqueeze(-1).repeat(1, 1, Nz)
bev_y = bev_grid_coords[..., 1].unsqueeze(-1).repeat(1, 1, Nz)
bev_z = anchor_heights.view(1, 1, Nz).repeat(H, W, 1)
pts_3d_homo = torch.stack([bev_x, bev_y, bev_z, torch.ones_like(bev_x)], dim=-1) # (H, W, Nz, 4)
# 2. 2D ์นด๋ฉ๋ผ ํฌ์ p_2d = P_cam @ p_3d
pts_2d_homo = torch.matmul(pts_3d_homo, P_cam.T) # (H, W, Nz, 3)
depths = pts_2d_homo[..., 2]
u = pts_2d_homo[..., 0] / (depths + 1e-6)
v = pts_2d_homo[..., 1] / (depths + 1e-6)
# 3. Valid Mask (์ ๋ฐฉ depth > 0 ๋ฐ ์ด๋ฏธ์ง ํฝ์
๋ด ์ ํจ์ฑ)
valid_mask = (depths > 0.1) & (u >= 0) & (u < W_img) & (v >= 0) & (v < H_img)
# [0, 1] ๋ฒ์๋ก ์ ๊ทํ๋ 2D Reference Coordinates
norm_u = u / W_img
norm_v = v / H_img
return torch.stack([norm_u, norm_v], dim=-1), valid_mask
# --- ์ฌ์ฉ ์์ ---
grid = torch.meshgrid(torch.linspace(-50, 50, 10), torch.linspace(-50, 50, 10), indexing='ij')
grid_coords = torch.stack(grid, dim=-1) # (10, 10, 2)
heights = torch.tensor([-2.0, 0.0, 2.0])
P_dummy = torch.eye(4)[:3, :]
uv_norm, mask = project_bev_pillar_to_camera(grid_coords, heights, P_dummy, (480, 640))
print("ํฌ์๋ ์ ๊ทํ 2D ์ขํ Shape:", uv_norm.shape)๐ ๏ธ Chapter 3: Temporal Self-Attention (TSA) ๋ฐ Ego-Motion ์ ๋ ฌ#
1. ์์ฝ#
๊ณผ๊ฑฐ ํ๋ ์์ BEV ํน์ง $B_{t-1}$์ ์์ฐจ ์ด๋ ๋ณํ ํ๋ ฌ $\mathbf{T}_{t-1 \to t}$๋ฅผ ์ฌ์ฉํ์ฌ ํ์ฌ ํ๋ ์ ์์ฐจ ์ขํ๊ณ๋ก ์ํ(Warping)ํ ํ, ํ์ฌ BEV ์ฟผ๋ฆฌ $Q$์ Deformable Self-Attention์ผ๋ก ํฉ์ฑํ์ฌ ์๋ ์ถ์ ์ ์ ๋ฐํํฉ๋๋ค.
2. ์์ ๋ฐ ํ์ด์ฌ ์ฝ๋ ์ค๋ช #
$$p_{t-1} = \mathbf{T}_{t-1 \to t}^{-1} \cdot p_t$$$$B'_{t-1} = \text{GridSample}\Big( B_{t-1}, \ p_{t-1} \Big)$$$$\text{TSA}(Q_p, \{Q, B'_{t-1}\}) = \sum_{V \in \{Q, B'_{t-1}\}} \text{DeformAttn}\Big( Q_p, p, V \Big)$$import torch
import torch.nn.functional as F
def align_previous_bev_feature(
prev_bev: torch.Tensor, # (B, C, H, W) ์ด์ ํ๋ ์ BEV ํน์ง
T_prev2curr: torch.Tensor, # (B, 4, 4) ์ด์ ->ํ์ฌ ์์ฐจ Ego-Motion ๋ณํ ํ๋ ฌ
grid_resolution: float = 0.5 # ๊ทธ๋ฆฌ๋ 1์
๋น ์ค์ ๊ฑฐ๋ฆฌ (m)
) -> torch.Tensor:
"""
Ego-Motion ๋ณด์ ์ ํตํ ๊ณผ๊ฑฐ BEV ํน์ง๋งต์ ํ์ฌ ์ขํ๊ณ ๊ณต๊ฐ ์ํ(Warping)
"""
B, C, H, W = prev_bev.shape
# 1. ํ์ฌ BEV ๊ทธ๋ฆฌ๋ 2D ์ขํ ์์ฑ
xs = torch.linspace(-W/2 * grid_resolution, W/2 * grid_resolution, W)
ys = torch.linspace(-H/2 * grid_resolution, H/2 * grid_resolution, H)
grid_y, grid_x = torch.meshgrid(ys, xs, indexing='ij')
# Homo 3D ์ขํ (X, Y, 0, 1)
pts_curr = torch.stack([grid_x, grid_y, torch.zeros_like(grid_x), torch.ones_like(grid_x)], dim=-1) # (H, W, 4)
pts_curr = pts_curr.unsqueeze(0).repeat(B, 1, 1, 1) # (B, H, W, 4)
# 2. ์ญ๋ณํ์ผ๋ก ์ด์ ์ขํ๊ณ์์์ ์์น ๊ณ์ฐ: p_prev = T_{curr->prev} @ p_curr
T_curr2prev = torch.linalg.inv(T_prev2curr)
pts_prev = torch.matmul(pts_curr, T_curr2prev.transpose(-2, -1)) # (B, H, W, 4)
# 3. [-1, 1] ๋ฒ์๋ก Grid Sample ์ ๊ทํ
norm_x = (pts_prev[..., 0] / (W/2 * grid_resolution))
norm_y = (pts_prev[..., 1] / (H/2 * grid_resolution))
grid_sample_norm = torch.stack([norm_x, norm_y], dim=-1) # (B, H, W, 2)
# 4. ์ด์ BEV ํน์ง ์ํ ์ํ๋ง
aligned_prev_bev = F.grid_sample(prev_bev, grid_sample_norm, mode='bilinear', align_corners=True)
return aligned_prev_bev
# --- ์ฌ์ฉ ์์ ---
prev_b = torch.randn(1, 256, 50, 50)
T_dummy = torch.eye(4)
T_dummy[0, 3] = 1.5 # X ๋ฐฉํฅ 1.5m ์ฐจ๋ ์ด๋
print("Ego-Motion ์ ๋ ฌ๋ ๊ณผ๊ฑฐ BEV Shape:", align_previous_bev_feature(prev_b, T_dummy.unsqueeze(0)).shape)๐ ๏ธ Chapter 4: Deformable Attention ์ฐ์ฐ ๊ตฌ์กฐ#
1. ์์ฝ#
๊ธ๋ก๋ฒ Attention์ ์ฐ์ฐ๋ ํญ๋ฐ์ ๋ฐฉ์งํ๊ธฐ ์ํด ์ฟผ๋ฆฌ ์ง์ ์ฃผ๋ณ์ $K$๊ฐ ์คํ์ ์์น๋ง ์ดํ ์ ํ๋ Deformable Attention์ ์ฌ์ฉํฉ๋๋ค.
2. ์์ ๋ฐ ํ์ด์ฌ ์ฝ๋ ์ค๋ช #
$$\text{DeformAttn}(q, p, x) = \sum_{m=1}^{M} \mathbf{W}_m \sum_{k=1}^{K} A_{m,k} \cdot \mathbf{W}'_m x(p + \Delta p_{m,k})$$import torch
import torch.nn as nn
import torch.nn.functional as F
class DeformableAttention2D(nn.Module):
"""
์์ K๊ฐ ์คํ์
์ง์ ๋ง ์ดํ
์
ํ๋ ๊ณ ์ 2D Deformable Attention
"""
def __init__(self, embed_dim: int = 256, num_heads: int = 8, num_keys: int = 4):
super().__init__()
self.num_heads = num_heads
self.num_keys = num_keys
self.scale = (embed_dim // num_heads) ** -0.5
# ์คํ์
delta_p ๋ฐ ๊ฐ์ค์น A ์์ฑ ํค๋
self.offset_head = nn.Linear(embed_dim, num_heads * num_keys * 2)
self.weight_head = nn.Linear(embed_dim, num_heads * num_keys)
self.value_proj = nn.Linear(embed_dim, embed_dim)
def forward(self, query: torch.Tensor, value_feat: torch.Tensor) -> torch.Tensor:
"""
query: (B, N_q, C)
value_feat: (B, C, H, W)
"""
B, N_q, C = query.shape
head_dim = C // self.num_heads
offsets = self.offset_head(query).view(B, N_q, self.num_heads, self.num_keys, 2)
weights = torch.softmax(self.weight_head(query).view(B, N_q, self.num_heads, self.num_keys), dim=-1)
# ํค๋๋ณ๋ก value_feat์ (B*num_heads, head_dim, H, W)๋ก ์ฌ๋ฐฐ์นํด grid_sample๋ก ์ค์ ์คํ์
์์น๋ฅผ ์ํ๋ง
v = self.value_proj(value_feat.flatten(2).transpose(1, 2)) # (B, H*W, C)
H, W = value_feat.shape[-2:]
v = v.transpose(1, 2).reshape(B, self.num_heads, head_dim, H, W)
v = v.reshape(B * self.num_heads, head_dim, H, W)
grid = offsets.clamp(-1, 1).permute(0, 2, 1, 3, 4).reshape(B * self.num_heads, N_q, self.num_keys, 2)
sampled = F.grid_sample(v, grid, align_corners=False) # (B*num_heads, head_dim, N_q, num_keys)
sampled = sampled.view(B, self.num_heads, head_dim, N_q, self.num_keys).permute(0, 3, 1, 4, 2)
# ์์ธก๋ ์ดํ
์
๊ฐ์ค์น(weights)๋ก K๊ฐ ์ํ ์ง์ ์ ๊ฐ์คํฉ
out = (sampled * weights.unsqueeze(-1)).sum(dim=3) # (B, N_q, num_heads, head_dim)
return out.reshape(B, N_q, C)
# --- ์ฌ์ฉ ์์ ---
q = torch.randn(1, 100, 256)
val = torch.randn(1, 256, 32, 32)
attn = DeformableAttention2D()
print("Deformable Attention ์ถ๋ ฅ Shape:", attn(q, val).shape)๐ ์ฃผ์ ์คํ ๋ฐ ๊ฒฐ๊ณผ (Experiments & Results)#
1. nuScenes 3D ๊ฐ์ฒด ํ์ง ์ฑ๋ฅ ๋น๊ต#
| ๋ฐฉ๋ฒ (Method) | ์ ๋ ฅ ์ผ์ ๋ชจ๋ฌ๋ฆฌํฐ | NDS โ | mAP โ | mAVE (์๋ ์ค์ฐจ) โ |
|---|---|---|---|---|
| FCOS3D | Camera | 0.428 | 0.358 | 1.14 |
| DETR3D | Camera | 0.479 | 0.412 | 0.84 |
| BEVDet | Camera | 0.488 | 0.424 | 0.328 |
| BEVFormer-S (๋จ์ผ ํ๋ ์) | Camera | 0.448 | 0.375 | 0.802 |
| BEVFormer (์๊ณต๊ฐ ์ตํฉ) | Camera | 0.569 | 0.481 | 0.394 (์ ๋ฐ ๊ฐ์) |
| SSN | LiDAR | 0.569 | 0.463 | 0.280 |
- ๊ฒฐ๊ณผ: ์๊ฐ ์ ๋ณด(TSA) ์ ์ฉ ์ ์๋ ์ค์ฐจ(mAVE)๊ฐ 0.802 $\to$ 0.394๋ก ์ ๋ฐ ์ด์ ๊ฐ์ํ์์ผ๋ฉฐ, ์นด๋ฉ๋ผ ์ ์ฉ ์ต์ด๋ก LiDAR ๊ธฐ๋ฐ SSN๊ณผ ๋๋ฑํ 56.9% NDS ๋ฌ์ฑ.
๐ก ๊ฒฐ๋ก ๋ฐ ์์ฌ์ (Conclusion & Insights)#
1. ๊ฒฐ๋ก #
BEVFormer๋ ๋ช ์์ ๊น์ด ์ถ์ ์ค์ฐจ๋ฅผ 3D Pillar Anchor ์ํ๋ง์ผ๋ก ์ฐํํ๊ณ ๊ณผ๊ฑฐ ํ๋ ์ BEV ์ ๋ ฌ๋ก ์๊ณต๊ฐ์ ํตํฉํ modern ์์จ์ฃผํ BEV ํธ๋์คํฌ๋จธ ํ์ค ์ํคํ ์ฒ์ ๋๋ค.
2. ํ๊ณ์ ๋ฐ ์์ฌ์ด ์ #
- ์นด๋ฉ๋ผ ๊ธฐ๋ฐ ๋ฐฉ๋ฒ์ ์ฌ์ ํ LiDAR ๋๋น ํจ์จ์ฑ๊ณผ ์ ํ๋์์ ๊ฒฉ์ฐจ๊ฐ ์์ผ๋ฉฐ, 2D ์ด๋ฏธ์ง์์ ์ ํํ 3D ์์น๋ฅผ ์ถ๋ก ํ๋ ๋ฌธ์ ๋ ๊ทผ๋ณธ์ ๊ณผ์ ๋ก ๋จ์์๋ค.
- 6๊ฐ ์ธ์ฝ๋ ๋ ์ด์ด์ ๋ค์ค anchor height ์ํ๋ง์ผ๋ก ์ธํ ์ฐ์ฐ ๋น์ฉ์ด ์ ์ง ์์, ์๋ฒ ๋๋ ํ๊ฒฝ์์์ ์ค์๊ฐ์ฑ ํ๋ณด๋ ๋ณ๋ ๊ฒ์ฆ์ด ํ์ํ๋ค.
์ฐธ๊ณ ์๋ฃ#
๊ด๋ จ ๋ ผ๋ฌธ: Attention Is All You Need, Lift Splat Shoot, BEVDepth, DETR3D, BEVFusion, nuScenes