-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[Feature] Support PIDNet #2609
[Feature] Support PIDNet #2609
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## dev-1.x #2609 +/- ##
===========================================
- Coverage 83.44% 83.43% -0.02%
===========================================
Files 147 153 +6
Lines 8620 9054 +434
Branches 1293 1343 +50
===========================================
+ Hits 7193 7554 +361
- Misses 1205 1263 +58
- Partials 222 237 +15
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
configs/pidnet/README.md
Outdated
|
||
<a href="https://github.com/XuJiacong/PIDNet">Official Repo</a> | ||
|
||
<a href="https://github.com/open-mmlab/mmdetection/blob/dev-3.x/mmdet/models/backbones/pidnet.py">Code Snippet</a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this link should be checked.
ppm_channels=112, | ||
num_stem_blocks=3, | ||
num_branch_blocks=4, | ||
init_cfg=dict(checkpoint='pretrain/PIDNet_L_ImageNet.pth')), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how can users get the pretrained? Please add some notes in README
mmseg/models/backbones/pidnet.py
Outdated
def forward(self, x_p: Tensor, x_i: Tensor) -> Tensor: | ||
if self.after_relu: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add docstring
"""Forward function. | ||
Args: | ||
inputs (Tensor | tuple[Tensor]): Input tensor or tuple of | ||
Tensor. When training, the input is a tuple of three tensors, | ||
(p_feat, i_feat, d_feat), and the output is a tuple of three | ||
tensors, (p_seg_logit, i_seg_logit, d_seg_logit). | ||
When inference, only the head of integral branch is used, and | ||
input is a tensor of integral feature map, and the output is | ||
the segmentation logit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please format the docstring
"""Forward function. | ||
Args: | ||
x (Tensor): Input tensor. | ||
cls_seg (nn.Module, optional): The classification head. | ||
|
||
Returns: | ||
Tensor: Output tensor. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should follow the google docstring style
self.i_head = BasePIDHead(in_channels, channels) | ||
self.p_head = BasePIDHead(in_channels // 2, channels) | ||
self.d_head = BasePIDHead(in_channels // 2, in_channels // 4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does i_head, p_head, and d_head use BN
rather than SyncBN
mmseg/models/backbones/pidnet.py
Outdated
"""Make stem layer. | ||
Args: | ||
in_channels (int): Number of input channels. | ||
channels (int): Number of output channels. | ||
num_blocks (int): Number of blocks. | ||
|
||
Returns: | ||
Stem layer (nn.Sequential) | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it didn't follow the google style.
mmseg/models/backbones/pidnet.py
Outdated
if num_stem_blocks == 2: | ||
self.d_branch_layers = nn.ModuleList([ | ||
self._make_single_layer(BasicBlock, channels * 2, channels), | ||
self._make_layer(Bottleneck, channels, channels, 1) | ||
]) | ||
self.diff_1 = ConvModule( | ||
channels * 4, | ||
channels, | ||
kernel_size=3, | ||
padding=1, | ||
bias=False, | ||
norm_cfg=norm_cfg, | ||
act_cfg=None) | ||
self.diff_2 = ConvModule( | ||
channels * 8, | ||
channels * 2, | ||
kernel_size=3, | ||
padding=1, | ||
bias=False, | ||
norm_cfg=norm_cfg, | ||
act_cfg=None) | ||
self.spp = PAPPM( | ||
channels * 16, ppm_channels, channels * 4, num_scales=5) | ||
self.dfm = LightBag(channels * 4, channels * 4, norm_cfg=norm_cfg) | ||
else: | ||
self.d_branch_layers = nn.ModuleList([ | ||
self._make_single_layer(BasicBlock, channels * 2, | ||
channels * 2), | ||
self._make_single_layer(BasicBlock, channels * 2, channels * 2) | ||
]) | ||
self.diff_1 = ConvModule( | ||
channels * 4, | ||
channels * 2, | ||
kernel_size=3, | ||
padding=1, | ||
norm_cfg=norm_cfg, | ||
act_cfg=None) | ||
self.diff_2 = ConvModule( | ||
channels * 8, | ||
channels * 2, | ||
kernel_size=3, | ||
padding=1, | ||
norm_cfg=norm_cfg, | ||
act_cfg=None) | ||
self.spp = DAPPM( | ||
channels * 16, ppm_channels, channels * 4, num_scales=5) | ||
self.dfm = Bag( | ||
channels * 4, channels * 4, norm_cfg=norm_cfg, act_cfg=act_cfg) | ||
self.d_branch_layers.append( | ||
self._make_layer(Bottleneck, channels * 2, channels * 2, 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if num_stem_blocks == 2: | |
self.d_branch_layers = nn.ModuleList([ | |
self._make_single_layer(BasicBlock, channels * 2, channels), | |
self._make_layer(Bottleneck, channels, channels, 1) | |
]) | |
self.diff_1 = ConvModule( | |
channels * 4, | |
channels, | |
kernel_size=3, | |
padding=1, | |
bias=False, | |
norm_cfg=norm_cfg, | |
act_cfg=None) | |
self.diff_2 = ConvModule( | |
channels * 8, | |
channels * 2, | |
kernel_size=3, | |
padding=1, | |
bias=False, | |
norm_cfg=norm_cfg, | |
act_cfg=None) | |
self.spp = PAPPM( | |
channels * 16, ppm_channels, channels * 4, num_scales=5) | |
self.dfm = LightBag(channels * 4, channels * 4, norm_cfg=norm_cfg) | |
else: | |
self.d_branch_layers = nn.ModuleList([ | |
self._make_single_layer(BasicBlock, channels * 2, | |
channels * 2), | |
self._make_single_layer(BasicBlock, channels * 2, channels * 2) | |
]) | |
self.diff_1 = ConvModule( | |
channels * 4, | |
channels * 2, | |
kernel_size=3, | |
padding=1, | |
norm_cfg=norm_cfg, | |
act_cfg=None) | |
self.diff_2 = ConvModule( | |
channels * 8, | |
channels * 2, | |
kernel_size=3, | |
padding=1, | |
norm_cfg=norm_cfg, | |
act_cfg=None) | |
self.spp = DAPPM( | |
channels * 16, ppm_channels, channels * 4, num_scales=5) | |
self.dfm = Bag( | |
channels * 4, channels * 4, norm_cfg=norm_cfg, act_cfg=act_cfg) | |
self.d_branch_layers.append( | |
self._make_layer(Bottleneck, channels * 2, channels * 2, 1)) | |
if num_stem_blocks == 2: | |
self.d_branch_layers = ... | |
channel_expand = 1 | |
bag_module = LightBag | |
else: | |
self.d_branch_layers = ... | |
channel_expend = 2 | |
bag_module = Bag | |
self.diff_1 = ConvModule( | |
channels * 4, | |
channels * channel_expand, | |
kernel_size=3, | |
padding=1, | |
bias=False, | |
norm_cfg=norm_cfg, | |
act_cfg=None) | |
self.diff_2 = ConvModule( | |
channels * 8, | |
channels * 2, | |
kernel_size=3, | |
padding=1, | |
bias=False, | |
norm_cfg=norm_cfg, | |
act_cfg=None) | |
self.spp = PAPPM( | |
channels * 16, ppm_channels, channels * 4, num_scales=5) | |
self.dfm = bag_module(channels * 4, channels * 4, norm_cfg=norm_cfg) |
mmseg/models/utils/ppm.py
Outdated
from mmseg.registry import MODELS | ||
|
||
|
||
@MODELS.register_module() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should be added docstring.
mmseg/models/utils/ppm.py
Outdated
self.conv_cfg = conv_cfg | ||
|
||
self.scales = ModuleList() | ||
for i in range(num_scales): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better that this loop is from 1 to num_scales-1 and move scales[0] definition and scales[num_scales-1] out of the loop. Too much if else
will hurt to read and efficiency, as every iteration of the loop must do if else.
configs/pidnet/README.md
Outdated
<!-- [IMAGE] --> | ||
|
||
<div align=center> | ||
<img src="https://raw.githubusercontent.com/XuJiacong/PIDNet/main/figs/pidnet.jpg" width="400"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This image is a little small when preview README
configs/pidnet/README.md
Outdated
|
||
| Method | Backbone | Crop Size | Lr schd | Mem (GB) | Inf time (fps) | mIoU | mIoU(ms+flip) | config | download | | ||
| ------ | -------- | --------- | ------- | -------- | -------------- | ----- | ------------- | ----------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| PIDNet | PIDNet-S | 1024x1024 | 120000 | 3466 | 80.82 | 78.74 | 80.87 | [config](https://github.com/open-mmlab/mmsegmentation/blob/dev-1.x/configs/pidnet/pidnet-s_2xb6-120k_1024x1024-cityscapes.py) | [model](https://download.openmmlab.com/mmsegmentation/v0.5/pidnet/pidnet-s_2xb6-120k_1024x1024-cityscapes/pidnet-s_2xb6-120k_1024x1024-cityscapes_20230302_191700-bb8e3bcc.pth) \| [log](https://download.openmmlab.com/mmsegmentation/v0.5/pidnet/pidnet-s_2xb6-120k_1024x1024-cityscapes/pidnet-s_2xb6-120k_1024x1024-cityscapes_20230302_191700.json) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3466/1024 GB
mmseg/models/losses/boundary_loss.py
Outdated
Args: | ||
bd_pre (Tensor): Predictions of the boundary head. | ||
bd_gt (Tensor): Ground truth of the boundary. | ||
|
||
Returns: | ||
Tensor: Loss tensor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Args: | |
bd_pre (Tensor): Predictions of the boundary head. | |
bd_gt (Tensor): Ground truth of the boundary. | |
Returns: | |
Tensor: Loss tensor. | |
Args: | |
bd_pre (Tensor): Predictions of the boundary head. | |
bd_gt (Tensor): Ground truth of the boundary. | |
Returns: | |
Tensor: Loss tensor. |
Args: | ||
score (Tensor): Predictions of the segmentation head. | ||
target (Tensor): Ground truth of the image. | ||
|
||
Returns: | ||
Tensor: Loss tensor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Args: | |
score (Tensor): Predictions of the segmentation head. | |
target (Tensor): Ground truth of the image. | |
Returns: | |
Tensor: Loss tensor. | |
Args: | |
score (Tensor): Predictions of the segmentation head. | |
target (Tensor): Ground truth of the image. | |
Returns: | |
Tensor: Loss tensor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add PIDNet in model zoo of readme
## Motivation Support SOTA real-time semantic segmentation method in [Paper with code](https://paperswithcode.com/task/real-time-semantic-segmentation) Paper: https://arxiv.org/pdf/2206.02066.pdf Official repo: https://github.com/XuJiacong/PIDNet ## Current results **Cityscapes** |Model|Ref mIoU|mIoU (ours)| |---|---|---| |PIDNet-S|78.8|78.74| |PIDNet-M|79.9|80.22| |PIDNet-L|80.9|80.89| ## TODO - [x] Support inference with official weights - [x] Support training on Cityscapes - [x] Update docstring - [x] Add unit test
Motivation
Support SOTA real-time semantic segmentation method in Paper with code
Paper: https://arxiv.org/pdf/2206.02066.pdf
Official repo: https://github.com/XuJiacong/PIDNet
Current results
Cityscapes
TODO