Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
48a125d8
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看板
未验证
提交
48a125d8
编写于
9月 10, 2021
作者:
Y
yeliang2258
提交者:
GitHub
9月 10, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #674 from kasyoukin/fix-caffe-pooling-convert-bug
fix caffe的pooling层对于kernel size和stride size的转换错误
上级
5098d192
17126424
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
27 addition
and
25 deletion
+27
-25
x2paddle/decoder/caffe_shape_inference.py
x2paddle/decoder/caffe_shape_inference.py
+8
-8
x2paddle/op_mapper/caffe2paddle/caffe_op_mapper.py
x2paddle/op_mapper/caffe2paddle/caffe_op_mapper.py
+19
-17
未找到文件。
x2paddle/decoder/caffe_shape_inference.py
浏览文件 @
48a125d8
...
@@ -19,25 +19,25 @@ from functools import reduce
...
@@ -19,25 +19,25 @@ from functools import reduce
def
get_kernel_parameters
(
params
):
def
get_kernel_parameters
(
params
):
[
k_h
,
k_w
]
=
[
1
,
1
]
[
k_h
,
k_w
]
=
[
1
,
1
]
if
isinstance
(
params
.
kernel_size
,
numbers
.
Number
):
if
params
.
kernel_h
>
0
or
params
.
kernel_w
>
0
:
k_h
=
params
.
kernel_h
k_w
=
params
.
kernel_w
elif
isinstance
(
params
.
kernel_size
,
numbers
.
Number
):
[
k_h
,
k_w
]
=
[
params
.
kernel_size
]
*
2
[
k_h
,
k_w
]
=
[
params
.
kernel_size
]
*
2
elif
len
(
params
.
kernel_size
)
>
0
:
elif
len
(
params
.
kernel_size
)
>
0
:
k_h
=
params
.
kernel_h
if
params
.
kernel_h
>
0
else
params
.
kernel_size
[
0
]
k_h
=
params
.
kernel_h
if
params
.
kernel_h
>
0
else
params
.
kernel_size
[
0
]
k_w
=
params
.
kernel_w
if
params
.
kernel_w
>
0
else
params
.
kernel_size
[
k_w
=
params
.
kernel_w
if
params
.
kernel_w
>
0
else
params
.
kernel_size
[
len
(
params
.
kernel_size
)
-
1
]
len
(
params
.
kernel_size
)
-
1
]
elif
params
.
kernel_h
>
0
or
params
.
kernel_w
>
0
:
k_h
=
params
.
kernel_h
k_w
=
params
.
kernel_w
[
s_h
,
s_w
]
=
[
1
,
1
]
[
s_h
,
s_w
]
=
[
1
,
1
]
if
isinstance
(
params
.
stride
,
numbers
.
Number
):
if
params
.
stride_h
>
0
or
params
.
stride_w
>
0
:
s_h
=
params
.
stride_h
s_w
=
params
.
stride_w
elif
isinstance
(
params
.
stride
,
numbers
.
Number
):
[
s_h
,
s_w
]
=
[
params
.
stride
]
*
2
[
s_h
,
s_w
]
=
[
params
.
stride
]
*
2
elif
len
(
params
.
stride
)
>
0
:
elif
len
(
params
.
stride
)
>
0
:
s_h
=
params
.
stride_h
if
params
.
stride_h
>
0
else
params
.
stride
[
0
]
s_h
=
params
.
stride_h
if
params
.
stride_h
>
0
else
params
.
stride
[
0
]
s_w
=
params
.
stride_w
if
params
.
stride_w
>
0
else
params
.
stride
[
len
(
s_w
=
params
.
stride_w
if
params
.
stride_w
>
0
else
params
.
stride
[
len
(
params
.
stride
)
-
1
]
params
.
stride
)
-
1
]
elif
params
.
stride_h
>
0
or
params
.
stride_w
>
0
:
s_h
=
params
.
stride_h
s_w
=
params
.
stride_w
[
p_h
,
p_w
]
=
[
0
,
0
]
[
p_h
,
p_w
]
=
[
0
,
0
]
if
isinstance
(
params
.
pad
,
numbers
.
Number
):
if
isinstance
(
params
.
pad
,
numbers
.
Number
):
[
p_h
,
p_w
]
=
[
params
.
pad
]
*
2
[
p_h
,
p_w
]
=
[
params
.
pad
]
*
2
...
...
x2paddle/op_mapper/caffe2paddle/caffe_op_mapper.py
浏览文件 @
48a125d8
...
@@ -72,15 +72,15 @@ def _get_kernel_parameters(kind, params):
...
@@ -72,15 +72,15 @@ def _get_kernel_parameters(kind, params):
k_w
=
params
.
kernel_w
if
params
.
kernel_w
>
0
else
params
.
kernel_size
[
k_w
=
params
.
kernel_w
if
params
.
kernel_w
>
0
else
params
.
kernel_size
[
len
(
params
.
kernel_size
)
-
1
]
len
(
params
.
kernel_size
)
-
1
]
[
s_h
,
s_w
]
=
[
1
,
1
]
[
s_h
,
s_w
]
=
[
1
,
1
]
if
isinstance
(
params
.
stride
,
numbers
.
Number
):
if
params
.
stride_h
>
0
or
params
.
stride_w
>
0
:
s_h
=
params
.
stride_h
s_w
=
params
.
stride_w
elif
isinstance
(
params
.
stride
,
numbers
.
Number
):
[
s_h
,
s_w
]
=
[
params
.
stride
]
*
2
[
s_h
,
s_w
]
=
[
params
.
stride
]
*
2
elif
len
(
params
.
stride
)
>
0
:
elif
len
(
params
.
stride
)
>
0
:
s_h
=
params
.
stride_h
if
params
.
stride_h
>
0
else
params
.
stride
[
0
]
s_h
=
params
.
stride_h
if
params
.
stride_h
>
0
else
params
.
stride
[
0
]
s_w
=
params
.
stride_w
if
params
.
stride_w
>
0
else
params
.
stride
[
len
(
s_w
=
params
.
stride_w
if
params
.
stride_w
>
0
else
params
.
stride
[
len
(
params
.
stride
)
-
1
]
params
.
stride
)
-
1
]
elif
params
.
stride_h
>
0
or
params
.
stride_w
>
0
:
s_h
=
params
.
stride_h
s_w
=
params
.
stride_w
[
p_h
,
p_w
]
=
[
0
,
0
]
[
p_h
,
p_w
]
=
[
0
,
0
]
if
isinstance
(
params
.
pad
,
numbers
.
Number
):
if
isinstance
(
params
.
pad
,
numbers
.
Number
):
[
p_h
,
p_w
]
=
[
params
.
pad
]
*
2
[
p_h
,
p_w
]
=
[
params
.
pad
]
*
2
...
@@ -168,7 +168,8 @@ class CaffeOpMapper():
...
@@ -168,7 +168,8 @@ class CaffeOpMapper():
return
False
return
False
def
directly_map
(
self
,
node
):
def
directly_map
(
self
,
node
):
assert
len
(
node
.
layer
.
bottom
)
==
1
,
'directly_map error with multi inputs'
assert
len
(
node
.
layer
.
bottom
)
==
1
,
'directly_map error with multi inputs'
op_info
=
self
.
directly_map_ops
[
node
.
layer_type
]
op_info
=
self
.
directly_map_ops
[
node
.
layer_type
]
input
=
self
.
graph
.
get_input_node
(
node
,
0
)
input
=
self
.
graph
.
get_input_node
(
node
,
0
)
paddle_op
=
op_info
[
0
]
paddle_op
=
op_info
[
0
]
...
@@ -193,7 +194,8 @@ class CaffeOpMapper():
...
@@ -193,7 +194,8 @@ class CaffeOpMapper():
outputs
=
layer_outputs
)
outputs
=
layer_outputs
)
else
:
else
:
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
kernel
=
paddle_op
,
inputs
=
{
"x"
:
input
.
name
},
kernel
=
paddle_op
,
inputs
=
{
"x"
:
input
.
name
},
outputs
=
[
node
.
name
])
outputs
=
[
node
.
name
])
def
Input
(
self
,
node
):
def
Input
(
self
,
node
):
...
@@ -203,8 +205,7 @@ class CaffeOpMapper():
...
@@ -203,8 +205,7 @@ class CaffeOpMapper():
outputs
=
[
node
.
layer_name
],
outputs
=
[
node
.
layer_name
],
data
=
node
.
name
)
data
=
node
.
name
)
shape
=
list
(
node
.
layer
.
input_param
.
shape
[
0
].
dim
)[
1
:]
shape
=
list
(
node
.
layer
.
input_param
.
shape
[
0
].
dim
)[
1
:]
self
.
inputs_info
[
node
.
name
]
=
[[
-
1
]
+
shape
,
self
.
inputs_info
[
node
.
name
]
=
[[
-
1
]
+
shape
,
"float32"
]
"float32"
]
def
MemoryData
(
self
,
node
):
def
MemoryData
(
self
,
node
):
params
=
node
.
layer
.
memory_data_param
params
=
node
.
layer
.
memory_data_param
...
@@ -619,7 +620,8 @@ class CaffeOpMapper():
...
@@ -619,7 +620,8 @@ class CaffeOpMapper():
num_parameters
=
num_parameters
)
num_parameters
=
num_parameters
)
def
Eltwise
(
self
,
node
):
def
Eltwise
(
self
,
node
):
if
len
(
node
.
layer
.
bottom
)
==
3
and
node
.
layer
.
eltwise_param
.
operation
==
1
:
if
len
(
node
.
layer
.
bottom
)
==
3
and
node
.
layer
.
eltwise_param
.
operation
==
1
:
inputs_dict
=
{}
inputs_dict
=
{}
input0
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
input0
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
input1
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
input1
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
...
@@ -630,18 +632,18 @@ class CaffeOpMapper():
...
@@ -630,18 +632,18 @@ class CaffeOpMapper():
inputs_dict
[
'x'
]
=
input0_name
inputs_dict
[
'x'
]
=
input0_name
inputs_dict
[
'y'
]
=
input1_name
inputs_dict
[
'y'
]
=
input1_name
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
"paddle.add"
,
inputs
=
inputs_dict
,
"paddle.add"
,
outputs
=
[
node
.
layer_name
+
"_1"
])
inputs
=
inputs_dict
,
outputs
=
[
node
.
layer_name
+
"_1"
])
inputs_dict
=
{}
inputs_dict
=
{}
inputs_dict
[
'x'
]
=
node
.
layer_name
+
"_1"
inputs_dict
[
'x'
]
=
node
.
layer_name
+
"_1"
inputs_dict
[
'y'
]
=
input2_name
inputs_dict
[
'y'
]
=
input2_name
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
"paddle.add"
,
inputs
=
inputs_dict
,
"paddle.add"
,
inputs
=
inputs_dict
,
outputs
=
[
node
.
layer_name
])
outputs
=
[
node
.
layer_name
])
return
return
assert
len
(
assert
len
(
node
.
layer
.
node
.
layer
.
bottom
)
==
2
,
"The count of Eltwise node
\'
s input is not 2."
bottom
)
==
2
,
"The count of Eltwise node
\'
s input is not 2."
params
=
node
.
layer
.
eltwise_param
params
=
node
.
layer
.
eltwise_param
mode
=
params
.
operation
mode
=
params
.
operation
inputs
=
[]
inputs
=
[]
...
@@ -925,7 +927,7 @@ class CaffeOpMapper():
...
@@ -925,7 +927,7 @@ class CaffeOpMapper():
offset_real
=
[
0
]
*
len
(
input_shape
)
offset_real
=
[
0
]
*
len
(
input_shape
)
if
hasattr
(
params
,
"offset"
)
and
len
(
params
.
offset
)
>
0
:
if
hasattr
(
params
,
"offset"
)
and
len
(
params
.
offset
)
>
0
:
offset_origin
=
list
(
params
.
offset
)
offset_origin
=
list
(
params
.
offset
)
if
len
(
offset_origin
)
==
1
:
if
len
(
offset_origin
)
==
1
:
offset
=
offset_origin
*
(
len
(
input_shape
)
-
axis
)
offset
=
offset_origin
*
(
len
(
input_shape
)
-
axis
)
assert
(
len
(
input_shape
)
-
axis
assert
(
len
(
input_shape
)
-
axis
)
==
len
(
offset
),
"invalid offset[%s] in crop layer"
%
(
)
==
len
(
offset
),
"invalid offset[%s] in crop layer"
%
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录