Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(image_projection_based_fusion): add cache for camera projection #9635

Conversation

a-maumau
Copy link
Contributor

@a-maumau a-maumau commented Dec 12, 2024

Description

This PR introduces a caching feature for calculating raw image projections (unrectifyPoint).
This PR must merged with autowarefoundation/autoware_launch#1275

It introduces the CameraProjection class to handle the related processes. The cache is computed based on specific grid centers, and the projected points are represented using these grid centers. These grid centers are determined by approximation_grid_cell_width and approximation_grid_cell_height.
Pre-cached result will be simply stored in an array and all grid cells on the image will be pre-computed.

For example, when approximation_grid_cell_* is set to 1.0 pixel, the grid centers will be created as shown in the following image:
image_projection_based_fusion_PR_image

Note that edge pixels ((w, *), (*, h)) will be rounded to fall outside the image bounds.

memory consumption

When using caching, memory consumption is calculated as:

ceil(image_width / grid_cell_width) * ceil(image_height / grid_cell_height) * (4 * 2) * roi_numbers [bytes]

Here, (4 * 2) represents the bytes for two float values.
For example, for an image with dimensions 1440 × 1080, a grid size of 1 pixel, and caching enabled for 6 cameras, the memory consumption is:

(1440 / 1.0) * (1080 / 1.0) * 4 * 2 * 6 / (1024 * 1024) ≈ 71.2 MiB (theoretical).

Also when using the cache feature, it requires an initialization step (pre-caching). This will make some delay to a node before starting the processing.

Other changes

  • This PR fixes a bug where the camera parameters were used before being properly initialized in pointpainting_fusion.
  • take a list input instead of single bool for point_project_to_unrectified_image param

Performance: current impl. vs. this PR

  • The following result is done with the same rosbag file, but the starting is determined by the (almost) first topic from the map_based_prediction node, so there is no guarantee it is aligned.
  • The processing time is timed with TimeKeeper (subCallback is timed).
  • CPU usage and memory usage is collected with autoware_tools
  • The grid cell size is set to a square (width == height), and the camera (roi) number is set to 6.
  • baseline indicates the current implementation, unrectified is the point_project_to_unrectified_image and cache means approximate_camera_projection option in the config.

Processing Time

roi_cluster_fusion

  • all processing times
    all_roi_cluster_fusion_processing_time

  • current point_project_to_unrectified_image=false vs. this PR point_project_to_unrectified_image=true, cache=true
    roi_cluster_fusion_baseline_vs_cache
    This shows the processing time is close to the case of point_project_to_unrectified_image=false case when we use the cache feature.

pointpainting_fusion

  • all processing times
    all_pointpainting_processing_time

  • current point_project_to_unrectified_image=false vs. this PR point_project_to_unrectified_image=true, cache=true
    pointpainting_baseline_vs_cache

  • current point_project_to_unrectified_image=true vs. this PR point_project_to_unrectified_image=true, no cache
    pointpainting_rectified_true_no_cache_compare
    This performance difference should be coming from the fix of the bug in FOV filtering (camera_info was not properly initialized).

CPU Usage

roi_cluster_fusion

roi_cluster_fusion_compare_cpu_usage
Plot length differ because of the difference of play rate (0.1x is 3 times longer than 0.3x).
It does not contains the CPU usage of initialization step (which might use 100% of CPU).

Memory Usage

roi_cluster_fusion

roi_cluster_fusion_compare_memory_usage
Plot length differ because of the difference of play rate (0.1x is 3 times longer than 0.3x).

Visualization

Following images ware not captured at the same frame.
example_compare_of_grid_cell_size
All images are in the case of point_project_to_unrectified_image=true.

Related links

Parent Issue:

  • Link

How was this PR tested?

Checked the rviz output and each fusion node's visualization.
output_is_normal

For checking by yourself, you need some processing like

# decompress image
ros2 launch autoware_image_transport_decompressor image_transport_decompressor.launch.xml input_topic_name:=/sensing/camera/camera0/image_rect_color/compressed output_topic_name:=/sensing/camera/camera0/image_rect_color

