mmcv
mmcv copied to clipboard
MaskedCol2imForward exist the bug of array out of bounds
Thanks for reporting the unexpected results and we appreciate it a lot.
Checklist
- I have searched related issues but cannot get the expected help.
- I have read the FAQ documentation but cannot get the expected help.
- The unexpected results still exist in the latest version.
Describe the Issue A clear and concise description of what the bug is, including what results are expected and what the real results you got. Hi, I found there is a problem with the implement of MaskedCol2imForward in masked_conv2d_cuda_kernel.cuh . mask_h_idx and mask_w_idx is generated by mask in masked_conv.py. By "assert features.size()[2:] == mask.size()[1:]", we can know height and width of mask is equal to feature. mask_inds = torch.nonzero(mask[0] > 0, as_tuple=False), mask_h_idx = mask_inds[:, 0].contiguous() and mask_w_idx = mask_inds[:, 1].contiguous() means the coordinate range of mask_h_idx is [0, height)(height is the height of feature) and the coordinate range of mask_w_idx is [0, width)(width is the width of feature) . In masked_conv.py, output = features.new_zeros(batch_size, out_channel, out_h, out_w), and out_h = int(math.floor((features.size(2) + 2 * pad_h - (kernel_h - 1) - 1) / stride_h + 1)) and out_w = int(math.floor((features.size(3) + 2 * pad_w - (kernel_h - 1) - 1) / stride_w + 1)), it means out_h may less than height and out_w may less than width. In function MaskedCol2imForward, "h_im = mask_h_idx[m_index]; w_im = mask_w_idx[m_index];data_im[(c_im * height + h_im) * width + w_im] = data_col[index];", h_im may larger than height and w_im may larger than width. Therefore, array out of bounds may occur in "data_im[(c_im * height + h_im) * width + w_im] = data_col[index];". Due to array out of bounds will not be checked in cuda C, so no error will be reported during execution. But there is still a problem with this function.
In addition, the existence of data coverage will lead to uncertainty. For example, height = 2, width =2, when c_im=0, h_im=2, w_im=0, data_im[4] will be writed, but c_im=1, h_im=0, w_im=0 also can write data_im[4].
Thanks for reporting and this is a potential bug. In the models that adopts MaskedConv2d, input and output sizes are the same, and current implementation does not support a smaller output feature map. We will fix it asap.
In addition, the existence of data coverage will lead to uncertainty. For example, height = 2, width =2, when c_im=0, h_im=2, w_im=0, data_im[4] will be writed, but c_im=1, h_im=0, w_im=0 also can write data_im[4].
As long as we assume input and output share the same size, for height=2, h_im=2 is not possible.