InternImage icon indicating copy to clipboard operation
InternImage copied to clipboard

RuntimeError: Not implemented on the CPU

Open leij0318 opened this issue 1 year ago • 3 comments

First, I successfully compiled DCNv3, but an error occurred when I performed inference and training! The following is the error that occurs.

  File "D:\project(yolo)\_DCNv3\functions\dcnv3_func.py", line 39, in forward
    output = DCNv3.dcnv3_forward(
RuntimeError: Not implemented on the CPU

DCNv3Function function in dcnv3_func.py

class DCNv3Function(Function):
    @staticmethod
    @custom_fwd
    def forward(
            ctx, input, offset, mask,
            kernel_h, kernel_w, stride_h, stride_w,
            pad_h, pad_w, dilation_h, dilation_w,
            group, group_channels, offset_scale, im2col_step):
        ctx.kernel_h = kernel_h
        ctx.kernel_w = kernel_w
        ctx.stride_h = stride_h
        ctx.stride_w = stride_w
        ctx.pad_h = pad_h
        ctx.pad_w = pad_w
        ctx.dilation_h = dilation_h
        ctx.dilation_w = dilation_w
        ctx.group = group
        ctx.group_channels = group_channels
        ctx.offset_scale = offset_scale
        ctx.im2col_step = im2col_step
        output = DCNv3.dcnv3_forward(
            input, offset, mask, kernel_h,
            kernel_w, stride_h, stride_w, pad_h,
            pad_w, dilation_h, dilation_w, group,
            group_channels, offset_scale, ctx.im2col_step)
        ctx.save_for_backward(input, offset, mask)

        return output

This is the model I defined.

class DCNV3_YoLo(nn.Module):
    def __init__(self, inc, ouc, k=1, s=1, p=None, g=1, act=True):
        super().__init__()

        self.conv = Conv(inc, ouc, k=1)
        self.dcnv3 = DCNv3(ouc, kernel_size=k, stride=s, group=g)
        # self.dcnv3 = DCNv3(ouc, kernel_size=k, stride=s, group=g)
        self.bn = nn.BatchNorm2d(ouc)
        # self.act = nn.SiLU() if act is True else (act if isinstance(act, nn.Module) else nn.Identity())
        self.act = Conv.default_act

    def forward(self, x):
        x = x
        x = self.conv(x)
        x = x.permute(0, 2, 3, 1)
        x = self.dcnv3(x)
        x = x.permute(0, 3, 1, 2)
        x = self.act(self.bn(x))
        return x

leij0318 avatar Oct 21 '23 08:10 leij0318

First, I successfully compiled DCNv3, but an error occurred when I performed inference and training! The following is the error that occurs.

  File "D:\project(yolo)\_DCNv3\functions\dcnv3_func.py", line 39, in forward
    output = DCNv3.dcnv3_forward(
RuntimeError: Not implemented on the CPU

DCNv3Function function in dcnv3_func.py

class DCNv3Function(Function):
    @staticmethod
    @custom_fwd
    def forward(
            ctx, input, offset, mask,
            kernel_h, kernel_w, stride_h, stride_w,
            pad_h, pad_w, dilation_h, dilation_w,
            group, group_channels, offset_scale, im2col_step):
        ctx.kernel_h = kernel_h
        ctx.kernel_w = kernel_w
        ctx.stride_h = stride_h
        ctx.stride_w = stride_w
        ctx.pad_h = pad_h
        ctx.pad_w = pad_w
        ctx.dilation_h = dilation_h
        ctx.dilation_w = dilation_w
        ctx.group = group
        ctx.group_channels = group_channels
        ctx.offset_scale = offset_scale
        ctx.im2col_step = im2col_step
        output = DCNv3.dcnv3_forward(
            input, offset, mask, kernel_h,
            kernel_w, stride_h, stride_w, pad_h,
            pad_w, dilation_h, dilation_w, group,
            group_channels, offset_scale, ctx.im2col_step)
        ctx.save_for_backward(input, offset, mask)

        return output

This is the model I defined.

class DCNV3_YoLo(nn.Module):
    def __init__(self, inc, ouc, k=1, s=1, p=None, g=1, act=True):
        super().__init__()

        self.conv = Conv(inc, ouc, k=1)
        self.dcnv3 = DCNv3(ouc, kernel_size=k, stride=s, group=g)
        # self.dcnv3 = DCNv3(ouc, kernel_size=k, stride=s, group=g)
        self.bn = nn.BatchNorm2d(ouc)
        # self.act = nn.SiLU() if act is True else (act if isinstance(act, nn.Module) else nn.Identity())
        self.act = Conv.default_act

    def forward(self, x):
        x = x
        x = self.conv(x)
        x = x.permute(0, 2, 3, 1)
        x = self.dcnv3(x)
        x = x.permute(0, 3, 1, 2)
        x = self.act(self.bn(x))
        return x

这个问题我也遇到了,请问你解决了吗?

Carolyn0822 avatar Nov 10 '23 02:11 Carolyn0822

I also meet this problem!!!!!! If u has solved it, could u give me some suggestions

ztbian-bzt avatar Jan 08 '24 06:01 ztbian-bzt

请问你是替换了yolo的backbone吗?

chenyao1216 avatar Jul 13 '24 03:07 chenyao1216