Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
30f9fca6
X
X2Paddle
项目概览
PaddlePaddle
/
X2Paddle
大约 1 年 前同步成功
通知
328
Star
698
Fork
167
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
26
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
X2Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
26
Issue
26
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
30f9fca6
编写于
6月 06, 2022
作者:
W
wjj19950828
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rm fluid for custom op
上级
32aa07a9
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
131 addition
and
12 deletion
+131
-12
x2paddle/op_mapper/caffe2paddle/caffe_custom_layer/priorbox.py
...dle/op_mapper/caffe2paddle/caffe_custom_layer/priorbox.py
+80
-3
x2paddle/op_mapper/caffe2paddle/caffe_custom_layer/roipooling.py
...e/op_mapper/caffe2paddle/caffe_custom_layer/roipooling.py
+45
-3
x2paddle/op_mapper/onnx2paddle/onnx_custom_layer/nms.py
x2paddle/op_mapper/onnx2paddle/onnx_custom_layer/nms.py
+6
-6
未找到文件。
x2paddle/op_mapper/caffe2paddle/caffe_custom_layer/priorbox.py
浏览文件 @
30f9fca6
...
...
@@ -13,7 +13,85 @@
# limitations under the License.
import
paddle
import
paddle.fluid
as
fluid
from
paddle
import
_C_ops
from
paddle.common_ops_import
import
Variable
,
LayerHelper
,
check_variable_and_dtype
,
check_type
,
check_dtype
def
prior_box
(
input
,
image
,
min_sizes
,
max_sizes
=
None
,
aspect_ratios
=
[
1.
],
variance
=
[
0.1
,
0.1
,
0.2
,
0.2
],
flip
=
False
,
clip
=
False
,
steps
=
[
0.0
,
0.0
],
offset
=
0.5
,
min_max_aspect_ratios_order
=
False
,
name
=
None
):
helper
=
LayerHelper
(
"prior_box"
,
**
locals
())
dtype
=
helper
.
input_dtype
()
check_variable_and_dtype
(
input
,
'input'
,
[
'uint8'
,
'int8'
,
'float32'
,
'float64'
],
'prior_box'
)
def
_is_list_or_tuple_
(
data
):
return
(
isinstance
(
data
,
list
)
or
isinstance
(
data
,
tuple
))
if
not
_is_list_or_tuple_
(
min_sizes
):
min_sizes
=
[
min_sizes
]
if
not
_is_list_or_tuple_
(
aspect_ratios
):
aspect_ratios
=
[
aspect_ratios
]
if
not
(
_is_list_or_tuple_
(
steps
)
and
len
(
steps
)
==
2
):
raise
ValueError
(
'steps should be a list or tuple '
,
'with length 2, (step_width, step_height).'
)
min_sizes
=
list
(
map
(
float
,
min_sizes
))
aspect_ratios
=
list
(
map
(
float
,
aspect_ratios
))
steps
=
list
(
map
(
float
,
steps
))
cur_max_sizes
=
None
if
max_sizes
is
not
None
and
len
(
max_sizes
)
>
0
and
max_sizes
[
0
]
>
0
:
if
not
_is_list_or_tuple_
(
max_sizes
):
max_sizes
=
[
max_sizes
]
cur_max_sizes
=
max_sizes
if
in_dynamic_mode
():
attrs
=
(
'min_sizes'
,
min_sizes
,
'aspect_ratios'
,
aspect_ratios
,
'variances'
,
variance
,
'flip'
,
flip
,
'clip'
,
clip
,
'step_w'
,
steps
[
0
],
'step_h'
,
steps
[
1
],
'offset'
,
offset
,
'min_max_aspect_ratios_order'
,
min_max_aspect_ratios_order
)
if
cur_max_sizes
is
not
None
:
attrs
+=
(
'max_sizes'
,
cur_max_sizes
)
box
,
var
=
_C_ops
.
prior_box
(
input
,
image
,
*
attrs
)
return
box
,
var
else
:
attrs
=
{
'min_sizes'
:
min_sizes
,
'aspect_ratios'
:
aspect_ratios
,
'variances'
:
variance
,
'flip'
:
flip
,
'clip'
:
clip
,
'step_w'
:
steps
[
0
],
'step_h'
:
steps
[
1
],
'offset'
:
offset
,
'min_max_aspect_ratios_order'
:
min_max_aspect_ratios_order
}
if
cur_max_sizes
is
not
None
:
attrs
[
'max_sizes'
]
=
cur_max_sizes
box
=
helper
.
create_variable_for_type_inference
(
dtype
)
var
=
helper
.
create_variable_for_type_inference
(
dtype
)
helper
.
append_op
(
type
=
"prior_box"
,
inputs
=
{
"Input"
:
input
,
"Image"
:
image
},
outputs
=
{
"Boxes"
:
box
,
"Variances"
:
var
},
attrs
=
attrs
,
)
box
.
stop_gradient
=
True
var
.
stop_gradient
=
True
return
box
,
var
class
PriorBox
(
object
):
...
...
@@ -32,8 +110,7 @@ class PriorBox(object):
}
def
__call__
(
self
,
x0
,
x1
):
box
,
var
=
fluid
.
layers
.
prior_box
(
input
=
x0
,
image
=
x1
,
**
self
.
priorbox_layer_attrs
)
box
,
var
=
prior_box
(
input
=
x0
,
image
=
x1
,
**
self
.
priorbox_layer_attrs
)
box
=
paddle
.
reshape
(
x
=
box
,
shape
=
[
1
,
1
,
-
1
])
var
=
paddle
.
reshape
(
x
=
var
,
shape
=
[
1
,
1
,
-
1
])
out
=
paddle
.
concat
(
x
=
[
box
,
var
],
axis
=
1
)
...
...
x2paddle/op_mapper/caffe2paddle/caffe_custom_layer/roipooling.py
浏览文件 @
30f9fca6
...
...
@@ -13,7 +13,50 @@
# limitations under the License.
import
paddle
import
paddle.fluid
as
fluid
from
paddle
import
_C_ops
from
paddle
import
in_dynamic_mode
from
paddle.common_ops_import
import
Variable
,
LayerHelper
,
check_variable_and_dtype
,
check_type
,
check_dtype
def
roi_pool
(
input
,
rois
,
pooled_height
,
pooled_width
,
spatial_scale
=
1.0
,
rois_num
=
None
,
name
=
None
):
if
in_dynamic_mode
():
assert
rois_num
is
not
None
,
"rois_num should not be None in dygraph mode."
pool_out
,
argmaxes
=
_C_ops
.
roi_pool
(
input
,
rois
,
rois_num
,
"pooled_height"
,
pooled_height
,
"pooled_width"
,
pooled_width
,
"spatial_scale"
,
spatial_scale
)
return
pool_out
,
argmaxes
else
:
check_variable_and_dtype
(
input
,
'input'
,
[
'float32'
],
'roi_pool'
)
check_variable_and_dtype
(
rois
,
'rois'
,
[
'float32'
],
'roi_pool'
)
helper
=
LayerHelper
(
'roi_pool'
,
**
locals
())
dtype
=
helper
.
input_dtype
()
pool_out
=
helper
.
create_variable_for_type_inference
(
dtype
)
argmaxes
=
helper
.
create_variable_for_type_inference
(
dtype
=
'int32'
)
inputs
=
{
"X"
:
input
,
"ROIs"
:
rois
,
}
if
rois_num
is
not
None
:
inputs
[
'RoisNum'
]
=
rois_num
helper
.
append_op
(
type
=
"roi_pool"
,
inputs
=
inputs
,
outputs
=
{
"Out"
:
pool_out
,
"Argmax"
:
argmaxes
},
attrs
=
{
"pooled_height"
:
pooled_height
,
"pooled_width"
:
pooled_width
,
"spatial_scale"
:
spatial_scale
})
return
pool_out
,
argmaxes
class
ROIPooling
(
object
):
...
...
@@ -26,6 +69,5 @@ class ROIPooling(object):
def
__call__
(
self
,
x0
,
x1
):
slice_x1
=
paddle
.
slice
(
input
=
x1
,
axes
=
[
1
],
starts
=
[
1
],
ends
=
[
5
])
out
=
fluid
.
layers
.
roi_pool
(
input
=
x0
,
rois
=
slice_x1
,
**
self
.
roipooling_layer_attrs
)
out
=
roi_pool
(
input
=
x0
,
rois
=
slice_x1
,
**
self
.
roipooling_layer_attrs
)
return
out
x2paddle/op_mapper/onnx2paddle/onnx_custom_layer/nms.py
浏览文件 @
30f9fca6
...
...
@@ -13,9 +13,9 @@
# limitations under the License.
import
paddle
from
paddle
.fluid
import
core
from
paddle
.fluid.framework
import
Variable
,
in_dygraph
_mode
from
paddle.
fluid.layer_helper
import
LayerHelper
from
paddle
import
_C_ops
from
paddle
import
in_dynamic
_mode
from
paddle.
common_ops_import
import
Variable
,
LayerHelper
def
multiclass_nms
(
bboxes
,
...
...
@@ -33,12 +33,12 @@ def multiclass_nms(bboxes,
name
=
None
):
helper
=
LayerHelper
(
'multiclass_nms3'
,
**
locals
())
if
in_dy
graph
_mode
():
if
in_dy
namic
_mode
():
attrs
=
(
'background_label'
,
background_label
,
'score_threshold'
,
score_threshold
,
'nms_top_k'
,
nms_top_k
,
'nms_threshold'
,
nms_threshold
,
'keep_top_k'
,
keep_top_k
,
'nms_eta'
,
nms_eta
,
'normalized'
,
normalized
)
output
,
index
,
nms_rois_num
=
core
.
ops
.
multiclass_nms3
(
bboxes
,
scores
,
output
,
index
,
nms_rois_num
=
_C_
ops
.
multiclass_nms3
(
bboxes
,
scores
,
rois_num
,
*
attrs
)
if
not
return_index
:
index
=
None
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录