Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
3248cc58
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
1 年多 前同步成功
通知
115
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3248cc58
编写于
7月 09, 2022
作者:
Y
Yang Nie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update `DecodeImage`
上级
4266b879
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
20 addition
and
26 deletion
+20
-26
ppcls/data/preprocess/ops/operators.py
ppcls/data/preprocess/ops/operators.py
+20
-26
未找到文件。
ppcls/data/preprocess/ops/operators.py
浏览文件 @
3248cc58
...
...
@@ -140,13 +140,12 @@ class DecodeImage(object):
""" decode image """
def
__init__
(
self
,
to_np
=
True
,
to_rgb
=
True
,
to_np
=
False
,
channel_first
=
False
,
backend
=
"cv2"
,
return_numpy
=
True
):
self
.
to_rgb
=
to_rgb
backend
=
"cv2"
):
self
.
to_np
=
to_np
# to numpy
self
.
to_rgb
=
to_rgb
# only enabled when to_np is True
self
.
channel_first
=
channel_first
# only enabled when to_np is True
if
backend
.
lower
()
not
in
[
"cv2"
,
"pil"
]:
...
...
@@ -156,38 +155,33 @@ class DecodeImage(object):
backend
=
"cv2"
self
.
backend
=
backend
.
lower
()
if
not
return_numpy
:
assert
to_rgb
,
f
"
\"
to_rgb
\"
must be True while
\"
return_numpy
\"
is False."
assert
not
channel_first
,
f
"
\"
channel_first
\"
must be False while
\"
return_numpy
\"
is False
."
self
.
return_numpy
=
return_numpy
if
not
to_np
:
logger
.
warning
(
f
"
\"
to_rgb
\"
and
\"
channel_first
\"
are only enabled when to_np is True.
\"
to_np
\"
is now
{
to_np
}
."
)
def
__call__
(
self
,
img
):
if
isinstance
(
img
,
Image
.
Image
):
if
self
.
return_numpy
:
img
=
np
.
asarray
(
img
)[:,
:,
::
-
1
]
# to bgr
assert
self
.
backend
==
"pil"
,
"invalid input 'img' in DecodeImage"
elif
isinstance
(
img
,
np
.
ndarray
):
assert
self
.
return_numpy
,
"invalid input 'img' in DecodeImage"
else
:
if
six
.
PY2
:
assert
type
(
img
)
is
str
and
len
(
img
)
>
0
,
"invalid input 'img' in DecodeImage"
else
:
assert
type
(
img
)
is
bytes
and
len
(
img
)
>
0
,
"invalid input 'img' in DecodeImage"
assert
self
.
backend
==
"cv2"
,
"invalid input 'img' in DecodeImage"
elif
isinstance
(
img
,
bytes
):
if
self
.
backend
==
"pil"
:
data
=
io
.
BytesIO
(
img
)
img
=
Image
.
open
(
data
).
convert
(
"RGB"
)
if
self
.
return_numpy
:
img
=
np
.
asarray
(
img
)[:,
:,
::
-
1
]
# to bgr
img
=
Image
.
open
(
data
)
else
:
data
=
np
.
frombuffer
(
img
,
dtype
=
'uint8'
)
data
=
np
.
frombuffer
(
img
,
dtype
=
"uint8"
)
img
=
cv2
.
imdecode
(
data
,
1
)
else
:
raise
ValueError
(
"invalid input 'img' in DecodeImage"
)
if
self
.
to_np
:
if
self
.
backend
==
"pil"
:
assert
img
.
mode
==
"RGB"
,
f
"invalid shape of image[
{
img
.
shape
}
]"
img
=
np
.
asarray
(
img
)[:,
:,
::
-
1
]
# BRG
if
self
.
return_numpy
:
if
self
.
to_rgb
:
assert
img
.
shape
[
2
]
==
3
,
'invalid shape of image[%s]'
%
(
img
.
shape
)
assert
img
.
shape
[
2
]
==
3
,
f
"invalid shape of image[
{
img
.
shape
}
]"
img
=
img
[:,
:,
::
-
1
]
if
self
.
channel_first
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录