Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
fbd18e99
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
大约 1 年 前同步成功
通知
282
Star
12117
Fork
2091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
200
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleHub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
200
Issue
200
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
fbd18e99
编写于
11月 04, 2022
作者:
jm_12138
提交者:
GitHub
11月 04, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update format (#2101)
上级
350407c7
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
176 addition
and
264 deletion
+176
-264
modules/image/semantic_segmentation/ginet_resnet50vd_voc/README.md
...mage/semantic_segmentation/ginet_resnet50vd_voc/README.md
+4
-4
modules/image/semantic_segmentation/ginet_resnet50vd_voc/README_en.md
...e/semantic_segmentation/ginet_resnet50vd_voc/README_en.md
+4
-4
modules/image/semantic_segmentation/ginet_resnet50vd_voc/__init__.py
...ge/semantic_segmentation/ginet_resnet50vd_voc/__init__.py
+0
-0
modules/image/semantic_segmentation/ginet_resnet50vd_voc/layers.py
...mage/semantic_segmentation/ginet_resnet50vd_voc/layers.py
+68
-108
modules/image/semantic_segmentation/ginet_resnet50vd_voc/module.py
...mage/semantic_segmentation/ginet_resnet50vd_voc/module.py
+50
-88
modules/image/semantic_segmentation/ginet_resnet50vd_voc/requirements.txt
...mantic_segmentation/ginet_resnet50vd_voc/requirements.txt
+1
-0
modules/image/semantic_segmentation/ginet_resnet50vd_voc/resnet.py
...mage/semantic_segmentation/ginet_resnet50vd_voc/resnet.py
+49
-60
未找到文件。
modules/image/semantic_segmentation/ginet_resnet50vd_voc/README.md
浏览文件 @
fbd18e99
modules/image/semantic_segmentation/ginet_resnet50vd_voc/README_en.md
浏览文件 @
fbd18e99
modules/image/semantic_segmentation/ginet_resnet50vd_voc/__init__.py
0 → 100644
浏览文件 @
fbd18e99
modules/image/semantic_segmentation/ginet_resnet50vd_voc/layers.py
浏览文件 @
fbd18e99
...
...
@@ -11,12 +11,12 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
paddle
import
paddle.nn
as
nn
import
paddle.nn.functional
as
F
from
paddle.nn
import
AvgPool2D
from
paddle.nn
import
Conv2D
from
paddle.nn.layer
import
activation
from
paddle.nn
import
Conv2D
,
AvgPool2D
def
SyncBatchNorm
(
*
args
,
**
kwargs
):
...
...
@@ -30,8 +30,7 @@ def SyncBatchNorm(*args, **kwargs):
class
ConvBNLayer
(
nn
.
Layer
):
"""Basic conv bn relu layer."""
def
__init__
(
self
,
def
__init__
(
self
,
in_channels
:
int
,
out_channels
:
int
,
kernel_size
:
int
,
...
...
@@ -44,10 +43,8 @@ class ConvBNLayer(nn.Layer):
super
(
ConvBNLayer
,
self
).
__init__
()
self
.
is_vd_mode
=
is_vd_mode
self
.
_pool2d_avg
=
AvgPool2D
(
kernel_size
=
2
,
stride
=
2
,
padding
=
0
,
ceil_mode
=
True
)
self
.
_conv
=
Conv2D
(
in_channels
=
in_channels
,
self
.
_pool2d_avg
=
AvgPool2D
(
kernel_size
=
2
,
stride
=
2
,
padding
=
0
,
ceil_mode
=
True
)
self
.
_conv
=
Conv2D
(
in_channels
=
in_channels
,
out_channels
=
out_channels
,
kernel_size
=
kernel_size
,
stride
=
stride
,
...
...
@@ -82,8 +79,7 @@ class BottleneckBlock(nn.Layer):
name
:
str
=
None
):
super
(
BottleneckBlock
,
self
).
__init__
()
self
.
conv0
=
ConvBNLayer
(
in_channels
=
in_channels
,
self
.
conv0
=
ConvBNLayer
(
in_channels
=
in_channels
,
out_channels
=
out_channels
,
kernel_size
=
1
,
act
=
'relu'
,
...
...
@@ -91,24 +87,21 @@ class BottleneckBlock(nn.Layer):
self
.
dilation
=
dilation
self
.
conv1
=
ConvBNLayer
(
in_channels
=
out_channels
,
self
.
conv1
=
ConvBNLayer
(
in_channels
=
out_channels
,
out_channels
=
out_channels
,
kernel_size
=
3
,
stride
=
stride
,
act
=
'relu'
,
dilation
=
dilation
,
name
=
name
+
"_branch2b"
)
self
.
conv2
=
ConvBNLayer
(
in_channels
=
out_channels
,
self
.
conv2
=
ConvBNLayer
(
in_channels
=
out_channels
,
out_channels
=
out_channels
*
4
,
kernel_size
=
1
,
act
=
None
,
name
=
name
+
"_branch2c"
)
if
not
shortcut
:
self
.
short
=
ConvBNLayer
(
in_channels
=
in_channels
,
self
.
short
=
ConvBNLayer
(
in_channels
=
in_channels
,
out_channels
=
out_channels
*
4
,
kernel_size
=
1
,
stride
=
1
,
...
...
@@ -139,22 +132,15 @@ class BottleneckBlock(nn.Layer):
class
SeparableConvBNReLU
(
nn
.
Layer
):
"""Depthwise Separable Convolution."""
def
__init__
(
self
,
in_channels
:
int
,
out_channels
:
int
,
kernel_size
:
int
,
padding
:
str
=
'same'
,
**
kwargs
:
dict
):
def
__init__
(
self
,
in_channels
:
int
,
out_channels
:
int
,
kernel_size
:
int
,
padding
:
str
=
'same'
,
**
kwargs
:
dict
):
super
(
SeparableConvBNReLU
,
self
).
__init__
()
self
.
depthwise_conv
=
ConvBN
(
in_channels
,
self
.
depthwise_conv
=
ConvBN
(
in_channels
,
out_channels
=
in_channels
,
kernel_size
=
kernel_size
,
padding
=
padding
,
groups
=
in_channels
,
**
kwargs
)
self
.
piontwise_conv
=
ConvBNReLU
(
in_channels
,
out_channels
,
kernel_size
=
1
,
groups
=
1
)
self
.
piontwise_conv
=
ConvBNReLU
(
in_channels
,
out_channels
,
kernel_size
=
1
,
groups
=
1
)
def
forward
(
self
,
x
:
paddle
.
Tensor
)
->
paddle
.
Tensor
:
x
=
self
.
depthwise_conv
(
x
)
...
...
@@ -165,15 +151,9 @@ class SeparableConvBNReLU(nn.Layer):
class
ConvBN
(
nn
.
Layer
):
"""Basic conv bn layer"""
def
__init__
(
self
,
in_channels
:
int
,
out_channels
:
int
,
kernel_size
:
int
,
padding
:
str
=
'same'
,
**
kwargs
:
dict
):
def
__init__
(
self
,
in_channels
:
int
,
out_channels
:
int
,
kernel_size
:
int
,
padding
:
str
=
'same'
,
**
kwargs
:
dict
):
super
(
ConvBN
,
self
).
__init__
()
self
.
_conv
=
Conv2D
(
in_channels
,
out_channels
,
kernel_size
,
padding
=
padding
,
**
kwargs
)
self
.
_conv
=
Conv2D
(
in_channels
,
out_channels
,
kernel_size
,
padding
=
padding
,
**
kwargs
)
self
.
_batch_norm
=
SyncBatchNorm
(
out_channels
)
def
forward
(
self
,
x
:
paddle
.
Tensor
)
->
paddle
.
Tensor
:
...
...
@@ -185,16 +165,10 @@ class ConvBN(nn.Layer):
class
ConvBNReLU
(
nn
.
Layer
):
"""Basic conv bn relu layer."""
def
__init__
(
self
,
in_channels
:
int
,
out_channels
:
int
,
kernel_size
:
int
,
padding
:
str
=
'same'
,
**
kwargs
:
dict
):
def
__init__
(
self
,
in_channels
:
int
,
out_channels
:
int
,
kernel_size
:
int
,
padding
:
str
=
'same'
,
**
kwargs
:
dict
):
super
(
ConvBNReLU
,
self
).
__init__
()
self
.
_conv
=
Conv2D
(
in_channels
,
out_channels
,
kernel_size
,
padding
=
padding
,
**
kwargs
)
self
.
_conv
=
Conv2D
(
in_channels
,
out_channels
,
kernel_size
,
padding
=
padding
,
**
kwargs
)
self
.
_batch_norm
=
SyncBatchNorm
(
out_channels
)
def
forward
(
self
,
x
:
paddle
.
Tensor
)
->
paddle
.
Tensor
:
...
...
@@ -251,8 +225,7 @@ class Activation(nn.Layer):
act_name
=
act_dict
[
act
]
self
.
act_func
=
eval
(
"activation.{}()"
.
format
(
act_name
))
else
:
raise
KeyError
(
"{} does not exist in the current {}"
.
format
(
act
,
act_dict
.
keys
()))
raise
KeyError
(
"{} does not exist in the current {}"
.
format
(
act
,
act_dict
.
keys
()))
def
forward
(
self
,
x
:
paddle
.
Tensor
)
->
paddle
.
Tensor
:
...
...
@@ -281,7 +254,7 @@ class ASPPModule(nn.Layer):
in_channels
:
int
,
out_channels
:
int
,
align_corners
:
bool
,
use_sep_conv
:
bool
=
False
,
use_sep_conv
:
bool
=
False
,
image_pooling
:
bool
=
False
):
super
().
__init__
()
...
...
@@ -294,8 +267,7 @@ class ASPPModule(nn.Layer):
else
:
conv_func
=
ConvBNReLU
block
=
conv_func
(
in_channels
=
in_channels
,
block
=
conv_func
(
in_channels
=
in_channels
,
out_channels
=
out_channels
,
kernel_size
=
1
if
ratio
==
1
else
3
,
dilation
=
ratio
,
...
...
@@ -305,16 +277,12 @@ class ASPPModule(nn.Layer):
out_size
=
len
(
self
.
aspp_blocks
)
if
image_pooling
:
self
.
global_avg_pool
=
nn
.
Sequential
(
nn
.
AdaptiveAvgPool2D
(
output_size
=
(
1
,
1
)),
self
.
global_avg_pool
=
nn
.
Sequential
(
nn
.
AdaptiveAvgPool2D
(
output_size
=
(
1
,
1
)),
ConvBNReLU
(
in_channels
,
out_channels
,
kernel_size
=
1
,
bias_attr
=
False
))
out_size
+=
1
self
.
image_pooling
=
image_pooling
self
.
conv_bn_relu
=
ConvBNReLU
(
in_channels
=
out_channels
*
out_size
,
out_channels
=
out_channels
,
kernel_size
=
1
)
self
.
conv_bn_relu
=
ConvBNReLU
(
in_channels
=
out_channels
*
out_size
,
out_channels
=
out_channels
,
kernel_size
=
1
)
self
.
dropout
=
nn
.
Dropout
(
p
=
0.1
)
# drop rate
...
...
@@ -322,20 +290,12 @@ class ASPPModule(nn.Layer):
outputs
=
[]
for
block
in
self
.
aspp_blocks
:
y
=
block
(
x
)
y
=
F
.
interpolate
(
y
,
x
.
shape
[
2
:],
mode
=
'bilinear'
,
align_corners
=
self
.
align_corners
)
y
=
F
.
interpolate
(
y
,
x
.
shape
[
2
:],
mode
=
'bilinear'
,
align_corners
=
self
.
align_corners
)
outputs
.
append
(
y
)
if
self
.
image_pooling
:
img_avg
=
self
.
global_avg_pool
(
x
)
img_avg
=
F
.
interpolate
(
img_avg
,
x
.
shape
[
2
:],
mode
=
'bilinear'
,
align_corners
=
self
.
align_corners
)
img_avg
=
F
.
interpolate
(
img_avg
,
x
.
shape
[
2
:],
mode
=
'bilinear'
,
align_corners
=
self
.
align_corners
)
outputs
.
append
(
img_avg
)
x
=
paddle
.
concat
(
outputs
,
axis
=
1
)
...
...
modules/image/semantic_segmentation/ginet_resnet50vd_voc/module.py
浏览文件 @
fbd18e99
...
...
@@ -11,25 +11,24 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
os
from
typing
import
Union
,
List
,
Tuple
from
typing
import
List
from
typing
import
Tuple
from
typing
import
Union
import
numpy
as
np
import
paddle
from
paddle
import
nn
import
paddle.nn.functional
as
F
import
numpy
as
np
from
paddlehub.module.module
import
moduleinfo
import
paddlehub.vision.segmentation_transforms
as
T
from
paddlehub.module.cv_module
import
ImageSegmentationModule
from
paddleseg.utils
import
utils
from
ginet_resnet50vd_voc.resnet
import
ResNet50_vd
from
paddle
import
nn
from
paddleseg.models
import
layers
from
ginet_resnet50vd_voc.resnet
import
ResNet50_vd
import
paddlehub.vision.segmentation_transforms
as
T
from
paddlehub.module.cv_module
import
ImageSegmentationModule
from
paddlehub.module.module
import
moduleinfo
@
moduleinfo
(
name
=
"ginet_resnet50vd_voc"
,
@
moduleinfo
(
name
=
"ginet_resnet50vd_voc"
,
type
=
"CV/semantic_segmentation"
,
author
=
"paddlepaddle"
,
author_email
=
""
,
...
...
@@ -55,8 +54,8 @@ class GINetResNet50(nn.Layer):
def
__init__
(
self
,
num_classes
:
int
=
21
,
backbone_indices
:
Tuple
[
int
]
=
(
0
,
1
,
2
,
3
),
enable_auxiliary_loss
:
bool
=
True
,
backbone_indices
:
Tuple
[
int
]
=
(
0
,
1
,
2
,
3
),
enable_auxiliary_loss
:
bool
=
True
,
align_corners
:
bool
=
True
,
jpu
:
bool
=
True
,
pretrained
:
str
=
None
):
...
...
@@ -74,8 +73,7 @@ class GINetResNet50(nn.Layer):
self
.
head
=
GIHead
(
in_channels
=
2048
,
nclass
=
num_classes
)
if
self
.
aux
:
self
.
auxlayer
=
layers
.
AuxLayer
(
1024
,
1024
//
4
,
num_classes
,
bias_attr
=
False
)
self
.
auxlayer
=
layers
.
AuxLayer
(
1024
,
1024
//
4
,
num_classes
,
bias_attr
=
False
)
if
pretrained
is
not
None
:
model_dict
=
paddle
.
load
(
pretrained
)
...
...
@@ -113,12 +111,7 @@ class GINetResNet50(nn.Layer):
logit_list
.
append
(
auxout
)
return
[
F
.
interpolate
(
logit
,
(
h
,
w
),
mode
=
'bilinear'
,
align_corners
=
self
.
align_corners
)
for
logit
in
logit_list
]
return
[
F
.
interpolate
(
logit
,
(
h
,
w
),
mode
=
'bilinear'
,
align_corners
=
self
.
align_corners
)
for
logit
in
logit_list
]
class
GIHead
(
nn
.
Layer
):
...
...
@@ -129,30 +122,16 @@ class GIHead(nn.Layer):
self
.
nclass
=
nclass
inter_channels
=
in_channels
//
4
self
.
inp
=
paddle
.
zeros
(
shape
=
(
nclass
,
300
),
dtype
=
'float32'
)
self
.
inp
=
paddle
.
create_parameter
(
shape
=
self
.
inp
.
shape
,
self
.
inp
=
paddle
.
create_parameter
(
shape
=
self
.
inp
.
shape
,
dtype
=
str
(
self
.
inp
.
numpy
().
dtype
),
default_initializer
=
paddle
.
nn
.
initializer
.
Assign
(
self
.
inp
))
self
.
fc1
=
nn
.
Sequential
(
nn
.
Linear
(
300
,
128
),
nn
.
BatchNorm1D
(
128
),
nn
.
ReLU
())
self
.
fc2
=
nn
.
Sequential
(
nn
.
Linear
(
128
,
256
),
nn
.
BatchNorm1D
(
256
),
nn
.
ReLU
())
self
.
conv5
=
layers
.
ConvBNReLU
(
in_channels
,
inter_channels
,
3
,
padding
=
1
,
bias_attr
=
False
,
stride
=
1
)
self
.
gloru
=
GlobalReasonUnit
(
in_channels
=
inter_channels
,
num_state
=
256
,
num_node
=
84
,
nclass
=
nclass
)
self
.
conv6
=
nn
.
Sequential
(
nn
.
Dropout
(
0.1
),
nn
.
Conv2D
(
inter_channels
,
nclass
,
1
))
self
.
fc1
=
nn
.
Sequential
(
nn
.
Linear
(
300
,
128
),
nn
.
BatchNorm1D
(
128
),
nn
.
ReLU
())
self
.
fc2
=
nn
.
Sequential
(
nn
.
Linear
(
128
,
256
),
nn
.
BatchNorm1D
(
256
),
nn
.
ReLU
())
self
.
conv5
=
layers
.
ConvBNReLU
(
in_channels
,
inter_channels
,
3
,
padding
=
1
,
bias_attr
=
False
,
stride
=
1
)
self
.
gloru
=
GlobalReasonUnit
(
in_channels
=
inter_channels
,
num_state
=
256
,
num_node
=
84
,
nclass
=
nclass
)
self
.
conv6
=
nn
.
Sequential
(
nn
.
Dropout
(
0.1
),
nn
.
Conv2D
(
inter_channels
,
nclass
,
1
))
def
forward
(
self
,
x
:
paddle
.
Tensor
)
->
List
[
paddle
.
Tensor
]:
B
,
C
,
H
,
W
=
x
.
shape
...
...
@@ -178,13 +157,10 @@ class GlobalReasonUnit(nn.Layer):
def
__init__
(
self
,
in_channels
:
int
,
num_state
:
int
=
256
,
num_node
:
int
=
84
,
nclass
:
int
=
59
):
super
().
__init__
()
self
.
num_state
=
num_state
self
.
conv_theta
=
nn
.
Conv2D
(
in_channels
,
num_node
,
kernel_size
=
1
,
stride
=
1
,
padding
=
0
)
self
.
conv_phi
=
nn
.
Conv2D
(
in_channels
,
num_state
,
kernel_size
=
1
,
stride
=
1
,
padding
=
0
)
self
.
conv_theta
=
nn
.
Conv2D
(
in_channels
,
num_node
,
kernel_size
=
1
,
stride
=
1
,
padding
=
0
)
self
.
conv_phi
=
nn
.
Conv2D
(
in_channels
,
num_state
,
kernel_size
=
1
,
stride
=
1
,
padding
=
0
)
self
.
graph
=
GraphLayer
(
num_state
,
num_node
,
nclass
)
self
.
extend_dim
=
nn
.
Conv2D
(
num_state
,
in_channels
,
kernel_size
=
1
,
bias_attr
=
False
)
self
.
extend_dim
=
nn
.
Conv2D
(
num_state
,
in_channels
,
kernel_size
=
1
,
bias_attr
=
False
)
self
.
bn
=
layers
.
SyncBatchNorm
(
in_channels
)
...
...
@@ -199,8 +175,7 @@ class GlobalReasonUnit(nn.Layer):
.
transpose
((
0
,
2
,
1
))
V
=
paddle
.
bmm
(
B
,
x_reduce
).
transpose
((
0
,
2
,
1
))
V
=
paddle
.
divide
(
V
,
paddle
.
to_tensor
([
sizex
[
2
]
*
sizex
[
3
]],
dtype
=
'float32'
))
V
=
paddle
.
divide
(
V
,
paddle
.
to_tensor
([
sizex
[
2
]
*
sizex
[
3
]],
dtype
=
'float32'
))
class_node
,
new_V
=
self
.
graph
(
inp
,
V
)
D
=
B
.
reshape
((
sizeB
[
0
],
-
1
,
sizeB
[
2
]
*
sizeB
[
3
])).
transpose
((
0
,
2
,
1
))
...
...
@@ -215,6 +190,7 @@ class GlobalReasonUnit(nn.Layer):
class
GraphLayer
(
nn
.
Layer
):
def
__init__
(
self
,
num_state
:
int
,
num_node
:
int
,
num_class
:
int
):
super
().
__init__
()
self
.
vis_gcn
=
GCN
(
num_state
,
num_node
)
...
...
@@ -222,12 +198,10 @@ class GraphLayer(nn.Layer):
self
.
transfer
=
GraphTransfer
(
num_state
)
self
.
gamma_vis
=
paddle
.
zeros
([
num_node
])
self
.
gamma_word
=
paddle
.
zeros
([
num_class
])
self
.
gamma_vis
=
paddle
.
create_parameter
(
shape
=
self
.
gamma_vis
.
shape
,
self
.
gamma_vis
=
paddle
.
create_parameter
(
shape
=
self
.
gamma_vis
.
shape
,
dtype
=
str
(
self
.
gamma_vis
.
numpy
().
dtype
),
default_initializer
=
paddle
.
nn
.
initializer
.
Assign
(
self
.
gamma_vis
))
self
.
gamma_word
=
paddle
.
create_parameter
(
shape
=
self
.
gamma_word
.
shape
,
self
.
gamma_word
=
paddle
.
create_parameter
(
shape
=
self
.
gamma_word
.
shape
,
dtype
=
str
(
self
.
gamma_word
.
numpy
().
dtype
),
default_initializer
=
paddle
.
nn
.
initializer
.
Assign
(
self
.
gamma_word
))
...
...
@@ -242,6 +216,7 @@ class GraphLayer(nn.Layer):
class
GCN
(
nn
.
Layer
):
def
__init__
(
self
,
num_state
:
int
=
128
,
num_node
:
int
=
64
,
bias
:
bool
=
False
):
super
().
__init__
()
self
.
conv1
=
nn
.
Conv1D
(
...
...
@@ -253,14 +228,7 @@ class GCN(nn.Layer):
groups
=
1
,
)
self
.
relu
=
nn
.
ReLU
()
self
.
conv2
=
nn
.
Conv1D
(
num_state
,
num_state
,
kernel_size
=
1
,
padding
=
0
,
stride
=
1
,
groups
=
1
,
bias_attr
=
bias
)
self
.
conv2
=
nn
.
Conv1D
(
num_state
,
num_state
,
kernel_size
=
1
,
padding
=
0
,
stride
=
1
,
groups
=
1
,
bias_attr
=
bias
)
def
forward
(
self
,
x
:
paddle
.
Tensor
)
->
paddle
.
Tensor
:
h
=
self
.
conv1
(
x
.
transpose
((
0
,
2
,
1
))).
transpose
((
0
,
2
,
1
))
...
...
@@ -276,14 +244,10 @@ class GraphTransfer(nn.Layer):
def
__init__
(
self
,
in_dim
:
int
):
super
().
__init__
()
self
.
channle_in
=
in_dim
self
.
query_conv
=
nn
.
Conv1D
(
in_channels
=
in_dim
,
out_channels
=
in_dim
//
2
,
kernel_size
=
1
)
self
.
key_conv
=
nn
.
Conv1D
(
in_channels
=
in_dim
,
out_channels
=
in_dim
//
2
,
kernel_size
=
1
)
self
.
value_conv_vis
=
nn
.
Conv1D
(
in_channels
=
in_dim
,
out_channels
=
in_dim
,
kernel_size
=
1
)
self
.
value_conv_word
=
nn
.
Conv1D
(
in_channels
=
in_dim
,
out_channels
=
in_dim
,
kernel_size
=
1
)
self
.
query_conv
=
nn
.
Conv1D
(
in_channels
=
in_dim
,
out_channels
=
in_dim
//
2
,
kernel_size
=
1
)
self
.
key_conv
=
nn
.
Conv1D
(
in_channels
=
in_dim
,
out_channels
=
in_dim
//
2
,
kernel_size
=
1
)
self
.
value_conv_vis
=
nn
.
Conv1D
(
in_channels
=
in_dim
,
out_channels
=
in_dim
,
kernel_size
=
1
)
self
.
value_conv_word
=
nn
.
Conv1D
(
in_channels
=
in_dim
,
out_channels
=
in_dim
,
kernel_size
=
1
)
self
.
softmax_vis
=
nn
.
Softmax
(
axis
=-
1
)
self
.
softmax_word
=
nn
.
Softmax
(
axis
=-
2
)
...
...
@@ -299,10 +263,8 @@ class GraphTransfer(nn.Layer):
attention_vis
=
self
.
softmax_vis
(
energy
).
transpose
((
0
,
2
,
1
))
attention_word
=
self
.
softmax_word
(
energy
)
proj_value_vis
=
self
.
value_conv_vis
(
vis_node
).
reshape
((
m_batchsize
,
-
1
,
Nn
))
proj_value_word
=
self
.
value_conv_word
(
word
).
reshape
((
m_batchsize
,
-
1
,
Nc
))
proj_value_vis
=
self
.
value_conv_vis
(
vis_node
).
reshape
((
m_batchsize
,
-
1
,
Nn
))
proj_value_word
=
self
.
value_conv_word
(
word
).
reshape
((
m_batchsize
,
-
1
,
Nc
))
class_out
=
paddle
.
bmm
(
proj_value_vis
,
attention_vis
)
node_out
=
paddle
.
bmm
(
proj_value_word
,
attention_word
)
...
...
modules/image/semantic_segmentation/ginet_resnet50vd_voc/requirements.txt
0 → 100644
浏览文件 @
fbd18e99
paddleseg>=2.3.0
\ No newline at end of file
modules/image/semantic_segmentation/ginet_resnet50vd_voc/resnet.py
浏览文件 @
fbd18e99
...
...
@@ -11,14 +11,13 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
ginet_resnet50vd_voc.layers
as
L
import
paddle
import
paddle.nn
as
nn
import
paddle.nn.functional
as
F
import
ginet_resnet50vd_voc.layers
as
L
class
BasicBlock
(
nn
.
Layer
):
def
__init__
(
self
,
in_channels
:
int
,
out_channels
:
int
,
...
...
@@ -28,23 +27,20 @@ class BasicBlock(nn.Layer):
name
:
str
=
None
):
super
(
BasicBlock
,
self
).
__init__
()
self
.
stride
=
stride
self
.
conv0
=
L
.
ConvBNLayer
(
in_channels
=
in_channels
,
self
.
conv0
=
L
.
ConvBNLayer
(
in_channels
=
in_channels
,
out_channels
=
out_channels
,
kernel_size
=
3
,
stride
=
stride
,
act
=
'relu'
,
name
=
name
+
"_branch2a"
)
self
.
conv1
=
L
.
ConvBNLayer
(
in_channels
=
out_channels
,
self
.
conv1
=
L
.
ConvBNLayer
(
in_channels
=
out_channels
,
out_channels
=
out_channels
,
kernel_size
=
3
,
act
=
None
,
name
=
name
+
"_branch2b"
)
if
not
shortcut
:
self
.
short
=
L
.
ConvBNLayer
(
in_channels
=
in_channels
,
self
.
short
=
L
.
ConvBNLayer
(
in_channels
=
in_channels
,
out_channels
=
out_channels
,
kernel_size
=
1
,
stride
=
1
,
...
...
@@ -67,30 +63,27 @@ class BasicBlock(nn.Layer):
class
ResNet50_vd
(
nn
.
Layer
):
def
__init__
(
self
,
multi_grid
:
tuple
=
(
1
,
2
,
4
)):
def
__init__
(
self
,
multi_grid
:
tuple
=
(
1
,
2
,
4
)):
super
(
ResNet50_vd
,
self
).
__init__
()
depth
=
[
3
,
4
,
6
,
3
]
num_channels
=
[
64
,
256
,
512
,
1024
]
num_filters
=
[
64
,
128
,
256
,
512
]
self
.
feat_channels
=
[
c
*
4
for
c
in
num_filters
]
dilation_dict
=
{
2
:
2
,
3
:
4
}
self
.
conv1_1
=
L
.
ConvBNLayer
(
in_channels
=
3
,
self
.
conv1_1
=
L
.
ConvBNLayer
(
in_channels
=
3
,
out_channels
=
32
,
kernel_size
=
3
,
stride
=
2
,
act
=
'relu'
,
name
=
"conv1_1"
)
self
.
conv1_2
=
L
.
ConvBNLayer
(
in_channels
=
32
,
self
.
conv1_2
=
L
.
ConvBNLayer
(
in_channels
=
32
,
out_channels
=
32
,
kernel_size
=
3
,
stride
=
1
,
act
=
'relu'
,
name
=
"conv1_2"
)
self
.
conv1_3
=
L
.
ConvBNLayer
(
in_channels
=
32
,
self
.
conv1_3
=
L
.
ConvBNLayer
(
in_channels
=
32
,
out_channels
=
64
,
kernel_size
=
3
,
stride
=
1
,
...
...
@@ -104,18 +97,14 @@ class ResNet50_vd(nn.Layer):
block_list
=
[]
for
i
in
range
(
depth
[
block
]):
conv_name
=
"res"
+
str
(
block
+
2
)
+
chr
(
97
+
i
)
dilation_rate
=
dilation_dict
[
block
]
if
dilation_dict
and
block
in
dilation_dict
else
1
dilation_rate
=
dilation_dict
[
block
]
if
dilation_dict
and
block
in
dilation_dict
else
1
if
block
==
3
:
dilation_rate
=
dilation_rate
*
multi_grid
[
i
]
bottleneck_block
=
self
.
add_sublayer
(
'bb_%d_%d'
%
(
block
,
i
),
L
.
BottleneckBlock
(
in_channels
=
num_channels
[
block
]
if
i
==
0
else
num_filters
[
block
]
*
4
,
L
.
BottleneckBlock
(
in_channels
=
num_channels
[
block
]
if
i
==
0
else
num_filters
[
block
]
*
4
,
out_channels
=
num_filters
[
block
],
stride
=
2
if
i
==
0
and
block
!=
0
and
dilation_rate
==
1
else
1
,
stride
=
2
if
i
==
0
and
block
!=
0
and
dilation_rate
==
1
else
1
,
shortcut
=
shortcut
,
if_first
=
block
==
i
==
0
,
name
=
conv_name
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录