-
Notifications
You must be signed in to change notification settings - Fork 291
[WIP] add lidar object detection op #721
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
Open
Cathy0908
wants to merge
3
commits into
datajuicer:main
Choose a base branch
from
Cathy0908:support_ad_ops
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| from typing import Dict | ||
|
|
||
| from data_juicer.utils.lazy_loader import LazyLoader | ||
| from data_juicer.utils.model_utils import get_model, prepare_model | ||
|
|
||
| from ..base_op import OPERATORS, Mapper | ||
|
|
||
| mmdet3d = LazyLoader("mmdet3d") | ||
|
|
||
| OP_NAME = "lidar_detection_mapper" | ||
|
|
||
|
|
||
| @OPERATORS.register_module(OP_NAME) | ||
| class LiDARDetectionMapper(Mapper): | ||
| """Mapper to detect ground truth from LiDAR data.""" | ||
|
|
||
| _batched_op = True | ||
| _accelerator = "cuda" | ||
|
|
||
| def __init__(self, model_name="centerpoint", *args, **kwargs): | ||
| """ | ||
| Initialization method. | ||
|
|
||
| :param mode: | ||
| :param args: extra args | ||
| :param kwargs: extra args | ||
| """ | ||
| super().__init__(*args, **kwargs) | ||
|
|
||
| self.model_name = model_name | ||
|
|
||
| if self.model_name == "centerpoint": | ||
| self.deploy_cfg_path = "voxel-detection_onnxruntime_dynamic.py" | ||
| self.model_cfg_path = "centerpoint_pillar02_second_secfpn_head-circlenms_8xb4-cyclic-20e_nus-3d.py" | ||
| self.backend_files = [ | ||
| "centerpoint_02pillar_second_secfpn_circlenms_4x8_cyclic_20e_nus_20220811_031844-191a3822.onnx" | ||
| ] | ||
| else: | ||
| raise NotImplementedError(f'Only support "centerpoint" for now, but got {self.model_name}') | ||
|
|
||
| self.model_key = prepare_model( | ||
| "mmlab", | ||
| model_cfg=self.model_cfg_path, | ||
| deploy_cfg=self.deploy_cfg_path, | ||
| backend_files=self.backend_files, | ||
| ) | ||
|
|
||
| # Maybe should include model name, timestamp, filename, image info etc. | ||
| def pred2dict(self, data_sample: mmdet3d.structures.Det3DDataSample) -> Dict: | ||
| """Extract elements necessary to represent a prediction into a | ||
| dictionary. | ||
|
|
||
| It's better to contain only basic data elements such as strings and | ||
| numbers in order to guarantee it's json-serializable. | ||
|
|
||
| Args: | ||
| data_sample (:obj:`DetDataSample`): Predictions of the model. | ||
|
|
||
| Returns: | ||
| dict: Prediction results. | ||
| """ | ||
| result = {} | ||
| if "pred_instances_3d" in data_sample: | ||
| pred_instances_3d = data_sample.pred_instances_3d.numpy() | ||
| result = { | ||
| "labels_3d": pred_instances_3d.labels_3d.tolist(), | ||
| "scores_3d": pred_instances_3d.scores_3d.tolist(), | ||
| "bboxes_3d": pred_instances_3d.bboxes_3d.tensor.cpu().tolist(), | ||
| } | ||
|
|
||
| if "pred_pts_seg" in data_sample: | ||
| pred_pts_seg = data_sample.pred_pts_seg.numpy() | ||
| result["pts_semantic_mask"] = pred_pts_seg.pts_semantic_mask.tolist() | ||
|
|
||
| if data_sample.box_mode_3d == mmdet3d.structures.Box3DMode.LIDAR: | ||
| result["box_type_3d"] = "LiDAR" | ||
| elif data_sample.box_mode_3d == mmdet3d.structures.Box3DMode.CAM: | ||
| result["box_type_3d"] = "Camera" | ||
| elif data_sample.box_mode_3d == mmdet3d.structures.Box3DMode.DEPTH: | ||
| result["box_type_3d"] = "Depth" | ||
|
|
||
| return result | ||
|
|
||
| def process_batched(self, samples, rank=None): | ||
| model = get_model(self.model_key, rank, self.use_cuda()) | ||
| lidars = samples[self.lidar_key] | ||
|
|
||
| results = [model(lidar) for lidar in lidars] | ||
| results = [self.pred2dict(result[0]) for result in results] | ||
| samples["lidar_detections"] = results | ||
|
|
||
| return samples |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, @Qirui-jiao : based on onnx models from mmdeploy