"tests/test_cli/vscode:/vscode.git/clone" did not exist on "90a36b7950028b87963ee9aaefa8e6001ff0f6dd"
Commit f27d308f authored by yinchimaoliang's avatar yinchimaoliang
Browse files

merge master

parents c66ae813 27ebcfac
...@@ -16,11 +16,13 @@ ...@@ -16,11 +16,13 @@
#define NMS_CPU_H #define NMS_CPU_H
#include <pybind11/pybind11.h> #include <pybind11/pybind11.h>
// must include pybind11/stl.h if using containers in STL in arguments. // must include pybind11/stl.h if using containers in STL in arguments.
#include <algorithm>
#include <boost/geometry.hpp>
#include <pybind11/numpy.h> #include <pybind11/numpy.h>
#include <pybind11/stl.h> #include <pybind11/stl.h>
#include <algorithm>
#include <boost/geometry.hpp>
#include <vector> #include <vector>
#include "box_iou.h" #include "box_iou.h"
#include "nms_gpu.h" #include "nms_gpu.h"
namespace spconv { namespace spconv {
...@@ -48,13 +50,11 @@ std::vector<int> non_max_suppression_cpu(py::array_t<DType> boxes, ...@@ -48,13 +50,11 @@ std::vector<int> non_max_suppression_cpu(py::array_t<DType> boxes,
DType xx1, xx2, w, h, inter, ovr; DType xx1, xx2, w, h, inter, ovr;
for (int _i = 0; _i < ndets; ++_i) { for (int _i = 0; _i < ndets; ++_i) {
i = order_r(_i); i = order_r(_i);
if (suppressed_rw(i) == 1) if (suppressed_rw(i) == 1) continue;
continue;
keep.push_back(i); keep.push_back(i);
for (int _j = _i + 1; _j < ndets; ++_j) { for (int _j = _i + 1; _j < ndets; ++_j) {
j = order_r(_j); j = order_r(_j);
if (suppressed_rw(j) == 1) if (suppressed_rw(j) == 1) continue;
continue;
xx2 = std::min(boxes_r(i, 2), boxes_r(j, 2)); xx2 = std::min(boxes_r(i, 2), boxes_r(j, 2));
xx1 = std::max(boxes_r(i, 0), boxes_r(j, 0)); xx1 = std::max(boxes_r(i, 0), boxes_r(j, 0));
w = xx2 - xx1 + eps; w = xx2 - xx1 + eps;
...@@ -65,8 +65,7 @@ std::vector<int> non_max_suppression_cpu(py::array_t<DType> boxes, ...@@ -65,8 +65,7 @@ std::vector<int> non_max_suppression_cpu(py::array_t<DType> boxes,
if (h > 0) { if (h > 0) {
inter = w * h; inter = w * h;
ovr = inter / (area_rw(i) + area_rw(j) - inter); ovr = inter / (area_rw(i) + area_rw(j) - inter);
if (ovr >= thresh) if (ovr >= thresh) suppressed_rw(j) = 1;
suppressed_rw(j) = 1;
} }
} }
} }
...@@ -97,15 +96,12 @@ std::vector<int> rotate_non_max_suppression_cpu(py::array_t<DType> box_corners, ...@@ -97,15 +96,12 @@ std::vector<int> rotate_non_max_suppression_cpu(py::array_t<DType> box_corners,
for (int _i = 0; _i < ndets; ++_i) { for (int _i = 0; _i < ndets; ++_i) {
i = order_r(_i); i = order_r(_i);
if (suppressed_rw(i) == 1) if (suppressed_rw(i) == 1) continue;
continue;
keep.push_back(i); keep.push_back(i);
for (int _j = _i + 1; _j < ndets; ++_j) { for (int _j = _i + 1; _j < ndets; ++_j) {
j = order_r(_j); j = order_r(_j);
if (suppressed_rw(j) == 1) if (suppressed_rw(j) == 1) continue;
continue; if (standup_iou_r(i, j) <= 0.0) continue;
if (standup_iou_r(i, j) <= 0.0)
continue;
// std::cout << "pre_poly" << std::endl; // std::cout << "pre_poly" << std::endl;
try { try {
bg::append(poly, bg::append(poly,
...@@ -169,8 +165,7 @@ std::vector<int> rotate_non_max_suppression_cpu(py::array_t<DType> box_corners, ...@@ -169,8 +165,7 @@ std::vector<int> rotate_non_max_suppression_cpu(py::array_t<DType> box_corners,
// std::cout << "post union area" << std::endl; // std::cout << "post union area" << std::endl;
// std::cout << union_area << "debug" << std::endl; // std::cout << union_area << "debug" << std::endl;
overlap = inter_area / union_area; overlap = inter_area / union_area;
if (overlap >= thresh) if (overlap >= thresh) suppressed_rw(j) = 1;
suppressed_rw(j) = 1;
poly_union.clear(); poly_union.clear();
} }
} }
......
...@@ -16,21 +16,16 @@ ...@@ -16,21 +16,16 @@
#define NMS_FUNCTOR_H_ #define NMS_FUNCTOR_H_
#include <tensorview/tensorview.h> #include <tensorview/tensorview.h>
namespace spconv namespace spconv {
{ namespace functor {
namespace functor
{
template <typename Device, typename T, typename Index> template <typename Device, typename T, typename Index>
struct NonMaxSupressionFunctor struct NonMaxSupressionFunctor {
{
Index operator()(const Device& d, tv::TensorView<Index> keep, Index operator()(const Device& d, tv::TensorView<Index> keep,
tv::TensorView<const T> boxes, tv::TensorView<const T> boxes, T threshold, T eps);
T threshold, T eps);
}; };
template <typename Device, typename T, typename Index> template <typename Device, typename T, typename Index>
struct rotateNonMaxSupressionFunctor struct rotateNonMaxSupressionFunctor {
{
Index operator()(const Device& d, tv::TensorView<Index> keep, Index operator()(const Device& d, tv::TensorView<Index> keep,
tv::TensorView<const T> boxCorners, tv::TensorView<const T> boxCorners,
tv::TensorView<const T> standupIoU, T threshold); tv::TensorView<const T> standupIoU, T threshold);
......
...@@ -16,13 +16,15 @@ ...@@ -16,13 +16,15 @@
#include <pybind11/pybind11.h> #include <pybind11/pybind11.h>
// must include pybind11/eigen.h if using eigen matrix as arguments. // must include pybind11/eigen.h if using eigen matrix as arguments.
// must include pybind11/stl.h if using containers in STL in arguments. // must include pybind11/stl.h if using containers in STL in arguments.
#include <algorithm>
#include <pybind11/numpy.h> #include <pybind11/numpy.h>
#include <pybind11/stl.h> #include <pybind11/stl.h>
#include <algorithm>
// #include <vector> // #include <vector>
#include <iostream>
#include <math.h> #include <math.h>
#include <iostream>
namespace spconv { namespace spconv {
namespace py = pybind11; namespace py = pybind11;
using namespace pybind11::literals; using namespace pybind11::literals;
...@@ -64,13 +66,11 @@ int points_to_voxel_3d_np(py::array_t<DType> points, py::array_t<DType> voxels, ...@@ -64,13 +66,11 @@ int points_to_voxel_3d_np(py::array_t<DType> points, py::array_t<DType> voxels,
} }
coor[ndim_minus_1 - j] = c; coor[ndim_minus_1 - j] = c;
} }
if (failed) if (failed) continue;
continue;
voxelidx = coor_to_voxelidx_rw(coor[0], coor[1], coor[2]); voxelidx = coor_to_voxelidx_rw(coor[0], coor[1], coor[2]);
if (voxelidx == -1) { if (voxelidx == -1) {
voxelidx = voxel_num; voxelidx = voxel_num;
if (voxel_num >= max_voxels) if (voxel_num >= max_voxels) break;
break;
voxel_num += 1; voxel_num += 1;
coor_to_voxelidx_rw(coor[0], coor[1], coor[2]) = voxelidx; coor_to_voxelidx_rw(coor[0], coor[1], coor[2]) = voxelidx;
for (int k = 0; k < NDim; ++k) { for (int k = 0; k < NDim; ++k) {
...@@ -87,15 +87,14 @@ int points_to_voxel_3d_np(py::array_t<DType> points, py::array_t<DType> voxels, ...@@ -87,15 +87,14 @@ int points_to_voxel_3d_np(py::array_t<DType> points, py::array_t<DType> voxels,
} }
for (int i = 0; i < voxel_num; ++i) { for (int i = 0; i < voxel_num; ++i) {
coor_to_voxelidx_rw(coors_rw(i, 0), coors_rw(i, 1), coors_rw(i, 2)) = -1; coor_to_voxelidx_rw(coors_rw(i, 0), coors_rw(i, 1), coors_rw(i, 2)) = -1;
} }
return voxel_num; return voxel_num;
} }
template <typename DType, int NDim> template <typename DType, int NDim>
int points_to_voxel_3d_np_mean(py::array_t<DType> points, py::array_t<DType> voxels, int points_to_voxel_3d_np_mean(py::array_t<DType> points,
py::array_t<DType> means, py::array_t<DType> voxels,
py::array_t<int> coors, py::array_t<DType> means, py::array_t<int> coors,
py::array_t<int> num_points_per_voxel, py::array_t<int> num_points_per_voxel,
py::array_t<int> coor_to_voxelidx, py::array_t<int> coor_to_voxelidx,
std::vector<DType> voxel_size, std::vector<DType> voxel_size,
...@@ -131,13 +130,11 @@ int points_to_voxel_3d_np_mean(py::array_t<DType> points, py::array_t<DType> vox ...@@ -131,13 +130,11 @@ int points_to_voxel_3d_np_mean(py::array_t<DType> points, py::array_t<DType> vox
} }
coor[ndim_minus_1 - j] = c; coor[ndim_minus_1 - j] = c;
} }
if (failed) if (failed) continue;
continue;
voxelidx = coor_to_voxelidx_rw(coor[0], coor[1], coor[2]); voxelidx = coor_to_voxelidx_rw(coor[0], coor[1], coor[2]);
if (voxelidx == -1) { if (voxelidx == -1) {
voxelidx = voxel_num; voxelidx = voxel_num;
if (voxel_num >= max_voxels) if (voxel_num >= max_voxels) break;
break;
voxel_num += 1; voxel_num += 1;
coor_to_voxelidx_rw(coor[0], coor[1], coor[2]) = voxelidx; coor_to_voxelidx_rw(coor[0], coor[1], coor[2]) = voxelidx;
for (int k = 0; k < NDim; ++k) { for (int k = 0; k < NDim; ++k) {
...@@ -151,14 +148,15 @@ int points_to_voxel_3d_np_mean(py::array_t<DType> points, py::array_t<DType> vox ...@@ -151,14 +148,15 @@ int points_to_voxel_3d_np_mean(py::array_t<DType> points, py::array_t<DType> vox
} }
num_points_per_voxel_rw(voxelidx) += 1; num_points_per_voxel_rw(voxelidx) += 1;
for (int k = 0; k < num_features; ++k) { for (int k = 0; k < num_features; ++k) {
means_rw(voxelidx, k) += (points_rw(i, k) - means_rw(voxelidx, k)) / DType(num + 1); means_rw(voxelidx, k) +=
(points_rw(i, k) - means_rw(voxelidx, k)) / DType(num + 1);
} }
} }
} }
for (int i = 0; i < voxel_num; ++i) { for (int i = 0; i < voxel_num; ++i) {
coor_to_voxelidx_rw(coors_rw(i, 0), coors_rw(i, 1), coors_rw(i, 2)) = -1; coor_to_voxelidx_rw(coors_rw(i, 0), coors_rw(i, 1), coors_rw(i, 2)) = -1;
num = num_points_per_voxel_rw(i); num = num_points_per_voxel_rw(i);
for (int j = num; j < max_points; ++j){ for (int j = num; j < max_points; ++j) {
for (int k = 0; k < num_features; ++k) { for (int k = 0; k < num_features; ++k) {
voxels_rw(i, j, k) = means_rw(i, k); voxels_rw(i, j, k) = means_rw(i, k);
} }
...@@ -168,15 +166,12 @@ int points_to_voxel_3d_np_mean(py::array_t<DType> points, py::array_t<DType> vox ...@@ -168,15 +166,12 @@ int points_to_voxel_3d_np_mean(py::array_t<DType> points, py::array_t<DType> vox
} }
template <typename DType, int NDim> template <typename DType, int NDim>
int points_to_voxel_3d_np_height(py::array_t<DType> points, py::array_t<DType> voxels, int points_to_voxel_3d_np_height(
py::array_t<DType> height, py::array_t<DType> points, py::array_t<DType> voxels,
py::array_t<DType> maxs, py::array_t<DType> height, py::array_t<DType> maxs, py::array_t<int> coors,
py::array_t<int> coors, py::array_t<int> num_points_per_voxel, py::array_t<int> coor_to_voxelidx,
py::array_t<int> num_points_per_voxel, std::vector<DType> voxel_size, std::vector<DType> coors_range,
py::array_t<int> coor_to_voxelidx, int max_points, int max_voxels) {
std::vector<DType> voxel_size,
std::vector<DType> coors_range, int max_points,
int max_voxels) {
auto points_rw = points.template mutable_unchecked<2>(); auto points_rw = points.template mutable_unchecked<2>();
auto height_rw = height.template mutable_unchecked<2>(); auto height_rw = height.template mutable_unchecked<2>();
auto maxs_rw = maxs.template mutable_unchecked<2>(); auto maxs_rw = maxs.template mutable_unchecked<2>();
...@@ -208,13 +203,11 @@ int points_to_voxel_3d_np_height(py::array_t<DType> points, py::array_t<DType> v ...@@ -208,13 +203,11 @@ int points_to_voxel_3d_np_height(py::array_t<DType> points, py::array_t<DType> v
} }
coor[ndim_minus_1 - j] = c; coor[ndim_minus_1 - j] = c;
} }
if (failed) if (failed) continue;
continue;
voxelidx = coor_to_voxelidx_rw(coor[0], coor[1], coor[2]); voxelidx = coor_to_voxelidx_rw(coor[0], coor[1], coor[2]);
if (voxelidx == -1) { if (voxelidx == -1) {
voxelidx = voxel_num; voxelidx = voxel_num;
if (voxel_num >= max_voxels) if (voxel_num >= max_voxels) break;
break;
voxel_num += 1; voxel_num += 1;
coor_to_voxelidx_rw(coor[0], coor[1], coor[2]) = voxelidx; coor_to_voxelidx_rw(coor[0], coor[1], coor[2]) = voxelidx;
for (int k = 0; k < NDim; ++k) { for (int k = 0; k < NDim; ++k) {
...@@ -225,7 +218,8 @@ int points_to_voxel_3d_np_height(py::array_t<DType> points, py::array_t<DType> v ...@@ -225,7 +218,8 @@ int points_to_voxel_3d_np_height(py::array_t<DType> points, py::array_t<DType> v
if (num < max_points) { if (num < max_points) {
for (int k = 0; k < num_features; ++k) { for (int k = 0; k < num_features; ++k) {
voxels_rw(voxelidx, num, k) = points_rw(i, k); voxels_rw(voxelidx, num, k) = points_rw(i, k);
height_rw(voxelidx, k) = std::min(points_rw(i, k), height_rw(voxelidx, k)); height_rw(voxelidx, k) =
std::min(points_rw(i, k), height_rw(voxelidx, k));
maxs_rw(voxelidx, k) = std::max(points_rw(i, k), maxs_rw(voxelidx, k)); maxs_rw(voxelidx, k) = std::max(points_rw(i, k), maxs_rw(voxelidx, k));
} }
num_points_per_voxel_rw(voxelidx) += 1; num_points_per_voxel_rw(voxelidx) += 1;
...@@ -241,15 +235,11 @@ int points_to_voxel_3d_np_height(py::array_t<DType> points, py::array_t<DType> v ...@@ -241,15 +235,11 @@ int points_to_voxel_3d_np_height(py::array_t<DType> points, py::array_t<DType> v
} }
template <typename DType, int NDim> template <typename DType, int NDim>
int block_filtering(py::array_t<DType> points, int block_filtering(py::array_t<DType> points, py::array_t<int> mask,
py::array_t<int> mask, py::array_t<DType> height, py::array_t<DType> maxs,
py::array_t<DType> height,
py::array_t<DType> maxs,
py::array_t<int> coor_to_voxelidx, py::array_t<int> coor_to_voxelidx,
std::vector<DType> voxel_size, std::vector<DType> voxel_size,
std::vector<DType> coors_range, std::vector<DType> coors_range, int max_voxels, DType eps) {
int max_voxels,
DType eps) {
auto points_rw = points.template mutable_unchecked<2>(); auto points_rw = points.template mutable_unchecked<2>();
auto height_rw = height.template mutable_unchecked<1>(); auto height_rw = height.template mutable_unchecked<1>();
auto maxs_rw = maxs.template mutable_unchecked<1>(); auto maxs_rw = maxs.template mutable_unchecked<1>();
...@@ -278,8 +268,7 @@ int block_filtering(py::array_t<DType> points, ...@@ -278,8 +268,7 @@ int block_filtering(py::array_t<DType> points,
} }
coor[ndim_minus_1 - j] = c; coor[ndim_minus_1 - j] = c;
} }
if (failed) if (failed) continue;
continue;
voxelidx = coor_to_voxelidx_rw(coor[0], coor[1], coor[2]); voxelidx = coor_to_voxelidx_rw(coor[0], coor[1], coor[2]);
if (voxelidx == -1) { if (voxelidx == -1) {
voxelidx = voxel_num; voxelidx = voxel_num;
...@@ -299,29 +288,22 @@ int block_filtering(py::array_t<DType> points, ...@@ -299,29 +288,22 @@ int block_filtering(py::array_t<DType> points,
} }
coor[ndim_minus_1 - j] = c; coor[ndim_minus_1 - j] = c;
} }
if (failed) if (failed) continue;
continue;
voxelidx = coor_to_voxelidx_rw(coor[0], coor[1], coor[2]); voxelidx = coor_to_voxelidx_rw(coor[0], coor[1], coor[2]);
if ((maxs_rw(voxelidx) - height_rw(voxelidx, 2)) < eps){ if ((maxs_rw(voxelidx) - height_rw(voxelidx, 2)) < eps) {
mask(i) = 0; mask(i) = 0;
} }
} }
} }
template <typename DType, int NDim> template <typename DType, int NDim>
int points_to_voxel_3d_with_filtering(py::array_t<DType> points, py::array_t<DType> voxels, int points_to_voxel_3d_with_filtering(
py::array_t<int> voxel_mask, py::array_t<DType> points, py::array_t<DType> voxels,
py::array_t<DType> mins, py::array_t<int> voxel_mask, py::array_t<DType> mins,
py::array_t<DType> maxs, py::array_t<DType> maxs, py::array_t<int> coors,
py::array_t<int> coors, py::array_t<int> num_points_per_voxel, py::array_t<int> coor_to_voxelidx,
py::array_t<int> num_points_per_voxel, std::vector<DType> voxel_size, std::vector<DType> coors_range,
py::array_t<int> coor_to_voxelidx, int max_points, int max_voxels, int block_factor, int block_size,
std::vector<DType> voxel_size,
std::vector<DType> coors_range,
int max_points,
int max_voxels,
int block_factor,
int block_size,
DType height_threshold) { DType height_threshold) {
auto points_rw = points.template mutable_unchecked<2>(); auto points_rw = points.template mutable_unchecked<2>();
auto mins_rw = mins.template mutable_unchecked<2>(); auto mins_rw = mins.template mutable_unchecked<2>();
...@@ -361,13 +343,11 @@ int points_to_voxel_3d_with_filtering(py::array_t<DType> points, py::array_t<DTy ...@@ -361,13 +343,11 @@ int points_to_voxel_3d_with_filtering(py::array_t<DType> points, py::array_t<DTy
} }
coor[ndim_minus_1 - j] = c; coor[ndim_minus_1 - j] = c;
} }
if (failed) if (failed) continue;
continue;
voxelidx = coor_to_voxelidx_rw(coor[0], coor[1], coor[2]); voxelidx = coor_to_voxelidx_rw(coor[0], coor[1], coor[2]);
if (voxelidx == -1) { if (voxelidx == -1) {
voxelidx = voxel_num; voxelidx = voxel_num;
if (voxel_num >= max_voxels) if (voxel_num >= max_voxels) break;
break;
voxel_num += 1; voxel_num += 1;
coor_to_voxelidx_rw(coor[0], coor[1], coor[2]) = voxelidx; coor_to_voxelidx_rw(coor[0], coor[1], coor[2]) = voxelidx;
for (int k = 0; k < NDim; ++k) { for (int k = 0; k < NDim; ++k) {
...@@ -381,8 +361,10 @@ int points_to_voxel_3d_with_filtering(py::array_t<DType> points, py::array_t<DTy ...@@ -381,8 +361,10 @@ int points_to_voxel_3d_with_filtering(py::array_t<DType> points, py::array_t<DTy
} }
block_coor[0] = coor[1] / block_factor; block_coor[0] = coor[1] / block_factor;
block_coor[1] = coor[2] / block_factor; block_coor[1] = coor[2] / block_factor;
mins_rw(block_coor[0], block_coor[1]) = std::min(points_rw(i, 2), mins_rw(block_coor[0], block_coor[1])); mins_rw(block_coor[0], block_coor[1]) =
maxs_rw(block_coor[0], block_coor[1]) = std::max(points_rw(i, 2), maxs_rw(block_coor[0], block_coor[1])); std::min(points_rw(i, 2), mins_rw(block_coor[0], block_coor[1]));
maxs_rw(block_coor[0], block_coor[1]) =
std::max(points_rw(i, 2), maxs_rw(block_coor[0], block_coor[1]));
num_points_per_voxel_rw(voxelidx) += 1; num_points_per_voxel_rw(voxelidx) += 1;
} }
} }
...@@ -394,13 +376,15 @@ int points_to_voxel_3d_with_filtering(py::array_t<DType> points, py::array_t<DTy ...@@ -394,13 +376,15 @@ int points_to_voxel_3d_with_filtering(py::array_t<DType> points, py::array_t<DTy
block_coor[1] = coor[2] / block_factor; block_coor[1] = coor[2] / block_factor;
min_value = mins_rw(block_coor[0], block_coor[1]); min_value = mins_rw(block_coor[0], block_coor[1]);
max_value = maxs_rw(block_coor[0], block_coor[1]); max_value = maxs_rw(block_coor[0], block_coor[1]);
startx = std::max(0, block_coor[0]-block_size/2); startx = std::max(0, block_coor[0] - block_size / 2);
stopx = std::min(block_shape_H, block_coor[0]+block_size-block_size/2); stopx =
starty = std::max(0, block_coor[1]-block_size/2); std::min(block_shape_H, block_coor[0] + block_size - block_size / 2);
stopy = std::min(block_shape_W, block_coor[1]+block_size-block_size/2); starty = std::max(0, block_coor[1] - block_size / 2);
stopy =
std::min(block_shape_W, block_coor[1] + block_size - block_size / 2);
for (int j = startx; j < stopx; ++j){ for (int j = startx; j < stopx; ++j) {
for (int k = starty; k < stopy; ++k){ for (int k = starty; k < stopy; ++k) {
min_value = std::min(min_value, mins_rw(j, k)); min_value = std::min(min_value, mins_rw(j, k));
max_value = std::max(max_value, maxs_rw(j, k)); max_value = std::max(max_value, maxs_rw(j, k));
} }
...@@ -410,5 +394,4 @@ int points_to_voxel_3d_with_filtering(py::array_t<DType> points, py::array_t<DTy ...@@ -410,5 +394,4 @@ int points_to_voxel_3d_with_filtering(py::array_t<DType> points, py::array_t<DTy
return voxel_num; return voxel_num;
} }
} // namespace spconv } // namespace spconv
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
import torch import torch
def test_voting_module(): def test_vote_module():
from mmdet3d.ops import VoteModule from mmdet3d.models.model_utils import VoteModule
self = VoteModule(vote_per_seed=3, in_channels=8) vote_loss = dict(
type='ChamferDistance',
mode='l1',
reduction='none',
loss_dst_weight=10.0)
self = VoteModule(vote_per_seed=3, in_channels=8, vote_loss=vote_loss)
seed_xyz = torch.rand([2, 64, 3], dtype=torch.float32) # (b, npoints, 3) seed_xyz = torch.rand([2, 64, 3], dtype=torch.float32) # (b, npoints, 3)
seed_features = torch.rand( seed_features = torch.rand(
......
This diff is collapsed.
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