From 5939b5102f5897eada0934e1aba6dfbf3a858bd5 Mon Sep 17 00:00:00 2001 From: Shilong Zhang <61961338+jshilong@users.noreply.github.com> Date: Thu, 2 Dec 2021 15:01:17 +0800 Subject: [PATCH] [Fix]fix init when densehead contains dcn (#6625) * fix init when densehead contains dcn * change to constant init --- mmdet/models/dense_heads/base_dense_head.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mmdet/models/dense_heads/base_dense_head.py b/mmdet/models/dense_heads/base_dense_head.py index ae10936615f..d3895f7a959 100644 --- a/mmdet/models/dense_heads/base_dense_head.py +++ b/mmdet/models/dense_heads/base_dense_head.py @@ -2,6 +2,7 @@ from abc import ABCMeta, abstractmethod import torch +from mmcv.cnn.utils.weight_init import constant_init from mmcv.ops import batched_nms from mmcv.runner import BaseModule, force_fp32 @@ -14,6 +15,14 @@ class BaseDenseHead(BaseModule, metaclass=ABCMeta): def __init__(self, init_cfg=None): super(BaseDenseHead, self).__init__(init_cfg) + def init_weights(self): + super(BaseDenseHead, self).init_weights() + # avoid init_cfg overwrite the initialization of `conv_offset` + for m in self.modules(): + # DeformConv2dPack, ModulatedDeformConv2dPack + if hasattr(m, 'conv_offset'): + constant_init(m.conv_offset, 0) + @abstractmethod def loss(self, **kwargs): """Compute losses of the head."""