-
Couldn't load subscription status.
- Fork 9.8k
CodeCamp #33 [Fix]:add type hints for res_layer, se_layer,normed_predictor,positional_encoding #9346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
CodeCamp #33 [Fix]:add type hints for res_layer, se_layer,normed_predictor,positional_encoding #9346
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4219abe
[Fix]:add type hints for res_layer
ZhikangNiu cff1bd6
Update mmdet/models/layers/res_layer.py
ZhikangNiu 34c3066
[Fix]:add type hint of norm1 and norm2
ZhikangNiu 54c6a6f
[WIP]:add res_layer type hints
ZhikangNiu 4dac59f
[WIP]:add layer type hints about issue 9234
ZhikangNiu beee50d
[FIX]:add all type hints and change some function note
ZhikangNiu bfc849c
[FIX]:add docstrings and change default -> defaults
ZhikangNiu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,13 @@ | ||
| # Copyright (c) OpenMMLab. All rights reserved. | ||
| from typing import Optional | ||
|
|
||
| from mmcv.cnn import build_conv_layer, build_norm_layer | ||
| from mmengine.model import BaseModule, Sequential | ||
| from torch import Tensor | ||
| from torch import nn as nn | ||
|
|
||
| from mmdet.utils import ConfigType, OptConfigType, OptMultiConfig | ||
|
|
||
|
|
||
| class ResLayer(Sequential): | ||
| """ResLayer to build ResNet style backbone. | ||
|
|
@@ -12,28 +17,28 @@ class ResLayer(Sequential): | |
| inplanes (int): inplanes of block. | ||
| planes (int): planes of block. | ||
| num_blocks (int): number of blocks. | ||
| stride (int): stride of the first block. Default: 1 | ||
| stride (int): stride of the first block. Defaults to 1 | ||
| avg_down (bool): Use AvgPool instead of stride conv when | ||
| downsampling in the bottleneck. Default: False | ||
| downsampling in the bottleneck. Defaults to False | ||
| conv_cfg (dict): dictionary to construct and config conv layer. | ||
| Default: None | ||
| Defaults to None | ||
| norm_cfg (dict): dictionary to construct and config norm layer. | ||
| Default: dict(type='BN') | ||
| Defaults to dict(type='BN') | ||
| downsample_first (bool): Downsample at the first block or last block. | ||
| False for Hourglass, True for ResNet. Default: True | ||
| False for Hourglass, True for ResNet. Defaults to True | ||
| """ | ||
|
|
||
| def __init__(self, | ||
| block, | ||
| inplanes, | ||
| planes, | ||
| num_blocks, | ||
| stride=1, | ||
| avg_down=False, | ||
| conv_cfg=None, | ||
| norm_cfg=dict(type='BN'), | ||
| downsample_first=True, | ||
| **kwargs): | ||
| block: BaseModule, | ||
| inplanes: int, | ||
| planes: int, | ||
| num_blocks: int, | ||
| stride: int = 1, | ||
| avg_down: bool = False, | ||
| conv_cfg: OptConfigType = None, | ||
| norm_cfg: ConfigType = dict(type='BN'), | ||
| downsample_first: bool = True, | ||
| **kwargs) -> None: | ||
| self.block = block | ||
|
|
||
| downsample = None | ||
|
|
@@ -101,7 +106,7 @@ def __init__(self, | |
| conv_cfg=conv_cfg, | ||
| norm_cfg=norm_cfg, | ||
| **kwargs)) | ||
| super(ResLayer, self).__init__(*layers) | ||
| super().__init__(*layers) | ||
|
|
||
|
|
||
| class SimplifiedBasicBlock(BaseModule): | ||
|
|
@@ -114,19 +119,19 @@ class SimplifiedBasicBlock(BaseModule): | |
| expansion = 1 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 109: super().init(*layers) |
||
|
|
||
| def __init__(self, | ||
| inplanes, | ||
| planes, | ||
| stride=1, | ||
| dilation=1, | ||
| downsample=None, | ||
| style='pytorch', | ||
| with_cp=False, | ||
| conv_cfg=None, | ||
| norm_cfg=dict(type='BN'), | ||
| dcn=None, | ||
| plugins=None, | ||
| init_fg=None): | ||
| super(SimplifiedBasicBlock, self).__init__(init_fg) | ||
| inplanes: int, | ||
| planes: int, | ||
| stride: int = 1, | ||
| dilation: int = 1, | ||
| downsample: Optional[Sequential] = None, | ||
| style: ConfigType = 'pytorch', | ||
| with_cp: bool = False, | ||
| conv_cfg: OptConfigType = None, | ||
| norm_cfg: ConfigType = dict(type='BN'), | ||
| dcn: OptConfigType = None, | ||
| plugins: OptConfigType = None, | ||
| init_cfg: OptMultiConfig = None) -> None: | ||
| super().__init__(init_cfg=init_cfg) | ||
| assert dcn is None, 'Not implemented yet.' | ||
| assert plugins is None, 'Not implemented yet.' | ||
| assert not with_cp, 'Not implemented yet.' | ||
|
|
@@ -159,17 +164,17 @@ def __init__(self, | |
| self.with_cp = with_cp | ||
|
|
||
| @property | ||
| def norm1(self): | ||
| def norm1(self) -> Optional[BaseModule]: | ||
| """nn.Module: normalization layer after the first convolution layer""" | ||
| return getattr(self, self.norm1_name) if self.with_norm else None | ||
|
|
||
| @property | ||
| def norm2(self): | ||
| def norm2(self) -> Optional[BaseModule]: | ||
| """nn.Module: normalization layer after the second convolution layer""" | ||
BIGWangYuDong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return getattr(self, self.norm2_name) if self.with_norm else None | ||
|
|
||
| def forward(self, x): | ||
| """Forward function.""" | ||
| def forward(self, x: Tensor) -> Tensor: | ||
| """Forward function for SimplifiedBasicBlock.""" | ||
|
|
||
| identity = x | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.