Commit e9777adb authored by Zhang's avatar Zhang Committed by Zaida Zhou
Browse files

[Feature] Support RoIAwarePool3d with cambricon MLU backend (#2359)

* [Feature] Support RoiawarePool3d with cambricon MLU backend.

* [Feature] Support RoiawarePool3d with cambricon MLU backend.
parent 4a0e9929
...@@ -47,7 +47,7 @@ We implement common ops used in detection, segmentation, etc. ...@@ -47,7 +47,7 @@ We implement common ops used in detection, segmentation, etc.
| RoIAlignRotated | √ | √ | √ | | | RoIAlignRotated | √ | √ | √ | |
| RiRoIAlignRotated | | √ | | | | RiRoIAlignRotated | | √ | | |
| RoIAlign | √ | √ | √ | | | RoIAlign | √ | √ | √ | |
| RoIAwarePool3d | | √ | | | | RoIAwarePool3d | | √ | | |
| SAConv2d | | √ | | | | SAConv2d | | √ | | |
| SigmoidFocalLoss | | √ | √ | | | SigmoidFocalLoss | | √ | √ | |
| SoftmaxFocalLoss | | √ | | | | SoftmaxFocalLoss | | √ | | |
......
...@@ -47,7 +47,7 @@ MMCV 提供了检测、分割等任务中常用的算子 ...@@ -47,7 +47,7 @@ MMCV 提供了检测、分割等任务中常用的算子
| RoIAlignRotated | √ | √ | √ | | | RoIAlignRotated | √ | √ | √ | |
| RiRoIAlignRotated | | √ | | | | RiRoIAlignRotated | | √ | | |
| RoIAlign | √ | √ | √ | | | RoIAlign | √ | √ | √ | |
| RoIAwarePool3d | | √ | | | | RoIAwarePool3d | | √ | | |
| SAConv2d | | √ | | | | SAConv2d | | √ | | |
| SigmoidFocalLoss | | √ | √ | | | SigmoidFocalLoss | | √ | √ | |
| SoftmaxFocalLoss | | √ | | | | SoftmaxFocalLoss | | √ | | |
......
This diff is collapsed.
This diff is collapsed.
...@@ -5,11 +5,27 @@ import torch ...@@ -5,11 +5,27 @@ import torch
from mmcv.ops import (RoIAwarePool3d, points_in_boxes_all, points_in_boxes_cpu, from mmcv.ops import (RoIAwarePool3d, points_in_boxes_all, points_in_boxes_cpu,
points_in_boxes_part) points_in_boxes_part)
from mmcv.utils import IS_CUDA_AVAILABLE, IS_MLU_AVAILABLE
@pytest.mark.skipif(
not torch.cuda.is_available(), reason='requires CUDA support') @pytest.mark.parametrize('device', [
def test_RoIAwarePool3d(): pytest.param(
'cuda',
marks=pytest.mark.skipif(
not IS_CUDA_AVAILABLE, reason='requires CUDA support')),
pytest.param(
'mlu',
marks=pytest.mark.skipif(
not IS_MLU_AVAILABLE, reason='requires MLU support'))
])
@pytest.mark.parametrize('dtype', [
torch.float, torch.half,
pytest.param(
torch.double,
marks=pytest.mark.skipif(
IS_MLU_AVAILABLE, reason='MLU does not support for double'))
])
def test_RoIAwarePool3d(device, dtype):
roiaware_pool3d_max = RoIAwarePool3d( roiaware_pool3d_max = RoIAwarePool3d(
out_size=4, max_pts_per_voxel=128, mode='max') out_size=4, max_pts_per_voxel=128, mode='max')
roiaware_pool3d_avg = RoIAwarePool3d( roiaware_pool3d_avg = RoIAwarePool3d(
...@@ -17,27 +33,27 @@ def test_RoIAwarePool3d(): ...@@ -17,27 +33,27 @@ def test_RoIAwarePool3d():
rois = torch.tensor( rois = torch.tensor(
[[1.0, 2.0, 3.0, 5.0, 4.0, 6.0, -0.3 - np.pi / 2], [[1.0, 2.0, 3.0, 5.0, 4.0, 6.0, -0.3 - np.pi / 2],
[-10.0, 23.0, 16.0, 20.0, 10.0, 20.0, -0.5 - np.pi / 2]], [-10.0, 23.0, 16.0, 20.0, 10.0, 20.0, -0.5 - np.pi / 2]],
dtype=torch.float32).cuda( dtype=dtype).to(device)
) # boxes (m, 7) with bottom center in lidar coordinate # boxes (m, 7) with bottom center in lidar coordinate
pts = torch.tensor( pts = torch.tensor(
[[1, 2, 3.3], [1.2, 2.5, 3.0], [0.8, 2.1, 3.5], [1.6, 2.6, 3.6], [[1, 2, 3.3], [1.2, 2.5, 3.0], [0.8, 2.1, 3.5], [1.6, 2.6, 3.6],
[0.8, 1.2, 3.9], [-9.2, 21.0, 18.2], [3.8, 7.9, 6.3], [0.8, 1.2, 3.9], [-9.2, 21.0, 18.2], [3.8, 7.9, 6.3],
[4.7, 3.5, -12.2], [3.8, 7.6, -2], [-10.6, -12.9, -20], [-16, -18, 9], [4.7, 3.5, -12.2], [3.8, 7.6, -2], [-10.6, -12.9, -20], [-16, -18, 9],
[-21.3, -52, -5], [0, 0, 0], [6, 7, 8], [-2, -3, -4]], [-21.3, -52, -5], [0, 0, 0], [6, 7, 8], [-2, -3, -4]],
dtype=torch.float32).cuda() # points (n, 3) in lidar coordinate dtype=dtype).to(device) # points (n, 3) in lidar coordinate
pts_feature = pts.clone() pts_feature = pts.clone()
pooled_features_max = roiaware_pool3d_max( pooled_features_max = roiaware_pool3d_max(
rois=rois, pts=pts, pts_feature=pts_feature) rois=rois, pts=pts, pts_feature=pts_feature)
assert pooled_features_max.shape == torch.Size([2, 4, 4, 4, 3]) assert pooled_features_max.shape == torch.Size([2, 4, 4, 4, 3])
assert torch.allclose(pooled_features_max.sum(), assert torch.allclose(pooled_features_max.sum(),
torch.tensor(51.100).cuda(), 1e-3) torch.tensor(51.100, dtype=dtype).to(device), 1e-3)
pooled_features_avg = roiaware_pool3d_avg( pooled_features_avg = roiaware_pool3d_avg(
rois=rois, pts=pts, pts_feature=pts_feature) rois=rois, pts=pts, pts_feature=pts_feature)
assert pooled_features_avg.shape == torch.Size([2, 4, 4, 4, 3]) assert pooled_features_avg.shape == torch.Size([2, 4, 4, 4, 3])
assert torch.allclose(pooled_features_avg.sum(), assert torch.allclose(pooled_features_avg.sum(),
torch.tensor(49.750).cuda(), 1e-3) torch.tensor(49.750, dtype=dtype).to(device), 1e-3)
@pytest.mark.skipif( @pytest.mark.skipif(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment