diff --git a/torchvision/csrc/ops/cpu/ps_roi_align_kernel.cpp b/torchvision/csrc/ops/cpu/ps_roi_align_kernel.cpp index 5e33fc0bc62..4f78d59ae6b 100644 --- a/torchvision/csrc/ops/cpu/ps_roi_align_kernel.cpp +++ b/torchvision/csrc/ops/cpu/ps_roi_align_kernel.cpp @@ -62,7 +62,7 @@ T bilinear_interpolate( template void ps_roi_align_forward_kernel_impl( - int nthreads, + int num_rois, const T* input, const T spatial_scale, int channels, @@ -75,7 +75,6 @@ void ps_roi_align_forward_kernel_impl( int channels_out, T* output, int* channel_mapping) { - int num_rois = nthreads / channels_out / pooled_width / pooled_height; for (int n = 0; n < num_rois; n++) { // [start, end) interval for spatial sampling const T* offset_rois = rois + n * 5; @@ -335,8 +334,7 @@ std::tuple ps_roi_align_forward_kernel( auto channel_mapping = at::zeros(output.sizes(), input.options().dtype(at::kInt)); - auto output_size = output.numel(); - if (output_size == 0) { + if (output.numel() == 0) { return std::make_tuple(output, channel_mapping); } @@ -344,7 +342,7 @@ std::tuple ps_roi_align_forward_kernel( AT_DISPATCH_FLOATING_TYPES_AND_HALF( input.scalar_type(), "ps_roi_align_forward_kernel", [&] { ps_roi_align_forward_kernel_impl( - output_size, + num_rois, input_.data_ptr(), spatial_scale, channels, diff --git a/torchvision/csrc/ops/cpu/roi_align_kernel.cpp b/torchvision/csrc/ops/cpu/roi_align_kernel.cpp index 8e86104513b..dc0c38cd314 100644 --- a/torchvision/csrc/ops/cpu/roi_align_kernel.cpp +++ b/torchvision/csrc/ops/cpu/roi_align_kernel.cpp @@ -117,7 +117,7 @@ void pre_calc_for_bilinear_interpolate( template void roi_align_forward_kernel_impl( - int nthreads, + int n_rois, const T* input, const T& spatial_scale, int channels, @@ -129,7 +129,6 @@ void roi_align_forward_kernel_impl( bool aligned, const T* rois, T* output) { - int n_rois = nthreads / channels / pooled_width / pooled_height; // (n, c, ph, pw) is an element in the pooled output // can be parallelized using omp // #pragma omp parallel for num_threads(32) @@ -414,8 +413,6 @@ at::Tensor roi_align_forward_kernel( at::Tensor output = at::zeros( {num_rois, channels, pooled_height, pooled_width}, input.options()); - auto output_size = num_rois * pooled_height * pooled_width * channels; - if (output.numel() == 0) return output; @@ -423,7 +420,7 @@ at::Tensor roi_align_forward_kernel( AT_DISPATCH_FLOATING_TYPES_AND_HALF( input.scalar_type(), "roi_align_forward_kernel", [&] { roi_align_forward_kernel_impl( - output_size, + num_rois, input_.data_ptr(), spatial_scale, channels,