|
|
|
@ -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,
|
|
|
|
|