Unverified Commit 6935a818 authored by q.yao's avatar q.yao Committed by GitHub
Browse files

[Fix] Update test data for test_iou3d (#1427)



* Update test data for test_iou3d

* delete blank lines
Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>
parent 2157b708
...@@ -134,25 +134,18 @@ int iou3d_nms_forward(Tensor boxes, Tensor keep, float nms_overlap_thresh) { ...@@ -134,25 +134,18 @@ int iou3d_nms_forward(Tensor boxes, Tensor keep, float nms_overlap_thresh) {
const int col_blocks = DIVUP(boxes_num, THREADS_PER_BLOCK_NMS); const int col_blocks = DIVUP(boxes_num, THREADS_PER_BLOCK_NMS);
unsigned long long *mask_data = NULL; Tensor mask =
CHECK_ERROR( at::empty({boxes_num, col_blocks}, boxes.options().dtype(at::kLong));
cudaMalloc((void **)&mask_data, unsigned long long *mask_data =
boxes_num * col_blocks * sizeof(unsigned long long))); (unsigned long long *)mask.data_ptr<int64_t>();
iou3d_nms_forward_cuda(boxes, mask_data, boxes_num, nms_overlap_thresh); iou3d_nms_forward_cuda(boxes, mask_data, boxes_num, nms_overlap_thresh);
// unsigned long long mask_cpu[boxes_num * col_blocks]; at::Tensor mask_cpu = mask.to(at::kCPU);
// unsigned long long *mask_cpu = new unsigned long long [boxes_num * unsigned long long *mask_host =
// col_blocks]; (unsigned long long *)mask_cpu.data_ptr<int64_t>();
std::vector<unsigned long long> mask_cpu(boxes_num * col_blocks);
// printf("boxes_num=%d, col_blocks=%d\n", boxes_num, col_blocks); std::vector<unsigned long long> remv_cpu(col_blocks);
CHECK_ERROR(cudaMemcpy(&mask_cpu[0], mask_data, memset(&remv_cpu[0], 0, sizeof(unsigned long long) * col_blocks);
boxes_num * col_blocks * sizeof(unsigned long long),
cudaMemcpyDeviceToHost));
cudaFree(mask_data);
unsigned long long *remv_cpu = new unsigned long long[col_blocks]();
int num_to_keep = 0; int num_to_keep = 0;
...@@ -162,13 +155,13 @@ int iou3d_nms_forward(Tensor boxes, Tensor keep, float nms_overlap_thresh) { ...@@ -162,13 +155,13 @@ int iou3d_nms_forward(Tensor boxes, Tensor keep, float nms_overlap_thresh) {
if (!(remv_cpu[nblock] & (1ULL << inblock))) { if (!(remv_cpu[nblock] & (1ULL << inblock))) {
keep_data[num_to_keep++] = i; keep_data[num_to_keep++] = i;
unsigned long long *p = &mask_cpu[0] + i * col_blocks; unsigned long long *p = &mask_host[0] + i * col_blocks;
for (int j = nblock; j < col_blocks; j++) { for (int j = nblock; j < col_blocks; j++) {
remv_cpu[j] |= p[j]; remv_cpu[j] |= p[j];
} }
} }
} }
delete[] remv_cpu;
if (cudaSuccess != cudaGetLastError()) printf("Error!\n"); if (cudaSuccess != cudaGetLastError()) printf("Error!\n");
return num_to_keep; return num_to_keep;
...@@ -196,26 +189,19 @@ int iou3d_nms_normal_forward(Tensor boxes, Tensor keep, ...@@ -196,26 +189,19 @@ int iou3d_nms_normal_forward(Tensor boxes, Tensor keep,
const int col_blocks = DIVUP(boxes_num, THREADS_PER_BLOCK_NMS); const int col_blocks = DIVUP(boxes_num, THREADS_PER_BLOCK_NMS);
unsigned long long *mask_data = NULL; Tensor mask =
CHECK_ERROR( at::empty({boxes_num, col_blocks}, boxes.options().dtype(at::kLong));
cudaMalloc((void **)&mask_data, unsigned long long *mask_data =
boxes_num * col_blocks * sizeof(unsigned long long))); (unsigned long long *)mask.data_ptr<int64_t>();
iou3d_nms_normal_forward_cuda(boxes, mask_data, boxes_num, iou3d_nms_normal_forward_cuda(boxes, mask_data, boxes_num,
nms_overlap_thresh); nms_overlap_thresh);
// unsigned long long mask_cpu[boxes_num * col_blocks]; at::Tensor mask_cpu = mask.to(at::kCPU);
// unsigned long long *mask_cpu = new unsigned long long [boxes_num * unsigned long long *mask_host =
// col_blocks]; (unsigned long long *)mask_cpu.data_ptr<int64_t>();
std::vector<unsigned long long> mask_cpu(boxes_num * col_blocks);
CHECK_ERROR(cudaMemcpy(&mask_cpu[0], mask_data,
boxes_num * col_blocks * sizeof(unsigned long long),
cudaMemcpyDeviceToHost));
cudaFree(mask_data);
unsigned long long *remv_cpu = new unsigned long long[col_blocks]();
std::vector<unsigned long long> remv_cpu(col_blocks);
memset(&remv_cpu[0], 0, sizeof(unsigned long long) * col_blocks);
int num_to_keep = 0; int num_to_keep = 0;
for (int i = 0; i < boxes_num; i++) { for (int i = 0; i < boxes_num; i++) {
...@@ -224,13 +210,13 @@ int iou3d_nms_normal_forward(Tensor boxes, Tensor keep, ...@@ -224,13 +210,13 @@ int iou3d_nms_normal_forward(Tensor boxes, Tensor keep,
if (!(remv_cpu[nblock] & (1ULL << inblock))) { if (!(remv_cpu[nblock] & (1ULL << inblock))) {
keep_data[num_to_keep++] = i; keep_data[num_to_keep++] = i;
unsigned long long *p = &mask_cpu[0] + i * col_blocks; unsigned long long *p = &mask_host[0] + i * col_blocks;
for (int j = nblock; j < col_blocks; j++) { for (int j = nblock; j < col_blocks; j++) {
remv_cpu[j] |= p[j]; remv_cpu[j] |= p[j];
} }
} }
} }
delete[] remv_cpu;
if (cudaSuccess != cudaGetLastError()) printf("Error!\n"); if (cudaSuccess != cudaGetLastError()) printf("Error!\n");
return num_to_keep; return num_to_keep;
......
...@@ -47,6 +47,7 @@ def nms_bev(boxes, scores, thresh, pre_max_size=None, post_max_size=None): ...@@ -47,6 +47,7 @@ def nms_bev(boxes, scores, thresh, pre_max_size=None, post_max_size=None):
Returns: Returns:
torch.Tensor: Indexes after NMS. torch.Tensor: Indexes after NMS.
""" """
assert boxes.size(1) == 5, 'Input boxes shape should be [N, 5]'
order = scores.sort(0, descending=True)[1] order = scores.sort(0, descending=True)[1]
if pre_max_size is not None: if pre_max_size is not None:
...@@ -74,6 +75,7 @@ def nms_normal_bev(boxes, scores, thresh): ...@@ -74,6 +75,7 @@ def nms_normal_bev(boxes, scores, thresh):
Returns: Returns:
torch.Tensor: Remaining indices with scores in descending order. torch.Tensor: Remaining indices with scores in descending order.
""" """
assert boxes.shape[1] == 5, 'Input boxes shape should be [N, 5]'
order = scores.sort(0, descending=True)[1] order = scores.sort(0, descending=True)[1]
boxes = boxes[order].contiguous() boxes = boxes[order].contiguous()
......
...@@ -30,9 +30,10 @@ def test_boxes_iou_bev(): ...@@ -30,9 +30,10 @@ def test_boxes_iou_bev():
@pytest.mark.skipif( @pytest.mark.skipif(
not torch.cuda.is_available(), reason='requires CUDA support') not torch.cuda.is_available(), reason='requires CUDA support')
def test_nms_gpu(): def test_nms_bev():
np_boxes = np.array([[6.0, 3.0, 8.0, 7.0], [3.0, 6.0, 9.0, 11.0], np_boxes = np.array(
[3.0, 7.0, 10.0, 12.0], [1.0, 4.0, 13.0, 7.0]], [[6.0, 3.0, 8.0, 7.0, 2.0], [3.0, 6.0, 9.0, 11.0, 1.0],
[3.0, 7.0, 10.0, 12.0, 1.0], [1.0, 4.0, 13.0, 7.0, 3.0]],
dtype=np.float32) dtype=np.float32)
np_scores = np.array([0.6, 0.9, 0.7, 0.2], dtype=np.float32) np_scores = np.array([0.6, 0.9, 0.7, 0.2], dtype=np.float32)
np_inds = np.array([1, 0, 3]) np_inds = np.array([1, 0, 3])
...@@ -40,19 +41,20 @@ def test_nms_gpu(): ...@@ -40,19 +41,20 @@ def test_nms_gpu():
scores = torch.from_numpy(np_scores) scores = torch.from_numpy(np_scores)
inds = nms_bev(boxes.cuda(), scores.cuda(), thresh=0.3) inds = nms_bev(boxes.cuda(), scores.cuda(), thresh=0.3)
assert np.allclose(inds.cpu().numpy(), np_inds) # test gpu assert np.allclose(inds.cpu().numpy(), np_inds)
@pytest.mark.skipif( @pytest.mark.skipif(
not torch.cuda.is_available(), reason='requires CUDA support') not torch.cuda.is_available(), reason='requires CUDA support')
def test_nms_normal_gpu(): def test_nms_normal_bev():
np_boxes = np.array([[6.0, 3.0, 8.0, 7.0], [3.0, 6.0, 9.0, 11.0], np_boxes = np.array(
[3.0, 7.0, 10.0, 12.0], [1.0, 4.0, 13.0, 7.0]], [[6.0, 3.0, 8.0, 7.0, 2.0], [3.0, 6.0, 9.0, 11.0, 1.0],
[3.0, 7.0, 10.0, 12.0, 1.0], [1.0, 4.0, 13.0, 7.0, 3.0]],
dtype=np.float32) dtype=np.float32)
np_scores = np.array([0.6, 0.9, 0.7, 0.2], dtype=np.float32) np_scores = np.array([0.6, 0.9, 0.7, 0.2], dtype=np.float32)
np_inds = np.array([1, 2, 0, 3]) np_inds = np.array([1, 0, 3])
boxes = torch.from_numpy(np_boxes) boxes = torch.from_numpy(np_boxes)
scores = torch.from_numpy(np_scores) scores = torch.from_numpy(np_scores)
inds = nms_normal_bev(boxes.cuda(), scores.cuda(), thresh=0.3) inds = nms_normal_bev(boxes.cuda(), scores.cuda(), thresh=0.3)
assert np.allclose(inds.cpu().numpy(), np_inds) # test gpu assert np.allclose(inds.cpu().numpy(), np_inds)
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