Unverified Commit 882822e0 authored by Fu0511's avatar Fu0511 Committed by GitHub
Browse files

[Fix] Fix the weight initialization of deform conv (#1262)



* Update deform_conv.py

* polish the docstring of reset_parameters

* change the initialization of `self.weight`

switch the initialization of `self.weight` to the standard kaiming method
Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>
parent f22c9eb4
# Copyright (c) OpenMMLab. All rights reserved. # Copyright (c) OpenMMLab. All rights reserved.
import math
from typing import Tuple, Union from typing import Tuple, Union
import torch import torch
...@@ -256,11 +255,11 @@ class DeformConv2d(nn.Module): ...@@ -256,11 +255,11 @@ class DeformConv2d(nn.Module):
self.reset_parameters() self.reset_parameters()
def reset_parameters(self): def reset_parameters(self):
n = self.in_channels # switch the initialization of `self.weight` to the standard kaiming
for k in self.kernel_size: # method described in `Delving deep into rectifiers: Surpassing
n *= k # human-level performance on ImageNet classification` - He, K. et al.
stdv = 1. / math.sqrt(n) # (2015), using a uniform distribution
self.weight.data.uniform_(-stdv, stdv) nn.init.kaiming_uniform_(self.weight, nonlinearity='relu')
def forward(self, x: Tensor, offset: Tensor) -> Tensor: def forward(self, x: Tensor, offset: Tensor) -> Tensor:
"""Deformable Convolutional forward function. """Deformable Convolutional forward function.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment