-
Notifications
You must be signed in to change notification settings - Fork 317
Add lidar object segmentation op #736
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
Qirui-jiao
wants to merge
5
commits into
main
Choose a base branch
from
dev/support_lidar_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
5 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,68 @@ | ||
| from data_juicer.utils.constant import Fields, MetaKeys | ||
| 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_segmentation_mapper" | ||
|
|
||
|
|
||
| @OPERATORS.register_module(OP_NAME) | ||
| class LiDARSegmentationMapper(Mapper): | ||
| """Mapper to do segmentation from LiDAR data.""" | ||
|
|
||
| _batched_op = True | ||
| _accelerator = "cuda" | ||
|
|
||
| def __init__( | ||
| self, | ||
| model_name="cylinder3d", | ||
| model_cfg_name="", | ||
| model_path="", | ||
| tag_field_name: str = MetaKeys.lidar_segmentation_tags, | ||
| *args, | ||
| **kwargs, | ||
| ): | ||
| """ | ||
| Initialization method. | ||
| :param model_name: Name of the model used. | ||
| :param model_cfg_name: The config name of the model used. | ||
| :param model_path: Path of the model weight. | ||
| :param tag_field_name: The field name to store the tags. It's | ||
| "lidar_segmentation_tags" in default. | ||
| :param args: extra args | ||
| :param kwargs: extra args | ||
| """ | ||
| super().__init__(*args, **kwargs) | ||
|
|
||
| self.model_name = model_name | ||
|
|
||
| if self.model_name == "cylinder3d": | ||
| self.model_cfg_name = model_cfg_name | ||
| self.model_path = model_path | ||
| else: | ||
| raise NotImplementedError(f'Only support "cylinder3d" for now, but got {self.model_name}') | ||
|
|
||
| self.model_key = prepare_model( | ||
| "mmlab", | ||
| model_cfg=self.model_cfg_name, | ||
| model_path=self.model_path, | ||
| task="LiDARSegmentation", | ||
| model_name=self.model_name, | ||
| ) | ||
| self.tag_field_name = tag_field_name | ||
|
|
||
| def process_single(self, sample, rank=None): | ||
|
|
||
| # check if it's generated already | ||
| if self.tag_field_name in sample[Fields.meta]: | ||
| return sample | ||
|
|
||
| model = get_model(self.model_key, rank, self.use_cuda()) | ||
|
|
||
| results = model(dict(points=sample[self.lidar_key])) | ||
| sample[Fields.meta][self.tag_field_name] = results[0] | ||
|
|
||
| return sample | ||
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
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,61 @@ | ||
| import unittest | ||
| import os | ||
|
|
||
| from data_juicer.core import NestedDataset as Dataset | ||
| from data_juicer.ops.mapper.lidar_segmentation_mapper import LiDARSegmentationMapper | ||
| from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase | ||
| from data_juicer.utils.constant import Fields, MetaKeys | ||
|
|
||
|
|
||
| class LiDARSegmentationMapperTest(DataJuicerTestCaseBase): | ||
| data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', | ||
| 'data') | ||
| lidar_test1 = os.path.join(data_path, 'lidar_test1.bin') | ||
| lidar_test2 = os.path.join(data_path, 'lidar_test2.bin') | ||
| lidar_test3 = os.path.join(data_path, 'lidar_test3.bin') | ||
|
|
||
| model_cfg_name = "cylinder3d_8xb2-laser-polar-mix-3x_semantickitti" | ||
| model_path = "cylinder3d_8xb2-amp-laser-polar-mix-3x_semantickitti_20230425_144950-372cdf69.pth" | ||
|
|
||
|
|
||
| def setUp(self): | ||
| super().setUp() | ||
| self.source = [ | ||
| {'lidar': self.lidar_test1}, | ||
| {'lidar': self.lidar_test2}, | ||
| {'lidar': self.lidar_test3} | ||
| ] | ||
| self.op = LiDARSegmentationMapper( | ||
| model_name="cylinder3d", | ||
| model_cfg_name=self.model_cfg_name, | ||
| model_path=self.model_path, | ||
| ) | ||
|
|
||
| def _run_and_assert(self, num_proc, with_rank): | ||
| dataset = Dataset.from_list(self.source) | ||
| if Fields.meta not in dataset.features: | ||
| dataset = dataset.add_column(name=Fields.meta, | ||
| column=[{}] * dataset.num_rows) | ||
| dataset = dataset.map(self.op.process, num_proc=num_proc, with_rank=with_rank) | ||
| res_list = dataset.to_list() | ||
|
|
||
| self.assertEqual(len(res_list), 3) | ||
| self.assertEqual(list(res_list[0][Fields.meta][MetaKeys.lidar_segmentation_tags].keys()), ['box_type_3d', 'pts_semantic_mask']) | ||
| self.assertEqual(len(res_list[0][Fields.meta][MetaKeys.lidar_segmentation_tags]["pts_semantic_mask"]), 17238) | ||
| self.assertEqual(res_list[0][Fields.meta][MetaKeys.lidar_segmentation_tags]["box_type_3d"], "LiDAR") | ||
|
|
||
| def test_cpu(self): | ||
| self._run_and_assert(num_proc=1, with_rank=False) | ||
|
|
||
| def test_cuda(self): | ||
| self._run_and_assert(num_proc=1, with_rank=True) | ||
|
|
||
| def test_cpu_mul_proc(self): | ||
| self._run_and_assert(num_proc=2, with_rank=False) | ||
|
|
||
| def test_cuda_mul_proc(self): | ||
| self._run_and_assert(num_proc=2, with_rank=True) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
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.