Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSeg
提交
efbb0c40
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看板
提交
efbb0c40
编写于
9月 24, 2020
作者:
C
chenguowei01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update to 2.0beta
上级
3fa39034
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
24 addition
and
46 deletion
+24
-46
dygraph/paddleseg/core/val.py
dygraph/paddleseg/core/val.py
+3
-4
dygraph/paddleseg/cvlibs/param_init.py
dygraph/paddleseg/cvlibs/param_init.py
+4
-4
dygraph/paddleseg/datasets/dataset.py
dygraph/paddleseg/datasets/dataset.py
+2
-2
dygraph/paddleseg/models/losses/cross_entroy_loss.py
dygraph/paddleseg/models/losses/cross_entroy_loss.py
+6
-26
dygraph/paddleseg/utils/get_environ_info.py
dygraph/paddleseg/utils/get_environ_info.py
+3
-2
dygraph/paddleseg/utils/logger.py
dygraph/paddleseg/utils/logger.py
+1
-1
dygraph/paddleseg/utils/utils.py
dygraph/paddleseg/utils/utils.py
+5
-7
未找到文件。
dygraph/paddleseg/core/val.py
浏览文件 @
efbb0c40
...
...
@@ -17,10 +17,9 @@ import os
import
numpy
as
np
import
tqdm
import
cv2
from
paddle.fluid.dygraph.base
import
to_variable
import
paddle.fluid
as
fluid
import
paddle.nn.functional
as
F
import
paddle
import
paddle.nn.functional
as
F
from
paddle
import
to_variable
import
paddleseg.utils.logger
as
logger
from
paddleseg.utils
import
ConfusionMatrix
...
...
@@ -34,7 +33,7 @@ def evaluate(model,
ignore_index
=
255
,
iter_id
=
None
):
ckpt_path
=
os
.
path
.
join
(
model_dir
,
'model'
)
para_state_dict
,
opti_state_dict
=
fluid
.
load_dygraph
(
ckpt_path
)
para_state_dict
,
opti_state_dict
=
paddle
.
load
(
ckpt_path
)
model
.
set_dict
(
para_state_dict
)
model
.
eval
()
...
...
dygraph/paddleseg/cvlibs/param_init.py
浏览文件 @
efbb0c40
...
...
@@ -12,19 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
paddle.
fluid
as
fluid
import
paddle.
nn
as
nn
def
constant_init
(
param
,
**
kwargs
):
initializer
=
fluid
.
initializer
.
Constant
(
**
kwargs
)
initializer
=
nn
.
initializer
.
Constant
(
**
kwargs
)
initializer
(
param
,
param
.
block
)
def
normal_init
(
param
,
**
kwargs
):
initializer
=
fluid
.
initializer
.
Normal
(
**
kwargs
)
initializer
=
nn
.
initializer
.
Normal
(
**
kwargs
)
initializer
(
param
,
param
.
block
)
def
msra_init
(
param
,
**
kwargs
):
initializer
=
fluid
.
initializer
.
MSRA
(
**
kwargs
)
initializer
=
nn
.
initializer
.
MSRA
(
**
kwargs
)
initializer
(
param
,
param
.
block
)
dygraph/paddleseg/datasets/dataset.py
浏览文件 @
efbb0c40
...
...
@@ -14,7 +14,7 @@
import
os
import
paddle
.fluid
as
fluid
import
paddle
import
numpy
as
np
from
PIL
import
Image
...
...
@@ -23,7 +23,7 @@ from paddleseg.transforms import Compose
@
manager
.
DATASETS
.
add_component
class
Dataset
(
fluid
.
io
.
Dataset
):
class
Dataset
(
paddle
.
io
.
Dataset
):
"""Pass in a custom dataset that conforms to the format.
Args:
...
...
dygraph/paddleseg/models/losses/cross_entroy_loss.py
浏览文件 @
efbb0c40
...
...
@@ -15,7 +15,6 @@
import
paddle
from
paddle
import
nn
import
paddle.nn.functional
as
F
import
paddle.fluid
as
fluid
from
paddleseg.cvlibs
import
manager
'''
...
...
@@ -107,34 +106,15 @@ class CrossEntropyLoss(nn.Layer):
if
len
(
label
.
shape
)
!=
len
(
logit
.
shape
):
label
=
paddle
.
unsqueeze
(
label
,
1
)
# logit = paddle.transpose(logit, [0, 2, 3, 1])
# label = paddle.transpose(label, [0, 2, 3, 1])
# loss = F.softmax_with_cross_entropy(
# logit, label, ignore_index=self.ignore_index, axis=-1)
# loss = paddle.reduce_mean(loss)
logit
=
paddle
.
transpose
(
logit
,
[
0
,
2
,
3
,
1
])
label
=
paddle
.
transpose
(
label
,
[
0
,
2
,
3
,
1
])
loss
=
F
.
softmax_with_cross_entropy
(
logit
,
label
,
ignore_index
=
self
.
ignore_index
,
axis
=-
1
)
# mask = label != self.ignore_index
# mask = paddle.cast(mask, 'float32')
# avg_loss = loss / (paddle.mean(mask) + self.EPS)
# label.stop_gradient = True
# mask.stop_gradient = True
# return avg_loss
logit
=
fluid
.
layers
.
transpose
(
logit
,
[
0
,
2
,
3
,
1
])
label
=
fluid
.
layers
.
transpose
(
label
,
[
0
,
2
,
3
,
1
])
mask
=
label
!=
self
.
ignore_index
mask
=
fluid
.
layers
.
cast
(
mask
,
'float32'
)
loss
,
probs
=
fluid
.
layers
.
softmax_with_cross_entropy
(
logit
,
label
,
ignore_index
=
self
.
ignore_index
,
return_softmax
=
True
,
axis
=-
1
)
mask
=
paddle
.
cast
(
mask
,
'float32'
)
loss
=
loss
*
mask
avg_loss
=
fluid
.
layers
.
mean
(
loss
)
/
(
fluid
.
layers
.
mean
(
mask
)
+
self
.
EPS
)
avg_loss
=
paddle
.
reduce_mean
(
loss
)
/
(
paddle
.
mean
(
mask
)
+
self
.
EPS
)
label
.
stop_gradient
=
True
mask
.
stop_gradient
=
True
...
...
dygraph/paddleseg/utils/get_environ_info.py
浏览文件 @
efbb0c40
...
...
@@ -19,8 +19,8 @@ import subprocess
import
glob
import
paddle
import
paddle.fluid
as
fluid
import
cv2
from
paddle.distributed
import
ParallelEnv
IS_WINDOWS
=
sys
.
platform
==
'win32'
...
...
@@ -96,13 +96,14 @@ def get_environ_info():
env_info
[
'Python'
]
=
sys
.
version
.
replace
(
'
\n
'
,
''
)
# todo is_compiled_with_cuda() has not been moved
compiled_with_cuda
=
paddle
.
fluid
.
is_compiled_with_cuda
()
env_info
[
'Paddle compiled with cuda'
]
=
compiled_with_cuda
if
compiled_with_cuda
:
cuda_home
=
_find_cuda_home
()
env_info
[
'NVCC'
]
=
_get_nvcc_info
(
cuda_home
)
gpu_nums
=
fluid
.
core
.
get_cuda_device_count
()
gpu_nums
=
ParallelEnv
().
nranks
env_info
[
'GPUs used'
]
=
gpu_nums
env_info
[
'CUDA_VISIBLE_DEVICES'
]
=
os
.
environ
.
get
(
'CUDA_VISIBLE_DEVICES'
)
...
...
dygraph/paddleseg/utils/logger.py
浏览文件 @
efbb0c40
...
...
@@ -16,7 +16,7 @@ import time
import
os
import
sys
from
paddle.
fluid.dygraph.parallel
import
ParallelEnv
from
paddle.
distributed
import
ParallelEnv
levels
=
{
0
:
'ERROR'
,
1
:
'WARNING'
,
2
:
'INFO'
,
3
:
'DEBUG'
}
log_level
=
2
...
...
dygraph/paddleseg/utils/utils.py
浏览文件 @
efbb0c40
...
...
@@ -14,11 +14,12 @@
import
contextlib
import
os
import
numpy
as
np
import
math
import
numpy
as
np
import
cv2
import
tempfile
import
paddle
.fluid
as
fluid
import
paddle
from
urllib.parse
import
urlparse
,
unquote
import
filelock
...
...
@@ -74,10 +75,7 @@ def load_pretrained_model(model, pretrained_model):
if
os
.
path
.
exists
(
pretrained_model
):
ckpt_path
=
os
.
path
.
join
(
pretrained_model
,
'model'
)
try
:
para_state_dict
,
_
=
fluid
.
load_dygraph
(
ckpt_path
)
except
:
para_state_dict
=
fluid
.
load_program_state
(
pretrained_model
)
para_state_dict
,
_
=
paddle
.
load
(
ckpt_path
)
model_state_dict
=
model
.
state_dict
()
keys
=
model_state_dict
.
keys
()
...
...
@@ -115,7 +113,7 @@ def resume(model, optimizer, resume_model):
if
os
.
path
.
exists
(
resume_model
):
resume_model
=
os
.
path
.
normpath
(
resume_model
)
ckpt_path
=
os
.
path
.
join
(
resume_model
,
'model'
)
para_state_dict
,
opti_state_dict
=
fluid
.
load_dygraph
(
ckpt_path
)
para_state_dict
,
opti_state_dict
=
paddle
.
load
(
ckpt_path
)
model
.
set_dict
(
para_state_dict
)
optimizer
.
set_dict
(
opti_state_dict
)
epoch
=
resume_model
.
split
(
'_'
)[
-
1
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录