# relay camera info
ros2 run topic_tools relay /sensing/camera/camera0/camera_info /perception/object_recognition/detection/pointpainting/pointpainting/debug/camera_info

and set the debug_mode: true in param. For pointpainting_fusion, you need to set the #if 0 to #if 1 to contain the points in an image.

Notes for reviewers

None.

Interface changes

None.

Effects on system behavior

None.

@github-actions github-actions bot added type:documentation Creating or refining documentation. (auto-assigned) component:perception Advanced sensor data processing and environment understanding. (auto-assigned) tag:require-cuda-build-and-test labels Dec 12, 2024
Copy link

github-actions bot commented Dec 12, 2024

Thank you for contributing to the Autoware project!

🚧 If your pull request is in progress, switch it to draft mode.

Please ensure:

@a-maumau a-maumau force-pushed the mau/perf/image_projection_based_fusion/add_projection_cache branch 2 times, most recently from 3a0b75c to be70bd7 Compare December 12, 2024 09:24
@technolojin technolojin self-assigned this Dec 13, 2024
@a-maumau a-maumau force-pushed the mau/perf/image_projection_based_fusion/add_projection_cache branch from d518133 to bf52055 Compare December 16, 2024 07:08
@github-actions github-actions bot added the component:planning Route planning, decision-making, and navigation. (auto-assigned) label Dec 16, 2024
@a-maumau a-maumau force-pushed the mau/perf/image_projection_based_fusion/add_projection_cache branch from bf52055 to 6e00c9c Compare December 16, 2024 07:51
@github-actions github-actions bot removed the component:planning Route planning, decision-making, and navigation. (auto-assigned) label Dec 16, 2024
@a-maumau a-maumau force-pushed the mau/perf/image_projection_based_fusion/add_projection_cache branch from 3822a96 to b445034 Compare December 19, 2024 04:05
@technolojin technolojin added the run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci) label Dec 19, 2024
@technolojin
Copy link
Contributor

Can you also update the schema file?
https://github.com/autowarefoundation/autoware.universe/blob/main/perception/autoware_image_projection_based_fusion/schema/fusion_common.schema.json

@a-maumau a-maumau marked this pull request as ready for review December 19, 2024 07:38
Copy link

codecov bot commented Dec 19, 2024

Codecov Report

Attention: Patch coverage is 0% with 166 lines in your changes missing coverage. Please review.

Project coverage is 29.78%. Comparing base (932e87f) to head (3b0bbd0).
Report is 53 commits behind head on main.

Files with missing lines Patch % Lines
..._projection_based_fusion/src/camera_projection.cpp 0.00% 99 Missing ⚠️
..._image_projection_based_fusion/src/fusion_node.cpp 0.00% 21 Missing ⚠️
...on_based_fusion/src/roi_pointcloud_fusion/node.cpp 0.00% 19 Missing ⚠️
...sed_fusion/src/roi_detected_object_fusion/node.cpp 0.00% 12 Missing ⚠️
...ction_based_fusion/src/roi_cluster_fusion/node.cpp 0.00% 9 Missing ⚠️
...fusion/src/segmentation_pointcloud_fusion/node.cpp 0.00% 3 Missing ⚠️
...ion_based_fusion/src/pointpainting_fusion/node.cpp 0.00% 2 Missing ⚠️
...mage_projection_based_fusion/camera_projection.hpp 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9635      +/-   ##
==========================================
- Coverage   29.80%   29.78%   -0.03%     
==========================================
  Files        1443     1446       +3     
  Lines      108590   108696     +106     
  Branches    42653    42691      +38     
==========================================
+ Hits        32369    32370       +1     
- Misses      73042    73145     +103     
- Partials     3179     3181       +2     
Flag Coverage Δ *Carryforward flag
differential 2.54% <0.00%> (?)
total 29.82% <ø> (+0.02%) ⬆️ Carriedforward from c3317ac

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: a-maumau <[email protected]>
@a-maumau
Copy link
Contributor Author

@technolojin I changed the terms in bc1e8ed

Signed-off-by: a-maumau <[email protected]>
Copy link
Contributor

