Skip to content

Conversation

SamratThapa120
Copy link
Collaborator

@SamratThapa120 SamratThapa120 commented Sep 9, 2025

This pull request introduces several improvements to the BEVFusion deployment pipeline, particularly for ONNX export. The changes focus on refactoring the model's forward and feature extraction logic to better handle image features, updating deployment configs for more flexible input shapes, and fixing geometry computation in the depth module. These updates enhance the modularity and exportability of the BEVFusion model, facilitating more efficient deployment and inference.

Model code refactoring and ONNX export support:

  • The bevfusion-cl model is split into two parts in deployment: image_backbone and main_body. The image_backbone takes the image input and outputs the features, the main_body does the rest of the predictions.

  • Removed the old deployment scripts.

  • Refactored BEVFusion model methods (_forward, predict, loss, and extract_feat) to consistently accept a new using_image_features flag, improving control over whether to use precomputed image features during inference or export. Added a new get_image_backbone_features helper to modularize image feature extraction. [1] [2] [3] [4] [5] [6] [7] [8] [9]

  • Updated the logic in extract_feat to handle ONNX inference mode, including geometry feature handling and disabling point features when necessary. [1] [2]

Deployment configuration updates:

  • Updated bevfusion_camera_backbone_tensorrt_dynamic.py and bevfusion_main_body_with_image_tensorrt_dynamic.py to use more flexible and parameterized input shapes (e.g., image_dims, depth_bins, feature_dims). Expanded the set of dynamic axes and input names to support a wider range of deployment scenarios, and added missing inputs required for the main body with image features. [1] [2] [3] [4] [5] [6]

  • Adjusted bevfusion_main_body_lidar_only_tensorrt_dynamic.py to update the expected voxel and coordinate shapes for lidar-only inference.

Depth module geometry computation fix:

  • Fixed the placement of geometry computation logic in depth_lss.py, ensuring that transformations and matrix inverses are only computed when not using precomputed geometry features. [1] [2]

Documentation updates:

  • Updated README.md deployment command examples to include the --module argument, clarifying how to export specific model components. [1] [2]

Note to reviewer.

Please try running the deployment script, using models included in this PR #88

@SamratThapa120 SamratThapa120 changed the title feat(fix): fix bevfusion ci deployment script feat(fix): fix bevfusion deployment script Sep 9, 2025
@SamratThapa120 SamratThapa120 marked this pull request as ready for review September 9, 2025 01:19

feats = feats.sum(dim=1, keepdim=False) / sizes.type_as(feats).view(-1, 1)
# feats = batch_inputs_dict["voxels"]["voxels"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

@@ -15,8 +15,8 @@
model_inputs=[
dict(
input_shapes=dict(
voxels=dict(min_shape=[1, 5], opt_shape=[64000, 5], max_shape=[256000, 5]),
coors=dict(min_shape=[1, 4], opt_shape=[64000, 4], max_shape=[256000, 4]),
voxels=dict(min_shape=[1, 10, 4], opt_shape=[64000, 10, 4], max_shape=[256000, 10, 4]),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shape should be [M, maximum number of points, features], which it will be [M, 10, 5] if we are using intensity right?

export_params=True,
input_names=input_names,
output_names=output_names,
opset_version=opset_version,
dynamic_axes=dynamic_axes,
keep_initializers_as_inputs=keep_initializers_as_inputs,
verbose=verbose,
do_constant_folding=False,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why disable though? I believe the constant_folding can speed up inference

@@ -18,7 +21,35 @@
voxels=dict(min_shape=[1, 10, 4], opt_shape=[64000, 10, 4], max_shape=[256000, 10, 4]),
coors=dict(min_shape=[1, 3], opt_shape=[64000, 3], max_shape=[256000, 3]),
num_points_per_voxel=dict(min_shape=[1], opt_shape=[64000], max_shape=[256000]),
image_feats=dict(min_shape=[80, 180, 180], opt_shape=[80, 180, 180], max_shape=[80, 180, 180]),
# TODO(TIERIV): Optimize. Now, using points will increase latency significantly
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to put TODO(YourName)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it because we want to compute depth map so we need to input points? This will actually run internal voxelization again in here
https://github.com/tier4/AWML/blob/main/projects/BEVFusion/bevfusion/bevfusion.py#L172

Copy link
Collaborator

@KSeangTan KSeangTan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall, thanks for the great work. I believe we need to further tidy up the code a bit more in another PR

@@ -18,7 +21,35 @@
voxels=dict(min_shape=[1, 10, 4], opt_shape=[64000, 10, 4], max_shape=[256000, 10, 4]),
coors=dict(min_shape=[1, 3], opt_shape=[64000, 3], max_shape=[256000, 3]),
num_points_per_voxel=dict(min_shape=[1], opt_shape=[64000], max_shape=[256000]),
image_feats=dict(min_shape=[80, 180, 180], opt_shape=[80, 180, 180], max_shape=[80, 180, 180]),
# TODO(TIERIV): Optimize. Now, using points will increase latency significantly
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it because we want to compute depth map so we need to input points? This will actually run internal voxelization again in here
https://github.com/tier4/AWML/blob/main/projects/BEVFusion/bevfusion/bevfusion.py#L172

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants