DCNv2 icon indicating copy to clipboard operation
DCNv2 copied to clipboard

add apex support with opt level o1

Open lbin opened this issue 5 years ago • 4 comments

lbin avatar Feb 06 '20 02:02 lbin

I followed the code in this branch and got the following error: RuntimeError: Function _DCNv2Backward returned an invalid gradient at index 1 - expected type torch.cuda.HalfTensor but got torch.cuda.FloatTensor

JesseYang avatar Apr 18 '20 13:04 JesseYang

https://github.com/lbin/DCNv2/blob/master/dcn_v2.py#L43 maybe you should clean you dcn env and recompile the dcn codes @JesseYang

lbin avatar Apr 20 '20 09:04 lbin

Thanks for your reply. I don't think recompiling can solve this problem. I re-clone the code from https://github.com/lbin/DCNv2 and build it, but still got the same error. My pytorch version is 1.2. The usage of DCN in my network is: self.dcn = DCN(input_channel, output_channel, kernel_size=(3, 3), stride=1, padding=1, dilation=1, deformable_groups=1) ...... enc = self.dcn(enc)

JesseYang avatar Apr 20 '20 14:04 JesseYang

The problem is solved. I add the following three lines before return in the _backward function of _DCNv2 in dcn_v2.py:

grad_input = grad_input.half()
grad_offset = grad_offset.half()
grad_mask = grad_mask.half()

JesseYang avatar Apr 20 '20 22:04 JesseYang