Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSeg
提交
8b1504aa
P
PaddleSeg
项目概览
PaddlePaddle
/
PaddleSeg
通知
286
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看板
提交
8b1504aa
编写于
8月 30, 2019
作者:
C
chenguowei01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add lael gray check
上级
ff6c36f9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
47 addition
and
11 deletion
+47
-11
pdseg/check.py
pdseg/check.py
+47
-11
未找到文件。
pdseg/check.py
浏览文件 @
8b1504aa
...
...
@@ -34,6 +34,7 @@ def init_global_variable():
global
list_wrong
#文件名格式错误列表
global
imread_failed
#图片读取失败列表, 二元列表
global
label_wrong
# 标注图片出错列表
global
label_gray_wrong
# 标注图非灰度图列表
png_format_right_num
=
0
png_format_wrong_num
=
0
...
...
@@ -49,6 +50,7 @@ def init_global_variable():
list_wrong
=
[]
imread_failed
=
[]
label_wrong
=
[]
label_gray_wrong
=
[]
def
parse_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
'PaddleSeg check'
)
...
...
@@ -68,10 +70,13 @@ def correct_print(str):
return
""
.
join
([
"
\n
PASS "
,
str
])
def
cv2_imread
(
file_path
,
flag
=
cv2
.
IMREAD_COLOR
):
# resolve cv2.imread open Chinese file path issues on Windows Platform.
"""
解决 cv2.imread 在window平台打开中文路径的问题.
"""
return
cv2
.
imdecode
(
np
.
fromfile
(
file_path
,
dtype
=
np
.
uint8
),
flag
)
def
get_image_max_height_width
(
img
):
"""获取图片最大宽和高"""
global
max_width
,
max_height
img_shape
=
img
.
shape
height
,
width
=
img_shape
[
0
],
img_shape
[
1
]
...
...
@@ -79,6 +84,7 @@ def get_image_max_height_width(img):
max_width
=
max
(
width
,
max_width
)
def
get_image_min_max_aspectratio
(
img
):
"""计算图片最大宽高比"""
global
min_aspectratio
,
max_aspectratio
img_shape
=
img
.
shape
height
,
width
=
img_shape
[
0
],
img_shape
[
1
]
...
...
@@ -87,11 +93,19 @@ def get_image_min_max_aspectratio(img):
return
min_aspectratio
,
max_aspectratio
def
get_image_dim
(
img
):
"""获取图像的
维度
"""
"""获取图像的
通道数
"""
img_shape
=
img
.
shape
if
img_shape
[
-
1
]
not
in
img_dim
:
img_dim
.
append
(
img_shape
[
-
1
])
def
is_label_gray
(
grt
):
"""判断标签是否为灰度图"""
grt_shape
=
grt
.
shape
if
len
(
grt_shape
)
==
2
:
return
True
else
:
return
False
def
image_label_shape_check
(
img
,
grt
):
"""
验证图像和标注的大小是否匹配
...
...
@@ -110,17 +124,15 @@ def image_label_shape_check(img, grt):
def
ground_truth_check
(
grt
,
grt_path
):
"""
验证标注是否重零开始,标注值为0,1,...,num_classes-1, ingnore_idx
验证标注图像的格式
返回标注的像素数
检查图像是否都是ignore_index
统计标注图类别和像素数
params:
grt: 标注图
grt_path: 标注图路径
return:
png_format: 返回是否是png格式图片
label_correct: 返回标注是否是正确的
label_pixel_num
: 返回标注的像素数
unique: 返回标注类别
counts
: 返回标注的像素数
"""
if
imghdr
.
what
(
grt_path
)
==
"png"
:
png_format
=
True
...
...
@@ -135,7 +147,7 @@ def sum_gt_check(png_format, grt_classes, num_of_each_class):
"""
统计所有标注图上的格式、类别和每个类别的像素数
params:
png_format:
返回
是否是png格式图片
png_format: 是否是png格式图片
grt_classes: 标注类别
num_of_each_class: 各个类别的像素数目
"""
...
...
@@ -322,6 +334,16 @@ def imread_check():
for
i
in
imread_failed
:
logger
.
debug
(
i
)
def
label_gray_check
():
if
len
(
label_gray_wrong
)
==
0
:
logger
.
info
(
correct_print
(
"label gray check"
))
logger
.
info
(
"All label images are gray"
)
else
:
logger
.
info
(
error_print
(
"label gray check"
))
logger
.
info
(
"{} label images are not gray"
.
format
(
len
(
label_gray_wrong
)))
for
i
in
label_gray_wrong
:
logger
.
debug
(
i
)
def
check_train_dataset
():
...
...
@@ -340,11 +362,15 @@ def check_train_dataset():
grt_path
=
os
.
path
.
join
(
cfg
.
DATASET
.
DATA_DIR
,
grt_name
)
try
:
img
=
cv2_imread
(
img_path
,
cv2
.
IMREAD_UNCHANGED
)
grt
=
cv2_imread
(
grt_path
,
cv2
.
IMREAD_
GRAYSCALE
)
grt
=
cv2_imread
(
grt_path
,
cv2
.
IMREAD_
UNCHANGED
)
except
Exception
as
e
:
imread_failed
.
append
((
line
,
str
(
e
)))
continue
is_label_gray
=
label_gray_check
(
grt
)
if
not
is_label_gray
:
label_gray_wrong
.
append
(
line
)
grt
=
cv2
.
cvtColor
(
grt
,
cv2
.
COLOR_BGR2GRAY
)
get_image_dim
(
img
)
is_equal_img_grt_shape
=
image_label_shape_check
(
img
,
grt
)
if
not
is_equal_img_grt_shape
:
...
...
@@ -383,9 +409,14 @@ def check_val_dataset():
grt_path
=
os
.
path
.
join
(
cfg
.
DATASET
.
DATA_DIR
,
grt_name
)
try
:
img
=
cv2_imread
(
img_path
,
cv2
.
IMREAD_UNCHANGED
)
grt
=
cv2_imread
(
grt_path
,
cv2
.
IMREAD_
GRAYSCALE
)
grt
=
cv2_imread
(
grt_path
,
cv2
.
IMREAD_
UNCHANGED
)
except
Exception
as
e
:
imread_failed
.
append
((
line
,
e
.
message
))
is_label_gray
=
label_gray_check
(
grt
)
if
not
is_label_gray
:
label_gray_wrong
.
append
(
line
)
grt
=
cv2
.
cvtColor
(
grt
,
cv2
.
COLOR_BGR2GRAY
)
get_image_max_height_width
(
img
)
get_image_min_max_aspectratio
(
img
)
get_image_dim
(
img
)
...
...
@@ -430,10 +461,15 @@ def check_test_dataset():
grt_path
=
os
.
path
.
join
(
cfg
.
DATASET
.
DATA_DIR
,
grt_name
)
try
:
img
=
cv2_imread
(
img_path
,
cv2
.
IMREAD_UNCHANGED
)
grt
=
cv2_imread
(
grt_path
,
cv2
.
IMREAD_
GRAYSCALE
)
grt
=
cv2_imread
(
grt_path
,
cv2
.
IMREAD_
UNCHANGED
)
except
Exception
as
e
:
imread_failed
.
append
((
line
,
e
.
message
))
continue
is_label_gray
=
label_gray_check
(
grt
)
if
not
is_label_gray
:
label_gray_wrong
.
append
(
line
)
grt
=
cv2
.
cvtColor
(
grt
,
cv2
.
COLOR_BGR2GRAY
)
is_equal_img_grt_shape
=
image_label_shape_check
(
img
,
grt
)
if
not
is_equal_img_grt_shape
:
shape_unequal_image
.
append
(
line
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录