Skip to content
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] Add ESPNetV1 #1625

Merged
merged 14 commits into from
Dec 28, 2021
Merged

[Feature] Add ESPNetV1 #1625

merged 14 commits into from
Dec 28, 2021

Conversation

simuler
Copy link
Contributor

@simuler simuler commented Dec 14, 2021

添加ESPNet模型(Dynamic Multi-scale Filters for Semantic Segmentation)

添加内容:
configs/espnetv1/espnetv1_cityscapes_1024x512_120k.yml
configs/espnetv1/README.md
paddleseg/models/espnetv1.py
paddleseg/models/init.py

Copy link
Collaborator

@shiyutang shiyutang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please read our style markdown before PR. This PR needs more adjustment than my comments.
Style markdown link: https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/pr/pr/style_cn.md#paddleseg%E6%A8%A1%E5%9E%8B%E5%BC%80%E5%8F%91%E8%A7%84%E8%8C%83



## Reference
[1] Mehta S , Rastegari M , Caspi A , et al. ESPNet: Efficient Spatial Pyramid of Dilated Convolutions for Semantic Segmentation[J]. Springer, Cham, 2018.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plz change this quote to Chicago format, which includes their full name.
you can refer to this: https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/pr/pr/style_cn.md#%E4%B8%89%E6%96%B0%E5%A2%9E-pr-checklist

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

