Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSeg
提交
79b93f76
P
PaddleSeg
项目概览
PaddlePaddle
/
PaddleSeg
通知
285
Star
8
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
53
列表
看板
标记
里程碑
合并请求
3
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleSeg
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
53
Issue
53
列表
看板
标记
里程碑
合并请求
3
合并请求
3
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
79b93f76
编写于
8月 26, 2020
作者:
C
chenguowei01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add comments
上级
5d0a6b72
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
64 addition
and
9 deletion
+64
-9
dygraph/README.md
dygraph/README.md
+3
-3
dygraph/models/architectures/hrnet.py
dygraph/models/architectures/hrnet.py
+17
-1
dygraph/models/fcn.py
dygraph/models/fcn.py
+4
-1
dygraph/models/unet.py
dygraph/models/unet.py
+40
-4
未找到文件。
dygraph/README.md
浏览文件 @
79b93f76
...
...
@@ -6,7 +6,7 @@ export PYTHONPATH=$PYTHONPATH:`pwd`
## 训练
```
python3 train.py --model_name
UN
et \
python3 train.py --model_name
un
et \
--dataset OpticDiscSeg \
--input_size 192 192 \
--iters 10 \
...
...
@@ -17,7 +17,7 @@ python3 train.py --model_name UNet \
## 评估
```
python3 val.py --model_name
UN
et \
python3 val.py --model_name
un
et \
--dataset OpticDiscSeg \
--input_size 192 192 \
--model_dir output/best_model
...
...
@@ -25,7 +25,7 @@ python3 val.py --model_name UNet \
## 预测
```
python3 infer.py --model_name
UN
et \
python3 infer.py --model_name
un
et \
--dataset OpticDiscSeg \
--model_dir output/best_model \
--input_size 192 192
...
...
dygraph/models/architectures/hrnet.py
浏览文件 @
79b93f76
...
...
@@ -32,7 +32,23 @@ __all__ = [
class
HRNet
(
fluid
.
dygraph
.
Layer
):
"""
HRNet:
HRNet:Deep High-Resolution Representation Learning for Visual Recognition
https://arxiv.org/pdf/1908.07919.pdf.
Args:
stage1_num_modules (int): number of modules for stage1. Default 1.
stage1_num_blocks (list): number of blocks per module for stage1. Default [4].
stage1_num_channels (list): number of channels per branch for stage1. Default [64].
stage2_num_modules (int): number of modules for stage2. Default 1.
stage2_num_blocks (list): number of blocks per module for stage2. Default [4, 4]
stage2_num_channels (list): number of channels per branch for stage2. Default [18, 36].
stage3_num_modules (int): number of modules for stage3. Default 4.
stage3_num_blocks (list): number of blocks per module for stage3. Default [4, 4, 4]
stage3_num_channels (list): number of channels per branch for stage3. Default [18, 36, 72].
stage4_num_modules (int): number of modules for stage4. Default 3.
stage4_num_blocks (list): number of blocks per module for stage4. Default [4, 4, 4, 4]
stage4_num_channels (list): number of channels per branch for stage4. Default [18, 36, 72. 144].
has_se (bool): whether to use Squeeze-and-Excitation module. Default False.
"""
def
__init__
(
self
,
...
...
dygraph/models/fcn.py
浏览文件 @
79b93f76
...
...
@@ -41,6 +41,10 @@ class FCN(fluid.dygraph.Layer):
Args:
backbone (str): backbone name,
num_classes (int): the unique number of target classes.
in_channels (int): the channels of input feature maps.
channels (int): channels after conv layer before the last one.
pretrained_model (str): the path of pretrained model.
ignore_index (int): the value of ground-truth mask would be ignored while computing loss or doing evaluation. Default 255.
"""
def
__init__
(
self
,
...
...
@@ -49,7 +53,6 @@ class FCN(fluid.dygraph.Layer):
in_channels
,
channels
=
None
,
pretrained_model
=
None
,
has_se
=
False
,
ignore_index
=
255
,
**
kwargs
):
super
(
FCN
,
self
).
__init__
()
...
...
dygraph/models/unet.py
浏览文件 @
79b93f76
...
...
@@ -12,13 +12,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
os
import
paddle.fluid
as
fluid
from
paddle.fluid.dygraph
import
Conv2D
,
Pool2D
from
paddle.fluid.dygraph
import
SyncBatchNorm
as
BatchNorm
from
paddle.nn
import
SyncBatchNorm
as
BatchNorm
from
dygraph.cvlibs
import
manager
from
dygraph
import
utils
class
UNet
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
self
,
num_classes
,
ignore_index
=
255
):
"""
U-Net: Convolutional Networks for Biomedical Image Segmentation.
https://arxiv.org/abs/1505.04597
Args:
num_classes (int): the unique number of target classes.
pretrained_model (str): the path of pretrained model.
ignore_index (int): the value of ground-truth mask would be ignored while computing loss or doing evaluation. Default 255.
"""
def
__init__
(
self
,
num_classes
,
pretrained_model
=
None
,
ignore_index
=
255
):
super
(
UNet
,
self
).
__init__
()
self
.
encode
=
UnetEncoder
()
self
.
decode
=
UnetDecode
()
...
...
@@ -26,6 +41,8 @@ class UNet(fluid.dygraph.Layer):
self
.
ignore_index
=
ignore_index
self
.
EPS
=
1e-5
self
.
init_weight
(
pretrained_model
)
def
forward
(
self
,
x
,
label
=
None
):
encode_data
,
short_cuts
=
self
.
encode
(
x
)
decode_data
=
self
.
decode
(
encode_data
,
short_cuts
)
...
...
@@ -39,6 +56,20 @@ class UNet(fluid.dygraph.Layer):
pred
=
fluid
.
layers
.
unsqueeze
(
pred
,
axes
=
[
3
])
return
pred
,
score_map
def
init_weight
(
self
,
pretrained_model
=
None
):
"""
Initialize the parameters of model parts.
Args:
pretrained_model ([str], optional): the pretrained_model path of backbone. Defaults to None.
"""
if
pretrained_model
is
not
None
:
if
os
.
path
.
exists
(
pretrained_model
):
utils
.
load_pretrained_model
(
self
.
backbone
,
pretrained_model
)
utils
.
load_pretrained_model
(
self
,
pretrained_model
)
else
:
raise
Exception
(
'Pretrained model is not found: {}'
.
format
(
pretrained_model
))
def
_get_loss
(
self
,
logit
,
label
):
logit
=
fluid
.
layers
.
transpose
(
logit
,
[
0
,
2
,
3
,
1
])
label
=
fluid
.
layers
.
transpose
(
label
,
[
0
,
2
,
3
,
1
])
...
...
@@ -108,14 +139,14 @@ class DoubleConv(fluid.dygraph.Layer):
filter_size
=
3
,
stride
=
1
,
padding
=
1
)
self
.
bn0
=
BatchNorm
(
num_
channels
=
num_
filters
)
self
.
bn0
=
BatchNorm
(
num_filters
)
self
.
conv1
=
Conv2D
(
num_channels
=
num_filters
,
num_filters
=
num_filters
,
filter_size
=
3
,
stride
=
1
,
padding
=
1
)
self
.
bn1
=
BatchNorm
(
num_
channels
=
num_
filters
)
self
.
bn1
=
BatchNorm
(
num_filters
)
def
forward
(
self
,
x
):
x
=
self
.
conv0
(
x
)
...
...
@@ -166,3 +197,8 @@ class GetLogit(fluid.dygraph.Layer):
def
forward
(
self
,
x
):
x
=
self
.
conv
(
x
)
return
x
@
manager
.
MODELS
.
add_component
def
unet
(
*
args
,
**
kwargs
):
return
UNet
(
*
args
,
**
kwargs
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录