RangiLyu / nanodet

NanoDet-Plus⚡Super fast and lightweight anchor-free object detection model. 🔥Only 980 KB(int8) / 1.8MB (fp16) and run 97FPS on cellphone🔥
Apache License 2.0
5.78k stars 1.04k forks source link

Fix RuntimeError due to inplace operation (fpn.py) #493

Open y-okumura-isp opened 1 year ago

y-okumura-isp commented 1 year ago

Thank you for great OSS!

When we use FPN, we get the following error on torch==1.13.1. It looks like this is due to an in-place update of laterals at FPN.forward() in fpn.py.

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [1, 64, 20, 20]], which is output 0 of LeakyReluBackward1, is at version 2; expected version 1 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).

Here is the difference of yaml file.

$ git diff config/nanodet-plus-m_320.yml
     fpn:
-      name: GhostPAN
+      name: FPN # GhostPAN
       in_channels: [116, 232, 464]
-      out_channels: 96
-      kernel_size: 5
-      num_extra_level: 1
-      use_depthwise: True
+      num_outs: 3
+      out_channels: 96
       activation: LeakyReLU
     head:
-      strides: [8, 16, 32, 64]
+      strides: [8, 16, 32]
     aux_head:
-      strides: [8, 16, 32, 64]
+      strides: [8, 16, 32]
alessiamarcolini commented 1 year ago

Thank you for the fix @y-okumura-isp !!