py123d_detection.torch.models.bevformer.camera_embedding¶
Telling a BEVFormer head which camera a feature came from.
The paper adds a learned vector per camera to the image features before the BEV encoder, so the encoder can treat the front camera differently from the rear one. That table is indexed by camera position, which locks a model to one rig: train with it on nuScenes’ six cameras and the weights mean nothing on Argoverse’s seven.
"none" is therefore the right choice for cross-dataset training, and "bevformer" for
reproducing the paper on a single dataset. The embedding is added once, before the encoder, which
is where the official implementation puts it.
Module Attributes
Accepted values of |
Functions
|
Build the per-camera embedding a BEVFormer head adds to its features. |
Classes
|
BEVFormer's own learnable per-camera embedding. |
|
Abstract base. |
- py123d_detection.torch.models.bevformer.camera_embedding.VALID_CAM_EMBED_TYPES = ('none', 'bevformer')¶
Accepted values of
cam_embed_type.
- class py123d_detection.torch.models.bevformer.camera_embedding.CameraEmbedding(*args, **kwargs)[source]¶
Bases:
ModuleAbstract base. Forward returns a tensor to be ADDED to
image_features(same shape(B, N, embed_dims, H, W)).
- class py123d_detection.torch.models.bevformer.camera_embedding.BEVFormerCamEmbed(num_cameras, embed_dims)[source]¶
Bases:
CameraEmbeddingBEVFormer’s own learnable per-camera embedding.
This is the
cams_embedsparameter of the official implementation’s transformer: one vector per camera, normal-initialised, broadcast-added to that camera’s features.The table is indexed by camera position, so the number of cameras is fixed at construction and a batch with a different
Nraises rather than silently reusing the wrong rows. That is the official design, and the error is the point: these weights mean nothing on another rig.There is one FPN level here, so there are no
level_embedsto go with it. Adding multi-scale features later means adding both parameters together, since the official code adds them in the same place.- Parameters:
- py123d_detection.torch.models.bevformer.camera_embedding.build_camera_embedding(cam_embed_type, *, embed_dims, num_cameras)[source]¶
Build the per-camera embedding a BEVFormer head adds to its features.
- Parameters:
cam_embed_type (
str) –"bevformer"for the paper’s learned per-camera token, or"none". The learned token is indexed by camera position, so it fixes the model to one rig;"none"is what lets a model train across datasets with different camera counts.num_cameras (
int) – Size of the learned table. Only meaningful for"bevformer".
- Return type: