Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSeg
提交
d72fb677
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看板
提交
d72fb677
编写于
8月 18, 2020
作者:
C
chenguowei01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change logging to logger
上级
ec54aeff
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
21 addition
and
21 deletion
+21
-21
dygraph/core/infer.py
dygraph/core/infer.py
+2
-2
dygraph/core/train.py
dygraph/core/train.py
+3
-3
dygraph/core/val.py
dygraph/core/val.py
+7
-7
dygraph/utils/__init__.py
dygraph/utils/__init__.py
+1
-1
dygraph/utils/logger.py
dygraph/utils/logger.py
+0
-0
dygraph/utils/utils.py
dygraph/utils/utils.py
+8
-8
未找到文件。
dygraph/core/infer.py
浏览文件 @
d72fb677
...
...
@@ -21,7 +21,7 @@ import cv2
import
tqdm
from
dygraph
import
utils
import
dygraph.utils.logg
ing
as
logging
import
dygraph.utils.logg
er
as
logger
def
mkdir
(
path
):
...
...
@@ -39,7 +39,7 @@ def infer(model, test_dataset=None, model_dir=None, save_dir='output'):
added_saved_dir
=
os
.
path
.
join
(
save_dir
,
'added'
)
pred_saved_dir
=
os
.
path
.
join
(
save_dir
,
'prediction'
)
logg
ing
.
info
(
"Start to predict..."
)
logg
er
.
info
(
"Start to predict..."
)
for
im
,
im_info
,
im_path
in
tqdm
.
tqdm
(
test_dataset
):
im
=
to_variable
(
im
)
pred
,
_
=
model
(
im
)
...
...
dygraph/core/train.py
浏览文件 @
d72fb677
...
...
@@ -19,7 +19,7 @@ from paddle.fluid.dygraph.parallel import ParallelEnv
from
paddle.fluid.io
import
DataLoader
from
paddle.incubate.hapi.distributed
import
DistributedBatchSampler
import
dygraph.utils.logg
ing
as
logging
import
dygraph.utils.logg
er
as
logger
from
dygraph.utils
import
load_pretrained_model
from
dygraph.utils
import
resume
from
dygraph.utils
import
Timer
,
calculate_eta
...
...
@@ -111,7 +111,7 @@ def train(model,
train_batch_cost
=
0.0
remain_steps
=
total_steps
-
num_steps
eta
=
calculate_eta
(
remain_steps
,
avg_train_batch_cost
)
logg
ing
.
info
(
logg
er
.
info
(
"[TRAIN] Epoch={}/{}, Step={}/{}, loss={:.4f}, lr={:.6f}, batch_cost={:.4f}, reader_cost={:.4f} | ETA {}"
.
format
(
epoch
+
1
,
num_epochs
,
step
+
1
,
steps_per_epoch
,
avg_loss
*
nranks
,
lr
,
avg_train_batch_cost
,
...
...
@@ -152,7 +152,7 @@ def train(model,
best_model_dir
=
os
.
path
.
join
(
save_dir
,
"best_model"
)
fluid
.
save_dygraph
(
model
.
state_dict
(),
os
.
path
.
join
(
best_model_dir
,
'model'
))
logg
ing
.
info
(
logg
er
.
info
(
'Current evaluated best model in eval_dataset is epoch_{}, miou={:4f}'
.
format
(
best_model_epoch
,
best_mean_iou
))
...
...
dygraph/core/val.py
浏览文件 @
d72fb677
...
...
@@ -20,7 +20,7 @@ import cv2
from
paddle.fluid.dygraph.base
import
to_variable
import
paddle.fluid
as
fluid
import
dygraph.utils.logg
ing
as
logging
import
dygraph.utils.logg
er
as
logger
from
dygraph.utils
import
ConfusionMatrix
from
dygraph.utils
import
Timer
,
calculate_eta
...
...
@@ -39,7 +39,7 @@ def evaluate(model,
total_steps
=
len
(
eval_dataset
)
conf_mat
=
ConfusionMatrix
(
num_classes
,
streaming
=
True
)
logg
ing
.
info
(
logg
er
.
info
(
"Start to evaluating(total_samples={}, total_steps={})..."
.
format
(
len
(
eval_dataset
),
total_steps
))
timer
=
Timer
()
...
...
@@ -69,7 +69,7 @@ def evaluate(model,
time_step
=
timer
.
elapsed_time
()
remain_step
=
total_steps
-
step
-
1
logg
ing
.
debug
(
logg
er
.
debug
(
"[EVAL] Epoch={}, Step={}/{}, iou={:4f}, sec/step={:.4f} | ETA {}"
.
format
(
epoch_id
,
step
+
1
,
total_steps
,
iou
,
time_step
,
calculate_eta
(
remain_step
,
time_step
)))
...
...
@@ -77,9 +77,9 @@ def evaluate(model,
category_iou
,
miou
=
conf_mat
.
mean_iou
()
category_acc
,
macc
=
conf_mat
.
accuracy
()
logg
ing
.
info
(
"[EVAL] #Images={} mAcc={:.4f} mIoU={:.4f}"
.
format
(
logg
er
.
info
(
"[EVAL] #Images={} mAcc={:.4f} mIoU={:.4f}"
.
format
(
len
(
eval_dataset
),
macc
,
miou
))
logg
ing
.
info
(
"[EVAL] Category IoU: "
+
str
(
category_iou
))
logg
ing
.
info
(
"[EVAL] Category Acc: "
+
str
(
category_acc
))
logg
ing
.
info
(
"[EVAL] Kappa:{:.4f} "
.
format
(
conf_mat
.
kappa
()))
logg
er
.
info
(
"[EVAL] Category IoU: "
+
str
(
category_iou
))
logg
er
.
info
(
"[EVAL] Category Acc: "
+
str
(
category_acc
))
logg
er
.
info
(
"[EVAL] Kappa:{:.4f} "
.
format
(
conf_mat
.
kappa
()))
return
miou
,
macc
dygraph/utils/__init__.py
浏览文件 @
d72fb677
...
...
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from
.
import
logg
ing
from
.
import
logg
er
from
.
import
download
from
.metrics
import
ConfusionMatrix
from
.utils
import
*
...
...
dygraph/utils/logg
ing
.py
→
dygraph/utils/logg
er
.py
浏览文件 @
d72fb677
文件已移动
dygraph/utils/utils.py
浏览文件 @
d72fb677
...
...
@@ -18,7 +18,7 @@ import math
import
cv2
import
paddle.fluid
as
fluid
from
.
import
logg
ing
from
.
import
logg
er
def
seconds_to_hms
(
seconds
):
...
...
@@ -49,7 +49,7 @@ def get_environ_info():
def
load_pretrained_model
(
model
,
pretrained_model
):
if
pretrained_model
is
not
None
:
logg
ing
.
info
(
'Load pretrained model from {}'
.
format
(
pretrained_model
))
logg
er
.
info
(
'Load pretrained model from {}'
.
format
(
pretrained_model
))
if
os
.
path
.
exists
(
pretrained_model
):
ckpt_path
=
os
.
path
.
join
(
pretrained_model
,
'model'
)
try
:
...
...
@@ -62,10 +62,10 @@ def load_pretrained_model(model, pretrained_model):
num_params_loaded
=
0
for
k
in
keys
:
if
k
not
in
para_state_dict
:
logg
ing
.
warning
(
"{} is not in pretrained model"
.
format
(
k
))
logg
er
.
warning
(
"{} is not in pretrained model"
.
format
(
k
))
elif
list
(
para_state_dict
[
k
].
shape
)
!=
list
(
model_state_dict
[
k
].
shape
):
logg
ing
.
warning
(
logg
er
.
warning
(
"[SKIP] Shape of pretrained params {} doesn't match.(Pretrained: {}, Actual: {})"
.
format
(
k
,
para_state_dict
[
k
].
shape
,
model_state_dict
[
k
].
shape
))
...
...
@@ -73,7 +73,7 @@ def load_pretrained_model(model, pretrained_model):
model_state_dict
[
k
]
=
para_state_dict
[
k
]
num_params_loaded
+=
1
model
.
set_dict
(
model_state_dict
)
logg
ing
.
info
(
"There are {}/{} varaibles are loaded."
.
format
(
logg
er
.
info
(
"There are {}/{} varaibles are loaded."
.
format
(
num_params_loaded
,
len
(
model_state_dict
)))
else
:
...
...
@@ -81,12 +81,12 @@ def load_pretrained_model(model, pretrained_model):
'The pretrained model directory is not Found: {}'
.
format
(
pretrained_model
))
else
:
logg
ing
.
info
(
'No pretrained model to load, train from scratch'
)
logg
er
.
info
(
'No pretrained model to load, train from scratch'
)
def
resume
(
model
,
optimizer
,
resume_model
):
if
resume_model
is
not
None
:
logg
ing
.
info
(
'Resume model from {}'
.
format
(
resume_model
))
logg
er
.
info
(
'Resume model from {}'
.
format
(
resume_model
))
if
os
.
path
.
exists
(
resume_model
):
resume_model
=
os
.
path
.
normpath
(
resume_model
)
ckpt_path
=
os
.
path
.
join
(
resume_model
,
'model'
)
...
...
@@ -102,7 +102,7 @@ def resume(model, optimizer, resume_model):
'The resume model directory is not Found: {}'
.
format
(
resume_model
))
else
:
logg
ing
.
info
(
'No model need to resume'
)
logg
er
.
info
(
'No model need to resume'
)
def
visualize
(
image
,
result
,
save_dir
=
None
,
weight
=
0.6
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录