## Reference
[1] Mehta S , Rastegari M , Caspi A , et al. ESPNet: Efficient Spatial Pyramid of Dilated Convolutions for Semantic Segmentation[J]. Springer, Cham, 2018.
## Performance
CityScapes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cityscapes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 9 to 11
| Model|steps|opt|image_size|batch_size|dataset|memory|card|mIou|config|
| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
|ESPNet|120k|adam|1024x512|4|CityScapes|32G|4|0.6365|[espnet_cityscapes_1024x512_120k.yml](configs/espnetv1/espnetv1_cityscapes_1024x512_120k.yml)|
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, you do not need to include so much information. Please refer to our style MD before you bring up your PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 24 to 31
def SyncBatchNorm(*args, **kwargs):
"""In cpu environment nn.SyncBatchNorm does not have kernel so use nn.BatchNorm2D instead"""
if paddle.get_device() == 'cpu' or os.environ.get('PADDLESEG_EXPORT_STAGE'):
return nn.BatchNorm2D(*args, **kwargs)
elif paddle.distributed.ParallelEnv().nranks == 1:
return nn.BatchNorm2D(*args, **kwargs)
else:
return nn.SyncBatchNorm(*args, **kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make use of the same function we have in layers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 67 to 73
p1, p2, p3 = self.encoder(x) # shape [N, C, H/2, W/2] [N, C, H/4, W/4] [N, C, H/8, W/8]
up_p3 = self.level3_up(p3) # [N, C, H/4, W/4]

combine = self.combine_l2_l3(paddle.concat([up_p3, p2], axis=1))
up_p2 = self.level2_up(combine) # [N, C, H/2, W/2]

combine = self.out_proj(paddle.concat([up_p2, p1], axis=1)) # shape [N, C, H/2, W/2]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this annotation please, here and elsewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

paddleseg/models/espnetv1.py Show resolved Hide resolved
@michaelowenliu michaelowenliu changed the title [Feature]Add ESPNetV1 [Feature] Add ESPNetV1 Dec 16, 2021
batch_size: 4
iters: 120000


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this plz

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixd

Comment on lines 267 to 269
if __name__ == '__main__':
model = ESPNetV1(19, 3, 2, 8)
paddle.summary(model, (4, 3, 256, 256))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove test code plz

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixd

Comment on lines 111 to 130
class Conv(nn.Layer):
def __init__(self, in_channels, out_channels, kernel_size, stride=1):
super().__init__()
padding = int((kernel_size - 1) / 2)
self.conv = nn.Conv2D(in_channels, out_channels, kernel_size, stride=stride, padding=padding, bias_attr=False)

def forward(self, x):
x = self.conv(x)
return x


class ConvDilated(nn.Layer):
def __init__(self, in_channels, out_channels, kernel_size, stride=1, dilation=1):
super().__init__()
padding = int((kernel_size - 1) / 2) * dilation
self.conv = nn.Conv2D(in_channels, out_channels, kernel_size, stride=stride, padding=padding, dilation=dilation, bias_attr=False)

def forward(self, x):
x = self.conv(x)
return x
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems these two function is not that necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixd

import paddle
import paddle.nn as nn
import paddle.nn.functional as F
import os
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved up

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixd

Comment on lines 71 to 108
class ConvBNPReLU(nn.Layer):
def __init__(self, in_channels, out_channels, kernel_size, stride=1):
super().__init__()
padding = int((kernel_size - 1) / 2)
self.conv = nn.Conv2D(in_channels, out_channels, kernel_size, stride=stride, padding=padding, bias_attr=False)
self.bn = layers.SyncBatchNorm(out_channels)
self.act = nn.PReLU(out_channels)

def forward(self, x):
x = self.conv(x)
x = self.bn(x)
x = self.act(x)
return x


class BNPReLU(nn.Layer):
def __init__(self, channels):
super().__init__()
self.bn = layers.SyncBatchNorm(channels)
self.act = nn.PReLU(channels)

def forward(self, x):
x = self.bn(x)
x = self.act(x)
return x


class ConvBN(nn.Layer):
def __init__(self, in_channels, out_channels, kernel_size, stride=1):
super().__init__()
padding = int((kernel_size - 1) / 2)
self.conv = nn.Conv2D(in_channels, out_channels, kernel_size, stride=stride, padding=padding, bias_attr=False)
self.bn = layers.SyncBatchNorm(out_channels)

def forward(self, x):
x = self.conv(x)
x = self.bn(x)
return x
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please checkout layers package for these function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1、The ConvBNPReLU of layers package cannot modified the stride
`class ConvBNPReLU(nn.Layer):
def init(self,
in_channels,
out_channels,
kernel_size,
padding='same',
**kwargs):
super().init()

    self._conv = nn.Conv2D(in_channels,
                           out_channels,
                           kernel_size,
                           padding=padding,
                           **kwargs)

    if 'data_format' in kwargs:
        data_format = kwargs['data_format']
    else:
        data_format = 'NCHW'
    self._batch_norm = SyncBatchNorm(out_channels, data_format=data_format)
    self._prelu = layers.Activation("prelu")

def forward(self, x):
    x = self._conv(x)
    x = self._batch_norm(x)
    x = self._prelu(x)
    return x`

2、no BNPReLU in layers package

3、 I checked the code again, ConvBN is not used


### Cityscapes

| Model | Backbone | Resolution | Training Iters | mIoU | Links |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add the result of mIOU(+flip) and +ms & flip like this:
image
You can get the result through:

flip+ms
python3  val.py --config .yml --model_path best_model/model.pdparams --num_workers 2 --aug_eval --flip_horizontal --scales 0.75 1.0 1.25

flip
python3  val.py --config config.yml --model_path best_model/model.pdparams --num_workers 2 --aug_eval --flip_horizontal 

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README.md is updated. Will you train espnetv1 from the scratch? If you do, wo don't supply weight trained before.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we will not train it again, you can give the model's weight to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 71 to 83
class ConvBNPReLU(nn.Layer):
def __init__(self, in_channels, out_channels, kernel_size, stride=1):
super().__init__()
padding = int((kernel_size - 1) / 2)
self.conv = nn.Conv2D(in_channels, out_channels, kernel_size, stride=stride, padding=padding, bias_attr=False)
self.bn = layers.SyncBatchNorm(out_channels)
self.act = nn.PReLU(out_channels)

def forward(self, x):
x = self.conv(x)
x = self.bn(x)
x = self.act(x)
return x
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the models.layers.ConvBNPReLU can pass in kwargs to change the padding and stride of Conv2D.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@michaelowenliu michaelowenliu merged commit bfca53f into PaddlePaddle:develop Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants