Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
b18e5972
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看板
提交
b18e5972
编写于
8月 17, 2022
作者:
R
root
提交者:
Tingquan Gao
8月 23, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
debug: reset to develop
fix the commit 72da54f that overwrite the file from release/2.4
上级
0da8db17
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
39 addition
and
12 deletion
+39
-12
deploy/python/preprocess.py
deploy/python/preprocess.py
+39
-12
未找到文件。
deploy/python/preprocess.py
浏览文件 @
b18e5972
...
...
@@ -27,8 +27,9 @@ import cv2
import
numpy
as
np
import
importlib
from
PIL
import
Image
from
paddle.vision.transforms
import
ToTensor
,
Normalize
from
.det_preprocess
import
DetNormalizeImage
,
DetPadStride
,
DetPermute
,
DetResize
from
python
.det_preprocess
import
DetNormalizeImage
,
DetPadStride
,
DetPermute
,
DetResize
def
create_operators
(
params
):
...
...
@@ -53,13 +54,14 @@ def create_operators(params):
class
UnifiedResize
(
object
):
def
__init__
(
self
,
interpolation
=
None
,
backend
=
"cv2"
):
def
__init__
(
self
,
interpolation
=
None
,
backend
=
"cv2"
,
return_numpy
=
True
):
_cv2_interp_from_str
=
{
'nearest'
:
cv2
.
INTER_NEAREST
,
'bilinear'
:
cv2
.
INTER_LINEAR
,
'area'
:
cv2
.
INTER_AREA
,
'bicubic'
:
cv2
.
INTER_CUBIC
,
'lanczos'
:
cv2
.
INTER_LANCZOS4
'lanczos'
:
cv2
.
INTER_LANCZOS4
,
'random'
:
(
cv2
.
INTER_LINEAR
,
cv2
.
INTER_CUBIC
)
}
_pil_interp_from_str
=
{
'nearest'
:
Image
.
NEAREST
,
...
...
@@ -67,13 +69,26 @@ class UnifiedResize(object):
'bicubic'
:
Image
.
BICUBIC
,
'box'
:
Image
.
BOX
,
'lanczos'
:
Image
.
LANCZOS
,
'hamming'
:
Image
.
HAMMING
'hamming'
:
Image
.
HAMMING
,
'random'
:
(
Image
.
BILINEAR
,
Image
.
BICUBIC
)
}
def
_pil_resize
(
src
,
size
,
resample
):
def
_cv2_resize
(
src
,
size
,
resample
):
if
isinstance
(
resample
,
tuple
):
resample
=
random
.
choice
(
resample
)
return
cv2
.
resize
(
src
,
size
,
interpolation
=
resample
)
def
_pil_resize
(
src
,
size
,
resample
,
return_numpy
=
True
):
if
isinstance
(
resample
,
tuple
):
resample
=
random
.
choice
(
resample
)
if
isinstance
(
src
,
np
.
ndarray
):
pil_img
=
Image
.
fromarray
(
src
)
else
:
pil_img
=
src
pil_img
=
pil_img
.
resize
(
size
,
resample
)
if
return_numpy
:
return
np
.
asarray
(
pil_img
)
return
pil_img
if
backend
.
lower
()
==
"cv2"
:
if
isinstance
(
interpolation
,
str
):
...
...
@@ -81,11 +96,12 @@ class UnifiedResize(object):
# compatible with opencv < version 4.4.0
elif
interpolation
is
None
:
interpolation
=
cv2
.
INTER_LINEAR
self
.
resize_func
=
partial
(
cv2
.
resize
,
interpolation
=
interpolation
)
self
.
resize_func
=
partial
(
_cv2_resize
,
resample
=
interpolation
)
elif
backend
.
lower
()
==
"pil"
:
if
isinstance
(
interpolation
,
str
):
interpolation
=
_pil_interp_from_str
[
interpolation
.
lower
()]
self
.
resize_func
=
partial
(
_pil_resize
,
resample
=
interpolation
)
self
.
resize_func
=
partial
(
_pil_resize
,
resample
=
interpolation
,
return_numpy
=
return_numpy
)
else
:
logger
.
warning
(
f
"The backend of Resize only support
\"
cv2
\"
or
\"
PIL
\"
.
\"
f
{
backend
}
\"
is unavailable. Use
\"
cv2
\"
instead."
...
...
@@ -93,6 +109,8 @@ class UnifiedResize(object):
self
.
resize_func
=
cv2
.
resize
def
__call__
(
self
,
src
,
size
):
if
isinstance
(
size
,
list
):
size
=
tuple
(
size
)
return
self
.
resize_func
(
src
,
size
)
...
...
@@ -137,7 +155,8 @@ class ResizeImage(object):
size
=
None
,
resize_short
=
None
,
interpolation
=
None
,
backend
=
"cv2"
):
backend
=
"cv2"
,
return_numpy
=
True
):
if
resize_short
is
not
None
and
resize_short
>
0
:
self
.
resize_short
=
resize_short
self
.
w
=
None
...
...
@@ -151,10 +170,18 @@ class ResizeImage(object):
'both 'size' and 'resize_short' are None"
)
self
.
_resize_func
=
UnifiedResize
(
interpolation
=
interpolation
,
backend
=
backend
)
interpolation
=
interpolation
,
backend
=
backend
,
return_numpy
=
return_numpy
)
def
__call__
(
self
,
img
):
if
isinstance
(
img
,
np
.
ndarray
):
# numpy input
img_h
,
img_w
=
img
.
shape
[:
2
]
else
:
# PIL image input
img_w
,
img_h
=
img
.
size
if
self
.
resize_short
is
not
None
:
percent
=
float
(
self
.
resize_short
)
/
min
(
img_w
,
img_h
)
w
=
int
(
round
(
img_w
*
percent
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录