InternImage
InternImage copied to clipboard
AttributeError: type object 'DCNv3' has no attribute 'dcnv3_forward'
Hi , I was trying to create a separate object of DCNv3
dcn = DCNv3(
channels=3,
kernel_size=3,
stride=1,
pad=1,
dilation=1,
group=1,)
x = torch.randn(2, 64, 64, 3)
but I encountered the following error
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
[/home/thor/pythonProjects/InternImage/segmentation/test_notebook.ipynb](https://file/+.[vscode-resource.vscode-cdn.net/home/thor/pythonProjects/InternImage/segmentation/test_notebook.ipynb](http://vscode-resource.vscode-cdn.net/home/thor/pythonProjects/InternImage/segmentation/test_notebook.ipynb)) Cell 9 line 1
----> [1](vscode-notebook-cell:/home/thor/pythonProjects/InternImage/segmentation/test_notebook.ipynb#X11sZmlsZQ%3D%3D?line=0) dcn(x.permute(0,2,3,1))
File [~/anaconda3/envs/torchenv/lib/python3.9/site-packages/torch/nn/modules/module.py:1501](https://file/+.[vscode-resource.vscode-cdn.net/home/thor/pythonProjects/InternImage/segmentation/~/anaconda3/envs/torchenv/lib/python3.9/site-packages/torch/nn/modules/module.py:1501](http://vscode-resource.vscode-cdn.net/home/thor/pythonProjects/InternImage/segmentation/~/anaconda3/envs/torchenv/lib/python3.9/site-packages/torch/nn/modules/module.py:1501)), in Module._call_impl(self, *args, **kwargs)
1496 # If we don't have any hooks, we want to skip the rest of the logic in
1497 # this function, and just call forward.
1498 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
1499 or _global_backward_pre_hooks or _global_backward_hooks
1500 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1501 return forward_call(*args, **kwargs)
1502 # Do not call functions when jit is used
1503 full_backward_hooks, non_full_backward_hooks = [], []
File [~/pythonProjects/InternImage/segmentation/ops_dcnv3/modules/dcnv3_base.py:272](https://file/+.[vscode-resource.vscode-cdn.net/home/thor/pythonProjects/InternImage/segmentation/~/pythonProjects/InternImage/segmentation/ops_dcnv3/modules/dcnv3_base.py:272](http://vscode-resource.vscode-cdn.net/home/thor/pythonProjects/InternImage/segmentation/~/pythonProjects/InternImage/segmentation/ops_dcnv3/modules/dcnv3_base.py:272)), in DCNv3.forward(self, input)
269 mask = self.mask(x1).reshape(N, H, W, self.group, -1)
270 mask = F.softmax(mask, -1).reshape(N, H, W, -1).type(dtype)
--> 272 x = DCNv3Function.apply(
273 x, offset, mask,
274 self.kernel_size, self.kernel_size,
275 self.stride, self.stride,
276 self.pad, self.pad,
277 self.dilation, self.dilation,
278 self.group, self.group_channels,
279 self.offset_scale,
280 256)
282 if self.center_feature_scale:
283 center_feature_scale = self.center_feature_scale_module(
284 x1, self.center_feature_scale_proj_weight, self.center_feature_scale_proj_bias)
File [~/anaconda3/envs/torchenv/lib/python3.9/site-packages/torch/autograd/function.py:506](https://file/+.[vscode-resource.vscode-cdn.net/home/thor/pythonProjects/InternImage/segmentation/~/anaconda3/envs/torchenv/lib/python3.9/site-packages/torch/autograd/function.py:506](http://vscode-resource.vscode-cdn.net/home/thor/pythonProjects/InternImage/segmentation/~/anaconda3/envs/torchenv/lib/python3.9/site-packages/torch/autograd/function.py:506)), in Function.apply(cls, *args, **kwargs)
503 if not torch._C._are_functorch_transforms_active():
504 # See NOTE: [functorch vjp and autograd interaction]
505 args = _functorch.utils.unwrap_dead_wrappers(args)
--> 506 return super().apply(*args, **kwargs) # type: ignore[misc]
508 if cls.setup_context == _SingleLevelFunction.setup_context:
509 raise RuntimeError(
510 'In order to use an autograd.Function with functorch transforms '
511 '(vmap, grad, jvp, jacrev, ...), it must override the setup_context '
512 'staticmethod. For more details, please see '
513 'https://pytorch.org/docs/master/notes/extending.func.html')
File [~/anaconda3/envs/torchenv/lib/python3.9/site-packages/torch/cuda/amp/autocast_mode.py:98](https://file/+.[vscode-resource.vscode-cdn.net/home/thor/pythonProjects/InternImage/segmentation/~/anaconda3/envs/torchenv/lib/python3.9/site-packages/torch/cuda/amp/autocast_mode.py:98](http://vscode-resource.vscode-cdn.net/home/thor/pythonProjects/InternImage/segmentation/~/anaconda3/envs/torchenv/lib/python3.9/site-packages/torch/cuda/amp/autocast_mode.py:98)), in custom_fwd.<locals>.decorate_fwd(*args, **kwargs)
96 if cast_inputs is None:
97 args[0]._fwd_used_autocast = torch.is_autocast_enabled()
---> 98 return fwd(*args, **kwargs)
99 else:
100 autocast_context = torch.is_autocast_enabled()
File [~/pythonProjects/InternImage/segmentation/ops_dcnv3/modules/dcnv3_base.py:39](https://file/+.[vscode-resource.vscode-cdn.net/home/thor/pythonProjects/InternImage/segmentation/~/pythonProjects/InternImage/segmentation/ops_dcnv3/modules/dcnv3_base.py:39](http://vscode-resource.vscode-cdn.net/home/thor/pythonProjects/InternImage/segmentation/~/pythonProjects/InternImage/segmentation/ops_dcnv3/modules/dcnv3_base.py:39)), in DCNv3Function.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)
37 ctx.offset_scale = offset_scale
38 ctx.im2col_step = im2col_step
---> 39 output = DCNv3.dcnv3_forward(
40 input, offset, mask, kernel_h,
41 kernel_w, stride_h, stride_w, pad_h,
42 pad_w, dilation_h, dilation_w, group,
43 group_channels, offset_scale, ctx.im2col_step)
44 ctx.save_for_backward(input, offset, mask)
46 return output
AttributeError: type object 'DCNv3' has no attribute 'dcnv3_forward'
Kindly guide me what are the steps that are needed to be taken.
You should have not compiled DCNv3! The dcnv3_forward and dcnv3_backward functions are written in C++ and finally compiled into DCNv3.pyd.
So you should use the command below to compile.
python setup.py build_ext install
After loading the DLL when the code is running, you can use DCNv3. Of course, if you do not compile, you can only use the dcnv3_pytorch function, and the inference speed may be slower.