Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
af6dd632
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
1 年多 前同步成功
通知
283
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看板
未验证
提交
af6dd632
编写于
4月 13, 2021
作者:
H
haoyuying
提交者:
GitHub
4月 13, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Raise an exception when the specified module does not support evaluation.
上级
30aace46
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
10 addition
and
16 deletion
+10
-16
paddlehub/finetune/trainer.py
paddlehub/finetune/trainer.py
+6
-1
paddlehub/module/cv_module.py
paddlehub/module/cv_module.py
+4
-15
未找到文件。
paddlehub/finetune/trainer.py
浏览文件 @
af6dd632
...
...
@@ -67,6 +67,7 @@ class Trainer(object):
if
not
isinstance
(
self
.
model
,
paddle
.
nn
.
Layer
):
raise
TypeError
(
'The model {} is not a `paddle.nn.Layer` object.'
.
format
(
self
.
model
.
__name__
))
if
self
.
local_rank
==
0
and
not
os
.
path
.
exists
(
self
.
checkpoint_dir
):
os
.
makedirs
(
self
.
checkpoint_dir
)
...
...
@@ -178,6 +179,9 @@ class Trainer(object):
collate_fn(callable): function to generate mini-batch data by merging the sample list.
None for only stack each fields of sample in axis 0(same as :attr::`np.stack(..., axis=0)`). Default None
'''
if
eval_dataset
is
not
None
and
not
hasattr
(
self
.
model
,
'validation_step'
):
raise
NotImplementedError
(
'The specified finetuning model does not support evaluation.'
)
batch_sampler
=
paddle
.
io
.
DistributedBatchSampler
(
train_dataset
,
batch_size
=
batch_size
,
shuffle
=
True
,
drop_last
=
False
)
loader
=
paddle
.
io
.
DataLoader
(
...
...
@@ -298,6 +302,7 @@ class Trainer(object):
with
logger
.
processing
(
'Evaluation on validation dataset'
):
for
batch_idx
,
batch
in
enumerate
(
loader
):
result
=
self
.
validation_step
(
batch
,
batch_idx
)
loss
=
result
.
get
(
'loss'
,
None
)
metrics
=
result
.
get
(
'metrics'
,
{})
bs
=
batch
[
0
].
shape
[
0
]
...
...
@@ -363,7 +368,7 @@ class Trainer(object):
batch_idx(int) : The index of batch.
'''
if
self
.
nranks
>
1
:
result
=
self
.
model
.
_layers
.
validation_step
(
batch
,
batch_idx
)
result
=
self
.
model
.
_layers
.
validation_step
(
batch
,
batch_idx
)
else
:
result
=
self
.
model
.
validation_step
(
batch
,
batch_idx
)
return
result
...
...
paddlehub/module/cv_module.py
浏览文件 @
af6dd632
...
...
@@ -643,21 +643,8 @@ class ImageSegmentationModule(ImageServing, RunModule):
Returns:
results(dict): The model outputs, such as loss.
'''
return
self
.
validation_step
(
batch
,
batch_idx
)
def
validation_step
(
self
,
batch
:
List
[
paddle
.
Tensor
],
batch_idx
:
int
)
->
dict
:
"""
One step for validation, which should be called as forward computation.
Args:
batch(list[paddle.Tensor]): The one batch data, which contains images and labels.
batch_idx(int): The index of batch.
Returns:
results(dict) : The model outputs, such as metrics.
"""
label
=
batch
[
1
].
astype
(
'int64'
)
criterionCE
=
nn
.
loss
.
CrossEntropyLoss
()
...
...
@@ -666,10 +653,12 @@ class ImageSegmentationModule(ImageServing, RunModule):
for
i
in
range
(
len
(
logits
)):
logit
=
logits
[
i
]
if
logit
.
shape
[
-
2
:]
!=
label
.
shape
[
-
2
:]:
logit
=
F
.
resize_bilinear
(
logit
,
label
.
shape
[
-
2
:])
logit
=
F
.
interpolate
(
logit
,
label
.
shape
[
-
2
:],
mode
=
'bilinear'
)
logit
=
logit
.
transpose
([
0
,
2
,
3
,
1
])
loss_ce
=
criterionCE
(
logit
,
label
)
loss
+=
loss_ce
/
len
(
logits
)
return
{
"loss"
:
loss
}
def
predict
(
self
,
images
:
Union
[
str
,
np
.
ndarray
],
batch_size
:
int
=
1
,
visualization
:
bool
=
True
,
save_path
:
str
=
'seg_result'
)
->
List
[
np
.
ndarray
]:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录