Skip to content

Commit 7ea199e

Browse files
author
胡钧耀
authored
[Doc]: add type hints in yolo_neck (#9383)
1 parent 072449f commit 7ea199e

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

mmdet/models/necks/yolo_neck.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Copyright (c) OpenMMLab. All rights reserved.
22
# Copyright (c) 2019 Western Digital Corporation or its affiliates.
3+
from typing import List, Tuple
34

45
import torch
56
import torch.nn.functional as F
67
from mmcv.cnn import ConvModule
78
from mmengine.model import BaseModule
9+
from torch import Tensor
810

911
from mmdet.registry import MODELS
12+
from mmdet.utils import ConfigType, OptConfigType, OptMultiConfig
1013

1114

1215
class DetectionBlock(BaseModule):
@@ -33,12 +36,13 @@ class DetectionBlock(BaseModule):
3336
"""
3437

3538
def __init__(self,
36-
in_channels,
37-
out_channels,
38-
conv_cfg=None,
39-
norm_cfg=dict(type='BN', requires_grad=True),
40-
act_cfg=dict(type='LeakyReLU', negative_slope=0.1),
41-
init_cfg=None):
39+
in_channels: int,
40+
out_channels: int,
41+
conv_cfg: OptConfigType = None,
42+
norm_cfg: ConfigType = dict(type='BN', requires_grad=True),
43+
act_cfg: ConfigType = dict(
44+
type='LeakyReLU', negative_slope=0.1),
45+
init_cfg: OptMultiConfig = None) -> None:
4246
super(DetectionBlock, self).__init__(init_cfg)
4347
double_out_channels = out_channels * 2
4448

@@ -52,7 +56,7 @@ def __init__(self,
5256
out_channels, double_out_channels, 3, padding=1, **cfg)
5357
self.conv5 = ConvModule(double_out_channels, out_channels, 1, **cfg)
5458

55-
def forward(self, x):
59+
def forward(self, x: Tensor) -> Tensor:
5660
tmp = self.conv1(x)
5761
tmp = self.conv2(tmp)
5862
tmp = self.conv3(tmp)
@@ -90,13 +94,14 @@ class YOLOV3Neck(BaseModule):
9094
"""
9195

9296
def __init__(self,
93-
num_scales,
94-
in_channels,
95-
out_channels,
96-
conv_cfg=None,
97-
norm_cfg=dict(type='BN', requires_grad=True),
98-
act_cfg=dict(type='LeakyReLU', negative_slope=0.1),
99-
init_cfg=None):
97+
num_scales: int,
98+
in_channels: List[int],
99+
out_channels: List[int],
100+
conv_cfg: OptConfigType = None,
101+
norm_cfg: ConfigType = dict(type='BN', requires_grad=True),
102+
act_cfg: ConfigType = dict(
103+
type='LeakyReLU', negative_slope=0.1),
104+
init_cfg: OptMultiConfig = None) -> None:
100105
super(YOLOV3Neck, self).__init__(init_cfg)
101106
assert (num_scales == len(in_channels) == len(out_channels))
102107
self.num_scales = num_scales
@@ -117,7 +122,7 @@ def __init__(self,
117122
self.add_module(f'detect{i+1}',
118123
DetectionBlock(in_c + out_c, out_c, **cfg))
119124

120-
def forward(self, feats):
125+
def forward(self, feats=Tuple[Tensor]) -> Tuple[Tensor]:
121126
assert len(feats) == self.num_scales
122127

123128
# processed from bottom (high-lvl) to top (low-lvl)

0 commit comments

Comments
 (0)