Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
e9f8dfb5
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
e9f8dfb5
编写于
4月 22, 2022
作者:
F
Feng Ni
提交者:
GitHub
4月 22, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[cherry-pick] fix yolox cpp infer (#5805)
* fix yolox cpp infer * fix cpp infer order, test=document_fix
上级
1ee341b9
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
55 addition
and
68 deletion
+55
-68
configs/yolox/_base_/yolox_reader.yml
configs/yolox/_base_/yolox_reader.yml
+4
-4
configs/yolox/yolox_nano_300e_coco.yml
configs/yolox/yolox_nano_300e_coco.yml
+4
-4
configs/yolox/yolox_tiny_300e_coco.yml
configs/yolox/yolox_tiny_300e_coco.yml
+4
-4
deploy/cpp/include/preprocess_op.h
deploy/cpp/include/preprocess_op.h
+16
-0
deploy/cpp/src/preprocess_op.cc
deploy/cpp/src/preprocess_op.cc
+18
-0
deploy/python/preprocess.py
deploy/python/preprocess.py
+9
-56
未找到文件。
configs/yolox/_base_/yolox_reader.yml
浏览文件 @
e9f8dfb5
...
@@ -27,8 +27,8 @@ TrainReader:
...
@@ -27,8 +27,8 @@ TrainReader:
EvalReader
:
EvalReader
:
sample_transforms
:
sample_transforms
:
-
Decode
:
{}
-
Decode
:
{}
-
Resize
:
{
target_size
:
640
,
keep_ratio
:
True
}
-
Resize
:
{
target_size
:
[
640
,
640
],
keep_ratio
:
True
,
interp
:
1
}
-
Pad
:
{
size
:
640
,
fill_value
:
[
114.
,
114.
,
114.
]}
-
Pad
:
{
size
:
[
640
,
640
]
,
fill_value
:
[
114.
,
114.
,
114.
]}
-
Permute
:
{}
-
Permute
:
{}
batch_size
:
4
batch_size
:
4
...
@@ -38,7 +38,7 @@ TestReader:
...
@@ -38,7 +38,7 @@ TestReader:
image_shape
:
[
3
,
640
,
640
]
image_shape
:
[
3
,
640
,
640
]
sample_transforms
:
sample_transforms
:
-
Decode
:
{}
-
Decode
:
{}
-
Resize
:
{
target_size
:
640
,
keep_ratio
:
True
}
-
Resize
:
{
target_size
:
[
640
,
640
],
keep_ratio
:
True
,
interp
:
1
}
-
Pad
:
{
size
:
640
,
fill_value
:
[
114.
,
114.
,
114.
]}
-
Pad
:
{
size
:
[
640
,
640
]
,
fill_value
:
[
114.
,
114.
,
114.
]}
-
Permute
:
{}
-
Permute
:
{}
batch_size
:
1
batch_size
:
1
configs/yolox/yolox_nano_300e_coco.yml
浏览文件 @
e9f8dfb5
...
@@ -64,8 +64,8 @@ TrainReader:
...
@@ -64,8 +64,8 @@ TrainReader:
EvalReader
:
EvalReader
:
sample_transforms
:
sample_transforms
:
-
Decode
:
{}
-
Decode
:
{}
-
Resize
:
{
target_size
:
416
,
keep_ratio
:
True
}
-
Resize
:
{
target_size
:
[
416
,
416
],
keep_ratio
:
True
,
interp
:
1
}
-
Pad
:
{
size
:
416
,
fill_value
:
[
114.
,
114.
,
114.
]}
-
Pad
:
{
size
:
[
416
,
416
]
,
fill_value
:
[
114.
,
114.
,
114.
]}
-
Permute
:
{}
-
Permute
:
{}
batch_size
:
8
batch_size
:
8
...
@@ -75,7 +75,7 @@ TestReader:
...
@@ -75,7 +75,7 @@ TestReader:
image_shape
:
[
3
,
416
,
416
]
image_shape
:
[
3
,
416
,
416
]
sample_transforms
:
sample_transforms
:
-
Decode
:
{}
-
Decode
:
{}
-
Resize
:
{
target_size
:
416
,
keep_ratio
:
True
}
-
Resize
:
{
target_size
:
[
416
,
416
],
keep_ratio
:
True
,
interp
:
1
}
-
Pad
:
{
size
:
416
,
fill_value
:
[
114.
,
114.
,
114.
]}
-
Pad
:
{
size
:
[
416
,
416
]
,
fill_value
:
[
114.
,
114.
,
114.
]}
-
Permute
:
{}
-
Permute
:
{}
batch_size
:
1
batch_size
:
1
configs/yolox/yolox_tiny_300e_coco.yml
浏览文件 @
e9f8dfb5
...
@@ -52,8 +52,8 @@ TrainReader:
...
@@ -52,8 +52,8 @@ TrainReader:
EvalReader
:
EvalReader
:
sample_transforms
:
sample_transforms
:
-
Decode
:
{}
-
Decode
:
{}
-
Resize
:
{
target_size
:
416
,
keep_ratio
:
True
}
-
Resize
:
{
target_size
:
[
416
,
416
],
keep_ratio
:
True
,
interp
:
1
}
-
Pad
:
{
size
:
416
,
fill_value
:
[
114.
,
114.
,
114.
]}
-
Pad
:
{
size
:
[
416
,
416
]
,
fill_value
:
[
114.
,
114.
,
114.
]}
-
Permute
:
{}
-
Permute
:
{}
batch_size
:
8
batch_size
:
8
...
@@ -63,7 +63,7 @@ TestReader:
...
@@ -63,7 +63,7 @@ TestReader:
image_shape
:
[
3
,
416
,
416
]
image_shape
:
[
3
,
416
,
416
]
sample_transforms
:
sample_transforms
:
-
Decode
:
{}
-
Decode
:
{}
-
Resize
:
{
target_size
:
416
,
keep_ratio
:
True
}
-
Resize
:
{
target_size
:
[
416
,
416
],
keep_ratio
:
True
,
interp
:
1
}
-
Pad
:
{
size
:
416
,
fill_value
:
[
114.
,
114.
,
114.
]}
-
Pad
:
{
size
:
[
416
,
416
]
,
fill_value
:
[
114.
,
114.
,
114.
]}
-
Permute
:
{}
-
Permute
:
{}
batch_size
:
1
batch_size
:
1
deploy/cpp/include/preprocess_op.h
浏览文件 @
e9f8dfb5
...
@@ -161,6 +161,20 @@ class WarpAffine : public PreprocessOp {
...
@@ -161,6 +161,20 @@ class WarpAffine : public PreprocessOp {
int
pad_
=
31
;
int
pad_
=
31
;
};
};
class
Pad
:
public
PreprocessOp
{
public:
virtual
void
Init
(
const
YAML
::
Node
&
item
)
{
size_
=
item
[
"size"
].
as
<
std
::
vector
<
int
>>
();
fill_value_
=
item
[
"fill_value"
].
as
<
std
::
vector
<
float
>>
();
}
virtual
void
Run
(
cv
::
Mat
*
im
,
ImageBlob
*
data
);
private:
std
::
vector
<
int
>
size_
;
std
::
vector
<
float
>
fill_value_
;
};
void
CropImg
(
cv
::
Mat
&
img
,
void
CropImg
(
cv
::
Mat
&
img
,
cv
::
Mat
&
crop_img
,
cv
::
Mat
&
crop_img
,
std
::
vector
<
int
>&
area
,
std
::
vector
<
int
>&
area
,
...
@@ -203,6 +217,8 @@ class Preprocessor {
...
@@ -203,6 +217,8 @@ class Preprocessor {
return
std
::
make_shared
<
TopDownEvalAffine
>
();
return
std
::
make_shared
<
TopDownEvalAffine
>
();
}
else
if
(
name
==
"WarpAffine"
)
{
}
else
if
(
name
==
"WarpAffine"
)
{
return
std
::
make_shared
<
WarpAffine
>
();
return
std
::
make_shared
<
WarpAffine
>
();
}
else
if
(
name
==
"Pad"
)
{
return
std
::
make_shared
<
Pad
>
();
}
}
std
::
cerr
<<
"can not find function of OP: "
<<
name
std
::
cerr
<<
"can not find function of OP: "
<<
name
<<
" and return: nullptr"
<<
std
::
endl
;
<<
" and return: nullptr"
<<
std
::
endl
;
...
...
deploy/cpp/src/preprocess_op.cc
浏览文件 @
e9f8dfb5
...
@@ -229,6 +229,23 @@ void WarpAffine::Run(cv::Mat* im, ImageBlob* data) {
...
@@ -229,6 +229,23 @@ void WarpAffine::Run(cv::Mat* im, ImageBlob* data) {
};
};
}
}
void
Pad
::
Run
(
cv
::
Mat
*
im
,
ImageBlob
*
data
)
{
int
h
=
size_
[
0
];
int
w
=
size_
[
1
];
int
rh
=
im
->
rows
;
int
rw
=
im
->
cols
;
if
(
h
==
rh
&&
w
==
rw
){
data
->
in_net_im_
=
im
->
clone
();
return
;
}
cv
::
copyMakeBorder
(
*
im
,
*
im
,
0
,
h
-
rh
,
0
,
w
-
rw
,
cv
::
BORDER_CONSTANT
,
cv
::
Scalar
(
114
));
data
->
in_net_im_
=
im
->
clone
();
data
->
in_net_shape_
=
{
static_cast
<
float
>
(
im
->
rows
),
static_cast
<
float
>
(
im
->
cols
),
};
}
// Preprocessor op running order
// Preprocessor op running order
const
std
::
vector
<
std
::
string
>
Preprocessor
::
RUN_ORDER
=
{
"InitInfo"
,
const
std
::
vector
<
std
::
string
>
Preprocessor
::
RUN_ORDER
=
{
"InitInfo"
,
"TopDownEvalAffine"
,
"TopDownEvalAffine"
,
...
@@ -237,6 +254,7 @@ const std::vector<std::string> Preprocessor::RUN_ORDER = {"InitInfo",
...
@@ -237,6 +254,7 @@ const std::vector<std::string> Preprocessor::RUN_ORDER = {"InitInfo",
"WarpAffine"
,
"WarpAffine"
,
"NormalizeImage"
,
"NormalizeImage"
,
"PadStride"
,
"PadStride"
,
"Pad"
,
"Permute"
};
"Permute"
};
void
Preprocessor
::
Run
(
cv
::
Mat
*
im
,
ImageBlob
*
data
)
{
void
Preprocessor
::
Run
(
cv
::
Mat
*
im
,
ImageBlob
*
data
)
{
...
...
deploy/python/preprocess.py
浏览文件 @
e9f8dfb5
...
@@ -247,77 +247,30 @@ class LetterBoxResize(object):
...
@@ -247,77 +247,30 @@ class LetterBoxResize(object):
class
Pad
(
object
):
class
Pad
(
object
):
def
__init__
(
self
,
def
__init__
(
self
,
size
,
fill_value
=
[
114.0
,
114.0
,
114.0
]):
size
=
None
,
size_divisor
=
32
,
pad_mode
=
0
,
offsets
=
None
,
fill_value
=
(
127.5
,
127.5
,
127.5
)):
"""
"""
Pad image to a specified size
or multiple of size_divisor
.
Pad image to a specified size.
Args:
Args:
size (int, Sequence): image target size, if None, pad to multiple of size_divisor, default None
size (list[int]): image target size
size_divisor (int): size divisor, default 32
fill_value (list[float]): rgb value of pad area, default (114.0, 114.0, 114.0)
pad_mode (int): pad mode, currently only supports four modes [-1, 0, 1, 2]. if -1, use specified offsets
if 0, only pad to right and bottom. if 1, pad according to center. if 2, only pad left and top
offsets (list): [offset_x, offset_y], specify offset while padding, only supported pad_mode=-1
fill_value (bool): rgb value of pad area, default (127.5, 127.5, 127.5)
"""
"""
super
(
Pad
,
self
).
__init__
()
super
(
Pad
,
self
).
__init__
()
if
isinstance
(
size
,
int
):
if
isinstance
(
size
,
int
):
size
=
[
size
,
size
]
size
=
[
size
,
size
]
assert
pad_mode
in
[
-
1
,
0
,
1
,
2
],
'currently only supports four modes [-1, 0, 1, 2]'
if
pad_mode
==
-
1
:
assert
offsets
,
'if pad_mode is -1, offsets should not be None'
self
.
size
=
size
self
.
size
=
size
self
.
size_divisor
=
size_divisor
self
.
pad_mode
=
pad_mode
self
.
fill_value
=
fill_value
self
.
fill_value
=
fill_value
self
.
offsets
=
offsets
def
apply_image
(
self
,
image
,
offsets
,
im_size
,
size
):
x
,
y
=
offsets
im_h
,
im_w
=
im_size
h
,
w
=
size
canvas
=
np
.
ones
((
h
,
w
,
3
),
dtype
=
np
.
float32
)
canvas
*=
np
.
array
(
self
.
fill_value
,
dtype
=
np
.
float32
)
canvas
[
y
:
y
+
im_h
,
x
:
x
+
im_w
,
:]
=
image
.
astype
(
np
.
float32
)
return
canvas
def
__call__
(
self
,
im
,
im_info
):
def
__call__
(
self
,
im
,
im_info
):
im_h
,
im_w
=
im
.
shape
[:
2
]
im_h
,
im_w
=
im
.
shape
[:
2
]
if
self
.
size
:
h
,
w
=
self
.
size
h
,
w
=
self
.
size
assert
(
im_h
<=
h
and
im_w
<=
w
),
'(h, w) of target size should be greater than (im_h, im_w)'
else
:
h
=
int
(
np
.
ceil
(
im_h
/
self
.
size_divisor
)
*
self
.
size_divisor
)
w
=
int
(
np
.
ceil
(
im_w
/
self
.
size_divisor
)
*
self
.
size_divisor
)
if
h
==
im_h
and
w
==
im_w
:
if
h
==
im_h
and
w
==
im_w
:
im
=
im
.
astype
(
np
.
float32
)
im
=
im
.
astype
(
np
.
float32
)
return
im
,
im_info
return
im
,
im_info
if
self
.
pad_mode
==
-
1
:
canvas
=
np
.
ones
((
h
,
w
,
3
),
dtype
=
np
.
float32
)
offset_x
,
offset_y
=
self
.
offsets
canvas
*=
np
.
array
(
self
.
fill_value
,
dtype
=
np
.
float32
)
elif
self
.
pad_mode
==
0
:
canvas
[
0
:
im_h
,
0
:
im_w
,
:]
=
im
.
astype
(
np
.
float32
)
offset_y
,
offset_x
=
0
,
0
im
=
canvas
elif
self
.
pad_mode
==
1
:
offset_y
,
offset_x
=
(
h
-
im_h
)
//
2
,
(
w
-
im_w
)
//
2
else
:
offset_y
,
offset_x
=
h
-
im_h
,
w
-
im_w
offsets
,
im_size
,
size
=
[
offset_x
,
offset_y
],
[
im_h
,
im_w
],
[
h
,
w
]
im
=
self
.
apply_image
(
im
,
offsets
,
im_size
,
size
)
if
self
.
pad_mode
==
0
:
return
im
,
im_info
return
im
,
im_info
return
im
,
im_info
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录