-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[Feature] Add ESPNetV1 #1625
Conversation
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 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
configs/espnetv1/README.md
Outdated
|
||
|
||
## Reference | ||
[1] Mehta S , Rastegari M , Caspi A , et al. ESPNet: Efficient Spatial Pyramid of Dilated Convolutions for Semantic Segmentation[J]. Springer, Cham, 2018. |
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.
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
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.
fixed
configs/espnetv1/README.md
Outdated
## 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 |
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.
Cityscapes
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.
fixed
configs/espnetv1/README.md
Outdated
| 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)| |
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.
Actually, you do not need to include so much information. Please refer to our style MD before you bring up your PR
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.
fixed
paddleseg/models/espnetv1.py
Outdated
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) |
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 make use of the same function we have in layers.
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.
fixed
paddleseg/models/espnetv1.py
Outdated
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] |
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.
Remove this annotation please, here and elsewhere
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.
fixed
batch_size: 4 | ||
iters: 120000 | ||
|
||
|
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.
remove this plz
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.
fixd
paddleseg/models/espnetv1.py
Outdated
if __name__ == '__main__': | ||
model = ESPNetV1(19, 3, 2, 8) | ||
paddle.summary(model, (4, 3, 256, 256)) |
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.
remove test code plz
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.
fixd
paddleseg/models/espnetv1.py
Outdated
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 |
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 seems these two function is not that necessary
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.
fixd
paddleseg/models/espnetv1.py
Outdated
import paddle | ||
import paddle.nn as nn | ||
import paddle.nn.functional as F | ||
import os |
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 should be moved up
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.
fixd
paddleseg/models/espnetv1.py
Outdated
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 |
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 checkout layers package for these function
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.
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
configs/espnetv1/README.md
Outdated
|
||
### Cityscapes | ||
|
||
| Model | Backbone | Resolution | Training Iters | mIoU | Links | |
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 the result of mIOU(+flip) and +ms & flip like this:
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
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.
README.md is updated. Will you train espnetv1 from the scratch? If you do, wo don't supply weight trained before.
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.
we will not train it again, you can give the model's weight to me.
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.
Done
paddleseg/models/espnetv1.py
Outdated
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 |
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.
Actually the models.layers.ConvBNPReLU can pass in kwargs to change the padding and stride of Conv2D.
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.
fixed
添加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