@technolojin technolojin left a comment

Choose a reason for hiding this comment

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

Just rename some variables.

  • avoid to use too general name such as index: more specify like grid_index
  • name as its role: grid_x -> grid_idx_x
  • align naming style: since cell_width_ is used, image_w_ -> image_width_

a-maumau and others added 6 commits December 20, 2024 15:13
Signed-off-by: a-maumau <[email protected]>
Co-authored-by: Taekjin LEE <[email protected]>
Signed-off-by: a-maumau <[email protected]>
Co-authored-by: Taekjin LEE <[email protected]>
Signed-off-by: a-maumau <[email protected]>
Co-authored-by: Taekjin LEE <[email protected]>
Signed-off-by: a-maumau <[email protected]>
Co-authored-by: Taekjin LEE <[email protected]>
Signed-off-by: a-maumau <[email protected]>
Co-authored-by: Taekjin LEE <[email protected]>
Signed-off-by: a-maumau <[email protected]>
@a-maumau a-maumau force-pushed the mau/perf/image_projection_based_fusion/add_projection_cache branch from 4bdbbcf to 542ed48 Compare December 20, 2024 06:14
@a-maumau
Copy link
Contributor Author

@technolojin I applied the suggestions. thank you for pointing out!

@technolojin
Copy link
Contributor

technolojin commented Dec 23, 2024

Test the PR in TIER IV INTERNAL CLOUD TESTER

Copy link
Contributor

@technolojin technolojin left a comment

Choose a reason for hiding this comment

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

LGTM

@technolojin
Copy link
Contributor

@badai-nguyen @YoshiRi @yukkysaito
Dear code-owners,

Can you review this PR? This PR has been tested.

Copy link
Contributor

@badai-nguyen badai-nguyen left a comment

Choose a reason for hiding this comment

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

@a-maumau Thank you for your great idea and PR. I have minor comments.

@a-maumau a-maumau force-pushed the mau/perf/image_projection_based_fusion/add_projection_cache branch from 118ca9b to 899a267 Compare December 23, 2024 07:08
a-maumau and others added 2 commits December 23, 2024 16:12
Co-authored-by: badai nguyen  <[email protected]>
Signed-off-by: a-maumau <[email protected]>
@a-maumau a-maumau force-pushed the mau/perf/image_projection_based_fusion/add_projection_cache branch from 899a267 to c3317ac Compare December 23, 2024 07:13
@a-maumau
Copy link
Contributor Author

@badai-nguyen Thank you for pointing out. I applied your suggestions.

@@ -65,6 +65,21 @@
"type": "number",
"description": "Maximum z position [m].",
"default": 100.0
},
Copy link
Contributor

Choose a reason for hiding this comment

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

point_project_to_unrectified_image parameter was missing from previous PR, could also add it?

Suggested change
},
},
"point_project_to_unrectified_image": {
"type": "array",
"description": "An array of options indicating whether to project point to unrectified image or not.",
"default": [false, false, false, false, false, false]
},

Copy link
Contributor

Choose a reason for hiding this comment

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

resolved 3b0bbd0

@badai-nguyen badai-nguyen added the run:deploy-docs Mark for deploy-docs action generation. (used-by-ci) label Dec 23, 2024
Copy link
Contributor

@badai-nguyen badai-nguyen left a comment

Choose a reason for hiding this comment

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

LGTM

@technolojin technolojin merged commit ca3afdd into autowarefoundation:main Dec 24, 2024
34 of 36 checks passed
kminoda pushed a commit to kminoda/autoware.universe that referenced this pull request Dec 25, 2024
…utowarefoundation#9635)

* add camera_projection class and projection cache

Signed-off-by: a-maumau <[email protected]>

* style(pre-commit): autofix

* fix FOV filtering

Signed-off-by: a-maumau <[email protected]>

* style(pre-commit): autofix

* remove unused includes

Signed-off-by: a-maumau <[email protected]>

* update schema

Signed-off-by: a-maumau <[email protected]>

* fix cpplint error

Signed-off-by: a-maumau <[email protected]>

* apply suggestion: more simple and effcient computation

Signed-off-by: a-maumau <[email protected]>

* correct terminology

Signed-off-by: a-maumau <[email protected]>

* style(pre-commit): autofix

* fix comments

Signed-off-by: a-maumau <[email protected]>

* fix var name

Signed-off-by: a-maumau <[email protected]>
Co-authored-by: Taekjin LEE <[email protected]>

* fix variable names

Signed-off-by: a-maumau <[email protected]>
Co-authored-by: Taekjin LEE <[email protected]>

* fix variable names

Signed-off-by: a-maumau <[email protected]>
Co-authored-by: Taekjin LEE <[email protected]>

* fix variable names

Signed-off-by: a-maumau <[email protected]>
Co-authored-by: Taekjin LEE <[email protected]>

* fix variable names

Signed-off-by: a-maumau <[email protected]>
Co-authored-by: Taekjin LEE <[email protected]>

* fix variable names

Signed-off-by: a-maumau <[email protected]>

* fix initialization

Co-authored-by: badai nguyen  <[email protected]>
Signed-off-by: a-maumau <[email protected]>

* add verification to point_project_to_unrectified_image when loading

Co-authored-by: badai nguyen  <[email protected]>
Signed-off-by: a-maumau <[email protected]>

* chore: add option description to project points to unrectified image

Signed-off-by: Taekjin LEE <[email protected]>

---------

Signed-off-by: a-maumau <[email protected]>
Signed-off-by: Taekjin LEE <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Taekjin LEE <[email protected]>
Co-authored-by: badai nguyen <[email protected]>
Co-authored-by: Taekjin LEE <[email protected]>
kyoichi-sugahara pushed a commit to kyoichi-sugahara/autoware.universe that referenced this pull request Dec 25, 2024
…utowarefoundation#9635)

* add camera_projection class and projection cache

Signed-off-by: a-maumau <[email protected]>

* style(pre-commit): autofix

* fix FOV filtering

Signed-off-by: a-maumau <[email protected]>

* style(pre-commit): autofix

* remove unused includes

Signed-off-by: a-maumau <[email protected]>

* update schema

Signed-off-by: a-maumau <[email protected]>

* fix cpplint error

Signed-off-by: a-maumau <[email protected]>

* apply suggestion: more simple and effcient computation

Signed-off-by: a-maumau <[email protected]>

* correct terminology

Signed-off-by: a-maumau <[email protected]>

* style(pre-commit): autofix

* fix comments

Signed-off-by: a-maumau <[email protected]>

* fix var name

Signed-off-by: a-maumau <[email protected]>
Co-authored-by: Taekjin LEE <[email protected]>

* fix variable names

Signed-off-by: a-maumau <[email protected]>
Co-authored-by: Taekjin LEE <[email protected]>

* fix variable names

Signed-off-by: a-maumau <[email protected]>
Co-authored-by: Taekjin LEE <[email protected]>

* fix variable names

Signed-off-by: a-maumau <[email protected]>
Co-authored-by: Taekjin LEE <[email protected]>

* fix variable names

Signed-off-by: a-maumau <[email protected]>
Co-authored-by: Taekjin LEE <[email protected]>

* fix variable names

Signed-off-by: a-maumau <[email protected]>

* fix initialization

Co-authored-by: badai nguyen  <[email protected]>
Signed-off-by: a-maumau <[email protected]>

* add verification to point_project_to_unrectified_image when loading

Co-authored-by: badai nguyen  <[email protected]>
Signed-off-by: a-maumau <[email protected]>

* chore: add option description to project points to unrectified image

Signed-off-by: Taekjin LEE <[email protected]>

---------

Signed-off-by: a-maumau <[email protected]>
Signed-off-by: Taekjin LEE <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Taekjin LEE <[email protected]>
Co-authored-by: badai nguyen <[email protected]>
Co-authored-by: Taekjin LEE <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:perception Advanced sensor data processing and environment understanding. (auto-assigned) run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci) run:deploy-docs Mark for deploy-docs action generation. (used-by-ci) tag:require-cuda-build-and-test type:documentation Creating or refining documentation. (auto-assigned)
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants