未验证 提交 c8e49be2 编写于 作者: W whs 提交者: GitHub

Fix roi_perspective_transform op (#20764)

上级 6bdf99d3
......@@ -187,17 +187,17 @@ void bilinear_interpolate(const T* in_data, const int channels, const int width,
const int height, int in_n, int in_c, T in_w, T in_h,
T* val) {
// Deal with cases that source coords are out of feature map boundary
if (GT<T>(-0.5, in_w) || GT<T>(in_w, width - 0.5) || GT<T>(-0.5, in_h) ||
GT<T>(in_h, height - 0.5)) {
if (GT_E<T>(-0.5, in_w) || GT_E<T>(in_w, width - 0.5) ||
GT_E<T>(-0.5, in_h) || GT_E<T>(in_h, height - 0.5)) {
// empty
val[0] = 0.0;
return;
}
if (GT<T>(0, in_w)) {
if (GT_E<T>(0, in_w)) {
in_w = 0;
}
if (GT<T>(0, in_h)) {
if (GT_E<T>(0, in_h)) {
in_h = 0;
}
......@@ -301,10 +301,10 @@ class CPUROIPerspectiveTransformOpKernel : public framework::OpKernel<T> {
T in_w, in_h;
get_source_coords<T>(matrix, out_w, out_h, &in_w, &in_h);
if (in_quad<T>(in_w, in_h, roi_x, roi_y)) {
if (GT<T>(-0.5, in_w) ||
GT<T>(in_w, static_cast<T>(in_width - 0.5)) ||
GT<T>(-0.5, in_h) ||
GT<T>(in_h, static_cast<T>(in_height - 0.5))) {
if (GT_E<T>(-0.5, in_w) ||
GT_E<T>(in_w, static_cast<T>(in_width - 0.5)) ||
GT_E<T>(-0.5, in_h) ||
GT_E<T>(in_h, static_cast<T>(in_height - 0.5))) {
output_data[out_index] = 0.0;
mask_data[(n * transformed_height + out_h) * transformed_width +
out_w] = 0;
......@@ -330,15 +330,15 @@ class CPUROIPerspectiveTransformOpKernel : public framework::OpKernel<T> {
template <typename T>
T get_feature_gradient(T xs, T ys, int w, int h, const int width,
const int height) {
if (GT<T>(-0.5, xs) || GT<T>(xs, width - 0.5) || GT<T>(-0.5, ys) ||
GT<T>(ys, height - 0.5)) {
if (GT_E<T>(-0.5, xs) || GT_E<T>(xs, width - 0.5) || GT_E<T>(-0.5, ys) ||
GT_E<T>(ys, height - 0.5)) {
return 0;
}
if (GT<T>(0, xs)) {
if (GT_E<T>(0, xs)) {
xs = 0;
}
if (GT<T>(0, ys)) {
if (GT_E<T>(0, ys)) {
ys = 0;
}
......@@ -441,10 +441,10 @@ class CPUROIPerspectiveTransformGradOpKernel : public framework::OpKernel<T> {
T src_h;
get_source_coords<T>(matrix, out_w, out_h, &src_w, &src_h);
if (in_quad<T>(src_w, src_h, roi_x, roi_y)) {
if (GT<T>(-0.5, src_w) ||
GT<T>(src_w, static_cast<T>(in_width - 0.5)) ||
GT<T>(-0.5, src_h) ||
GT<T>(src_h, static_cast<T>(in_height - 0.5))) {
if (GT_E<T>(-0.5, src_w) ||
GT_E<T>(src_w, static_cast<T>(in_width - 0.5)) ||
GT_E<T>(-0.5, src_h) ||
GT_E<T>(src_h, static_cast<T>(in_height - 0.5))) {
continue;
}
T weight = get_feature_gradient<T>(src_w, src_h, in_w, in_h,
......
......@@ -120,16 +120,16 @@ __device__ void bilinear_interpolate(const T* in_data, const int channels,
int out_idx, int* out2in_idx,
T* out2in_w) {
// Deal with cases that source coords are out of feature map boundary
if (GT<T>(-0.5, in_w) || GT<T>(in_w, width - 0.5) || GT<T>(-0.5, in_h) ||
GT<T>(in_h, height - 0.5)) {
if (GT_E<T>(-0.5, in_w) || GT_E<T>(in_w, width - 0.5) ||
GT_E<T>(-0.5, in_h) || GT_E<T>(in_h, height - 0.5)) {
val[0] = 0.0;
return;
}
if (GT<T>(0, in_w)) {
if (GT_E<T>(0, in_w)) {
in_w = 0;
}
if (GT<T>(0, in_h)) {
if (GT_E<T>(0, in_h)) {
in_h = 0;
}
......@@ -284,7 +284,6 @@ __global__ void RoiTransformKernel(const float* input_data,
int* mask, T* transform_matrix) {
int output_size =
num_rois * transformed_height * transformed_width * channels;
CUDA_1D_KERNEL_LOOP(index, output_size) {
// (n, c, out_h, out_w) is an element in the transformed output
int out_w = idx4_4(index, num_rois, channels, transformed_height,
......@@ -318,8 +317,10 @@ __global__ void RoiTransformKernel(const float* input_data,
get_source_coords<T>(matrix, out_w, out_h, &in_w, &in_h);
if (in_quad<T>(in_w, in_h, roi_x, roi_y)) {
if (GT<T>(-0.5, in_w) || GT<T>(in_w, static_cast<T>(in_width - 0.5)) ||
GT<T>(-0.5, in_h) || GT<T>(in_h, static_cast<T>(in_height - 0.5))) {
if (GT_E<T>(-0.5, in_w) ||
GT_E<T>(in_w, static_cast<T>(in_width - 0.5)) ||
GT_E<T>(-0.5, in_h) ||
GT_E<T>(in_h, static_cast<T>(in_height - 0.5))) {
// Skip if source coords is not in input image
output_data[index] = 0.0;
mask[(n * transformed_height + out_h) * transformed_width + out_w] = 0;
......@@ -409,15 +410,15 @@ class CUDAROIPerspectiveTransformOpKernel : public framework::OpKernel<T> {
template <typename T>
__device__ T get_feature_gradient(T xs, T ys, int w, int h, const int width,
const int height) {
if (GT<T>(-0.5, xs) || GT<T>(xs, width - 0.5) || GT<T>(-0.5, ys) ||
GT<T>(ys, height - 0.5)) {
if (GT_E<T>(-0.5, xs) || GT_E<T>(xs, width - 0.5) || GT_E<T>(-0.5, ys) ||
GT_E<T>(ys, height - 0.5)) {
return 0;
}
if (GT<T>(0, xs)) {
if (GT_E<T>(0, xs)) {
xs = 0;
}
if (GT<T>(0, ys)) {
if (GT_E<T>(0, ys)) {
ys = 0;
}
......
......@@ -135,13 +135,13 @@ def bilinear_interpolate(in_data, in_n, in_c, in_w, in_h):
height = in_data.shape[2]
width = in_data.shape[3]
if gt(-0.5, in_w) or gt(in_w, width - 0.5) or gt(-0.5, in_h) or gt(
if gt_e(-0.5, in_w) or gt_e(in_w, width - 0.5) or gt_e(-0.5, in_h) or gt_e(
in_h, height - 0.5):
return 0.0
if gt(0, in_w):
if gt_e(0, in_w):
in_w = 0
if gt(0, in_h):
if gt_e(0, in_h):
in_h = 0
in_w_floor = floor(in_w)
......@@ -216,9 +216,9 @@ def roi_transform(in_data, rois, rois_lod, transformed_height,
for out_w in range(transformed_width):
in_w, in_h = get_source_coords(transform_matrix, out_w,
out_h)
if in_quad(in_w, in_h, roi_x, roi_y) and gt_e(
in_w, -0.5) and lt_e(in_w, in_width - 0.5) and gt_e(
in_h, -0.5) and lt_e(in_h, in_height - 0.5):
if in_quad(in_w, in_h, roi_x, roi_y) and gt(
in_w, -0.5) and gt(in_width - 0.5, in_w) and gt(
in_h, -0.5) and gt(in_height - 0.5, in_h):
out[n][c][out_h][out_w] = bilinear_interpolate(
in_data, image_id, c, in_w, in_h)
mask[n][0][out_h][out_w] = 1
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册