Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSeg
提交
9452bf66
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看板
提交
9452bf66
编写于
6月 15, 2020
作者:
C
chenguowei01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add optic_disc_seg dataset
上级
d73b5914
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
146 addition
and
71 deletion
+146
-71
dygraph/datasets/__init__.py
dygraph/datasets/__init__.py
+1
-0
dygraph/datasets/optic_disc_seg.py
dygraph/datasets/optic_disc_seg.py
+95
-0
dygraph/transforms/transforms.py
dygraph/transforms/transforms.py
+49
-70
dygraph/utils/__init__.py
dygraph/utils/__init__.py
+1
-1
未找到文件。
dygraph/datasets/__init__.py
浏览文件 @
9452bf66
...
...
@@ -13,3 +13,4 @@
# limitations under the License.
from
.dataset
import
Dataset
from
.optic_disc_seg
import
OpticDiscSeg
dygraph/datasets/optic_disc_seg.py
0 → 100644
浏览文件 @
9452bf66
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
print_function
import
os
import
random
from
paddle.fluid.io
import
Dataset
from
utils.download
import
download_file_and_uncompress
LOCAL_PATH
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
URL
=
"https://paddleseg.bj.bcebos.com/dataset/optic_disc_seg.zip"
class
OpticDiscSeg
(
Dataset
):
def
__init__
(
self
,
data_dir
=
None
,
train_list
=
None
,
val_list
=
None
,
test_list
=
None
,
shuffle
=
'False'
,
mode
=
'train'
,
transform
=
None
,
download
=
True
):
self
.
data_dir
=
data_dir
self
.
shuffle
=
shuffle
self
.
transform
=
transform
self
.
file_list
=
list
()
if
mode
.
lower
()
not
in
[
'train'
,
'eval'
,
'test'
]:
raise
Exception
(
"mode should be 'train', 'eval' or 'test', but got {}."
.
format
(
mode
))
if
transform
is
None
:
raise
Exception
(
"transform is necessary, but it is None."
)
self
.
data_dir
=
data_dir
if
self
.
data_dir
is
None
:
if
not
download
:
raise
Exception
(
"data_file not set and auto download disabled."
)
self
.
data_dir
=
download_file_and_uncompress
(
url
=
URL
,
savepath
=
LOCAL_PATH
,
extrapath
=
LOCAL_PATH
)
if
mode
==
'train'
:
file_list
=
os
.
path
.
join
(
self
.
data_dir
,
'train_list.txt'
)
elif
mode
==
'eval'
:
file_list
=
os
.
paht
.
join
(
self
.
data_dir
,
'val_list.txt'
)
else
:
file_list
=
os
.
path
.
join
(
self
.
data_dir
,
'test_list.txt'
)
else
:
if
mode
==
'train'
:
file_list
=
train_list
elif
mode
==
'eval'
:
file_list
=
val_list
else
:
file_list
=
test_list
with
open
(
file_list
,
'r'
)
as
f
:
for
line
in
f
:
items
=
line
.
strip
().
split
()
if
len
(
items
)
!=
2
:
if
mode
==
'train'
or
mode
==
'eval'
:
raise
Exception
(
"File list format incorrect! It should be"
" image_name label_name
\\
n"
)
image_path
=
os
.
path
.
join
(
self
.
data_dir
,
items
[
0
])
grt_path
=
None
else
:
image_path
=
os
.
path
.
join
(
self
.
data_dir
,
items
[
0
])
grt_path
=
os
.
path
.
join
(
self
.
data_dir
,
items
[
1
])
self
.
file_list
.
append
([
image_path
,
grt_path
])
if
shuffle
:
random
.
shuffle
(
self
.
file_list
)
def
__getitem__
(
self
,
idx
):
print
(
idx
)
image_path
,
grt_path
=
self
.
file_list
[
idx
]
return
self
.
transform
(
im
=
image_path
,
label
=
grt_path
)
def
__len__
(
self
):
return
len
(
self
.
file_list
)
dygraph/transforms/transforms.py
浏览文件 @
9452bf66
...
...
@@ -33,8 +33,7 @@ class Compose:
ValueError: transforms元素个数小于1。
"""
def
__init__
(
self
,
transforms
,
to_rgb
=
False
):
def
__init__
(
self
,
transforms
,
to_rgb
=
True
):
if
not
isinstance
(
transforms
,
list
):
raise
TypeError
(
'The transforms must be a list!'
)
if
len
(
transforms
)
<
1
:
...
...
@@ -87,7 +86,6 @@ class RandomHorizontalFlip:
prob (float): 随机水平翻转的概率。默认值为0.5。
"""
def
__init__
(
self
,
prob
=
0.5
):
self
.
prob
=
prob
...
...
@@ -119,7 +117,6 @@ class RandomVerticalFlip:
Args:
prob (float): 随机垂直翻转的概率。默认值为0.1。
"""
def
__init__
(
self
,
prob
=
0.1
):
self
.
prob
=
prob
...
...
@@ -236,7 +233,6 @@ class ResizeByLong:
Args:
long_size (int): resize后图像的长边大小。
"""
def
__init__
(
self
,
long_size
):
self
.
long_size
=
long_size
...
...
@@ -278,7 +274,6 @@ class ResizeRangeScaling:
Raises:
ValueError: min_value大于max_value
"""
def
__init__
(
self
,
min_value
=
400
,
max_value
=
600
):
if
min_value
>
max_value
:
raise
ValueError
(
'min_value must be less than max_value, '
...
...
@@ -326,7 +321,6 @@ class ResizeStepScaling:
Raises:
ValueError: min_scale_factor大于max_scale_factor
"""
def
__init__
(
self
,
min_scale_factor
=
0.75
,
max_scale_factor
=
1.25
,
...
...
@@ -392,7 +386,6 @@ class Normalize:
Raises:
ValueError: mean或std不是list对象。std包含0。
"""
def
__init__
(
self
,
mean
=
[
0.5
,
0.5
,
0.5
],
std
=
[
0.5
,
0.5
,
0.5
]):
self
.
mean
=
mean
self
.
std
=
std
...
...
@@ -438,7 +431,6 @@ class Padding:
TypeError: target_size不是int|list|tuple。
ValueError: target_size为list|tuple时元素个数不等于2。
"""
def
__init__
(
self
,
target_size
,
im_padding_value
=
[
127.5
,
127.5
,
127.5
],
...
...
@@ -491,23 +483,21 @@ class Padding:
'the size of image should be less than target_size, but the size of image ({}, {}), is larger than target_size ({}, {})'
.
format
(
im_width
,
im_height
,
target_width
,
target_height
))
else
:
im
=
cv2
.
copyMakeBorder
(
im
,
0
,
pad_height
,
0
,
pad_width
,
cv2
.
BORDER_CONSTANT
,
value
=
self
.
im_padding_value
)
im
=
cv2
.
copyMakeBorder
(
im
,
0
,
pad_height
,
0
,
pad_width
,
cv2
.
BORDER_CONSTANT
,
value
=
self
.
im_padding_value
)
if
label
is
not
None
:
label
=
cv2
.
copyMakeBorder
(
label
,
0
,
pad_height
,
0
,
pad_width
,
cv2
.
BORDER_CONSTANT
,
value
=
self
.
label_padding_value
)
label
=
cv2
.
copyMakeBorder
(
label
,
0
,
pad_height
,
0
,
pad_width
,
cv2
.
BORDER_CONSTANT
,
value
=
self
.
label_padding_value
)
if
label
is
None
:
return
(
im
,
im_info
)
else
:
...
...
@@ -526,7 +516,6 @@ class RandomPaddingCrop:
TypeError: crop_size不是int/list/tuple。
ValueError: target_size为list/tuple时元素个数不等于2。
"""
def
__init__
(
self
,
crop_size
=
512
,
im_padding_value
=
[
127.5
,
127.5
,
127.5
],
...
...
@@ -575,23 +564,21 @@ class RandomPaddingCrop:
pad_height
=
max
(
crop_height
-
img_height
,
0
)
pad_width
=
max
(
crop_width
-
img_width
,
0
)
if
(
pad_height
>
0
or
pad_width
>
0
):
im
=
cv2
.
copyMakeBorder
(
im
,
0
,
pad_height
,
0
,
pad_width
,
cv2
.
BORDER_CONSTANT
,
value
=
self
.
im_padding_value
)
im
=
cv2
.
copyMakeBorder
(
im
,
0
,
pad_height
,
0
,
pad_width
,
cv2
.
BORDER_CONSTANT
,
value
=
self
.
im_padding_value
)
if
label
is
not
None
:
label
=
cv2
.
copyMakeBorder
(
label
,
0
,
pad_height
,
0
,
pad_width
,
cv2
.
BORDER_CONSTANT
,
value
=
self
.
label_padding_value
)
label
=
cv2
.
copyMakeBorder
(
label
,
0
,
pad_height
,
0
,
pad_width
,
cv2
.
BORDER_CONSTANT
,
value
=
self
.
label_padding_value
)
img_height
=
im
.
shape
[
0
]
img_width
=
im
.
shape
[
1
]
...
...
@@ -599,11 +586,11 @@ class RandomPaddingCrop:
h_off
=
np
.
random
.
randint
(
img_height
-
crop_height
+
1
)
w_off
=
np
.
random
.
randint
(
img_width
-
crop_width
+
1
)
im
=
im
[
h_off
:(
crop_height
+
h_off
),
w_off
:(
w_off
+
crop_width
),
:]
im
=
im
[
h_off
:(
crop_height
+
h_off
),
w_off
:(
w_off
+
crop_width
),
:]
if
label
is
not
None
:
label
=
label
[
h_off
:(
crop_height
+
h_off
),
w_off
:(
w_off
+
crop_width
)]
label
=
label
[
h_off
:(
crop_height
+
h_off
),
w_off
:(
w_off
+
crop_width
)]
if
label
is
None
:
return
(
im
,
im_info
)
else
:
...
...
@@ -616,7 +603,6 @@ class RandomBlur:
Args:
prob (float): 图像模糊概率。默认为0.1。
"""
def
__init__
(
self
,
prob
=
0.1
):
self
.
prob
=
prob
...
...
@@ -664,7 +650,6 @@ class RandomRotation:
label_padding_value (int): 标注图像padding的值。默认为255。
"""
def
__init__
(
self
,
max_rotation
=
15
,
im_padding_value
=
[
127.5
,
127.5
,
127.5
],
...
...
@@ -701,20 +686,18 @@ class RandomRotation:
r
[
0
,
2
]
+=
(
nw
/
2
)
-
cx
r
[
1
,
2
]
+=
(
nh
/
2
)
-
cy
dsize
=
(
nw
,
nh
)
im
=
cv2
.
warpAffine
(
im
,
r
,
dsize
=
dsize
,
flags
=
cv2
.
INTER_LINEAR
,
borderMode
=
cv2
.
BORDER_CONSTANT
,
borderValue
=
self
.
im_padding_value
)
label
=
cv2
.
warpAffine
(
label
,
r
,
dsize
=
dsize
,
flags
=
cv2
.
INTER_NEAREST
,
borderMode
=
cv2
.
BORDER_CONSTANT
,
borderValue
=
self
.
label_padding_value
)
im
=
cv2
.
warpAffine
(
im
,
r
,
dsize
=
dsize
,
flags
=
cv2
.
INTER_LINEAR
,
borderMode
=
cv2
.
BORDER_CONSTANT
,
borderValue
=
self
.
im_padding_value
)
label
=
cv2
.
warpAffine
(
label
,
r
,
dsize
=
dsize
,
flags
=
cv2
.
INTER_NEAREST
,
borderMode
=
cv2
.
BORDER_CONSTANT
,
borderValue
=
self
.
label_padding_value
)
if
label
is
None
:
return
(
im
,
im_info
)
...
...
@@ -730,7 +713,6 @@ class RandomScaleAspect:
min_scale (float):裁取图像占原始图像的面积比,取值[0,1],为0时则返回原图。默认为0.5。
aspect_ratio (float): 裁取图像的宽高比范围,非负值,为0时返回原图。默认为0.33。
"""
def
__init__
(
self
,
min_scale
=
0.5
,
aspect_ratio
=
0.33
):
self
.
min_scale
=
min_scale
self
.
aspect_ratio
=
aspect_ratio
...
...
@@ -769,12 +751,10 @@ class RandomScaleAspect:
im
=
im
[
h1
:(
h1
+
dh
),
w1
:(
w1
+
dw
),
:]
label
=
label
[
h1
:(
h1
+
dh
),
w1
:(
w1
+
dw
)]
im
=
cv2
.
resize
(
im
,
(
img_width
,
img_height
),
interpolation
=
cv2
.
INTER_LINEAR
)
label
=
cv2
.
resize
(
label
,
(
img_width
,
img_height
),
interpolation
=
cv2
.
INTER_NEAREST
)
im
=
cv2
.
resize
(
im
,
(
img_width
,
img_height
),
interpolation
=
cv2
.
INTER_LINEAR
)
label
=
cv2
.
resize
(
label
,
(
img_width
,
img_height
),
interpolation
=
cv2
.
INTER_NEAREST
)
break
if
label
is
None
:
return
(
im
,
im_info
)
...
...
@@ -798,7 +778,6 @@ class RandomDistort:
hue_range (int): 色调因子的范围。默认为18。
hue_prob (float): 随机调整色调的概率。默认为0.5。
"""
def
__init__
(
self
,
brightness_range
=
0.5
,
brightness_prob
=
0.5
,
...
...
dygraph/utils/__init__.py
浏览文件 @
9452bf66
...
...
@@ -13,6 +13,6 @@
# limitations under the License.
from
.
import
logging
from
.
import
download
from
.metrics
import
ConfusionMatrix
from
.download
import
download_file_and_uncompress
from
.utils
import
*
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录