-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[Feature] Add Cylinder3D head #2291
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
526b8f2
add cylinder decode head
xizaoqu 9506d15
update
xizaoqu 8fbac9b
update
xizaoqu bb65b62
add lovasz loss
xizaoqu 288c8b4
update
xizaoqu f7499b1
update
xizaoqu e24688f
update
xizaoqu 73bffd1
update
xizaoqu 0d2df75
update
xizaoqu 961efd3
update
xizaoqu 8931d4e
update
xizaoqu 5788d78
update
xizaoqu 034960c
update
xizaoqu 545d878
cylinder3d_head
xizaoqu 39ecf13
update
xizaoqu 9c0e75a
update
xizaoqu 3f71f15
update
xizaoqu 952fa9e
update
xizaoqu 57a0218
update
xizaoqu 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| # Copyright (c) OpenMMLab. All rights reserved. | ||
| from .cylinder3d_head import Cylinder3DHead | ||
| from .dgcnn_head import DGCNNHead | ||
| from .paconv_head import PAConvHead | ||
| from .pointnet2_head import PointNet2Head | ||
|
|
||
| __all__ = ['PointNet2Head', 'DGCNNHead', 'PAConvHead'] | ||
| __all__ = ['PointNet2Head', 'DGCNNHead', 'PAConvHead', 'Cylinder3DHead'] |
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,119 @@ | ||
| # Copyright (c) OpenMMLab. All rights reserved. | ||
| import torch | ||
| from mmcv.ops import SparseConvTensor, SubMConv3d | ||
|
|
||
| from mmdet3d.registry import MODELS | ||
| from mmdet3d.structures.det3d_data_sample import SampleList | ||
| from mmdet3d.utils.typing_utils import ConfigType | ||
| from .decode_head import Base3DDecodeHead | ||
|
|
||
|
|
||
| @MODELS.register_module() | ||
| class Cylinder3DHead(Base3DDecodeHead): | ||
| """Cylinder3D decoder head. | ||
|
|
||
| Decoder head used in `Cylinder3D <https://arxiv.org/abs/2011.10033>`_. | ||
| Refer to the | ||
| `official code <https://https://github.com/xinge008/Cylinder3D>`_. | ||
|
|
||
| Args: | ||
| channels (int): Channels after modules, before conv_seg. | ||
| num_classes (int): Number of classes. | ||
| dropout_ratio (float): Ratio of dropout layer. Defaults to 0.5. | ||
| conv_cfg (dict or :obj:`ConfigDict`): Config of conv layers. | ||
| Defaults to dict(type='Conv1d'). | ||
| norm_cfg (dict or :obj:`ConfigDict`): Config of norm layers. | ||
| Defaults to dict(type='BN1d'). | ||
| act_cfg (dict or :obj:`ConfigDict`): Config of activation layers. | ||
| Defaults to dict(type='ReLU'). | ||
| loss_ce (dict or :obj:`ConfigDict`): Config of CrossEntropy loss. | ||
| Defaults to dict( | ||
| type='mmdet.CrossEntropyLoss', | ||
| use_sigmoid=False, | ||
| class_weight=None, | ||
| loss_weight=1.0). | ||
| loss_lovasz (dict or :obj:`ConfigDict`): Config of Lovasz loss. | ||
| Defaults to dict(type='mmseg.LovaszLoss', loss_weight=1.0). | ||
| conv_seg_kernel_size (int): The kernel size used in conv_seg. | ||
| Defaults to 1. | ||
| ignore_index (int): The label index to be ignored. When using masked | ||
xizaoqu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| BCE loss, ignore_index should be set to None. Defaults to 255. | ||
| init_cfg (dict or :obj:`ConfigDict` or list[dict or :obj:`ConfigDict`], | ||
| optional): Initialization config dict. Defaults to None. | ||
| """ | ||
|
|
||
| def __init__(self, | ||
| channels: int, | ||
| num_classes: int, | ||
| dropout_ratio: float = 0, | ||
| conv_cfg: ConfigType = dict(type='Conv1d'), | ||
| norm_cfg: ConfigType = dict(type='BN1d'), | ||
| act_cfg: ConfigType = dict(type='ReLU'), | ||
| loss_ce: ConfigType = dict( | ||
| type='mmdet.CrossEntropyLoss', | ||
| use_sigmoid=False, | ||
| class_weight=None, | ||
| loss_weight=1.0), | ||
| loss_lovasz: ConfigType = dict( | ||
| type='mmseg.LovaszLoss', loss_weight=1.0), | ||
xizaoqu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| conv_seg_kernel_size: int = 3, | ||
| ignore_index: int = 0, | ||
| init_cfg=None) -> None: | ||
xizaoqu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| super(Cylinder3DHead, self).__init__( | ||
| channels=channels, | ||
| num_classes=num_classes, | ||
| dropout_ratio=dropout_ratio, | ||
| conv_cfg=conv_cfg, | ||
| norm_cfg=norm_cfg, | ||
| act_cfg=act_cfg, | ||
| conv_seg_kernel_size=conv_seg_kernel_size, | ||
| init_cfg=init_cfg) | ||
|
|
||
| self.loss_lovasz = MODELS.build(loss_lovasz) | ||
| self.loss_ce = MODELS.build(loss_ce) | ||
| self.ignore_index = ignore_index | ||
|
|
||
| def build_conv_seg(self, channels: int, num_classes: int, | ||
| kernel_size: int) -> SubMConv3d: | ||
| return SubMConv3d( | ||
| channels, | ||
| num_classes, | ||
| indice_key='logit', | ||
| kernel_size=kernel_size, | ||
| stride=1, | ||
| padding=1, | ||
| bias=True) | ||
|
|
||
| def forward(self, sparse_voxels: SparseConvTensor) -> SparseConvTensor: | ||
| """Forward function.""" | ||
| sparse_logits = self.cls_seg(sparse_voxels) | ||
| return sparse_logits | ||
|
|
||
xizaoqu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def loss_by_feat(self, seg_logit: SparseConvTensor, | ||
| batch_data_samples: SampleList) -> dict: | ||
| """Compute semantic segmentation loss. | ||
|
|
||
| Args: | ||
| seg_logit (spconv.SparseConvTensor): Predicted per-voxel | ||
| segmentation logits of shape [num_voxels, num_classes] | ||
| stored in SparseConvTensor. | ||
| batch_data_samples (List[:obj:`Det3DDataSample`]): The seg | ||
| data samples. It usually includes information such | ||
| as `metainfo` and `gt_pts_seg`. | ||
xizaoqu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """ | ||
|
|
||
| gt_semantic_segs = [ | ||
| data_sample.gt_pts_seg.voxel_semantic_mask | ||
| for data_sample in batch_data_samples | ||
| ] | ||
| seg_label = torch.cat(gt_semantic_segs) | ||
| seg_logit_feat = seg_logit.features | ||
| loss = dict() | ||
| loss['loss_ce'] = self.loss_ce( | ||
| seg_logit_feat, seg_label, ignore_index=self.ignore_index) | ||
| seg_logit_feat = seg_logit_feat.permute(1, 0)[None, :, :, | ||
| None] # pseudo BCHW | ||
| loss['loss_lovasz'] = self.loss_lovasz( | ||
| seg_logit_feat, seg_label, ignore_index=self.ignore_index) | ||
|
|
||
| return loss | ||
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.