DCNv2
DCNv2 copied to clipboard
add apex support with opt level o1
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
https://github.com/lbin/DCNv2/blob/master/dcn_v2.py#L43 maybe you should clean you dcn env and recompile the dcn codes @JesseYang
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)
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()