Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
7505c65d
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看板
提交
7505c65d
编写于
7月 19, 2019
作者:
S
SunAhong1993
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
for squeezenet
上级
a829051a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
79 addition
and
11 deletion
+79
-11
x2paddle/decoder/caffe_decoder.py
x2paddle/decoder/caffe_decoder.py
+4
-4
x2paddle/decoder/caffe_shape.py
x2paddle/decoder/caffe_shape.py
+14
-3
x2paddle/op_mapper/caffe_op_mapper.py
x2paddle/op_mapper/caffe_op_mapper.py
+61
-4
未找到文件。
x2paddle/decoder/caffe_decoder.py
浏览文件 @
7505c65d
...
@@ -60,9 +60,9 @@ class CaffeResolver(object):
...
@@ -60,9 +60,9 @@ class CaffeResolver(object):
class
CaffeGraphNode
(
GraphNode
):
class
CaffeGraphNode
(
GraphNode
):
def
__init__
(
self
,
layer
,
layer_name
=
None
):
def
__init__
(
self
,
layer
,
layer_name
=
None
):
if
layer_name
is
None
:
if
layer_name
is
None
:
super
(
CaffeGraphNode
,
self
).
__init__
(
layer
,
layer
.
name
)
super
(
CaffeGraphNode
,
self
).
__init__
(
layer
,
layer
.
name
.
replace
(
'/'
,
'_'
)
)
else
:
else
:
super
(
CaffeGraphNode
,
self
).
__init__
(
layer
,
layer_name
)
super
(
CaffeGraphNode
,
self
).
__init__
(
layer
,
layer_name
.
replace
(
'/'
,
'_'
)
)
self
.
layer_type
=
layer
.
type
self
.
layer_type
=
layer
.
type
self
.
fluid_code
=
FluidCode
()
self
.
fluid_code
=
FluidCode
()
...
@@ -181,8 +181,8 @@ class CaffeGraph(Graph):
...
@@ -181,8 +181,8 @@ class CaffeGraph(Graph):
name
)
name
)
input_node
=
self
.
node_map
[
input_node_name
]
input_node
=
self
.
node_map
[
input_node_name
]
if
len
(
input_node
.
layer
.
top
)
>
1
:
if
len
(
input_node
.
layer
.
top
)
>
1
:
idx
=
list
(
input_node
.
layer
.
top
).
index
(
node
.
layer
.
bottom
[
need
])
need_idx
=
list
(
input_node
.
layer
.
top
).
index
(
node
.
layer
.
bottom
[
idx
])
name
=
input_node_name
+
':'
+
str
(
idx
)
name
=
input_node_name
+
':'
+
str
(
need_
idx
)
else
:
else
:
name
=
input_node_name
name
=
input_node_name
return
self
.
get_node
(
name
,
copy
=
copy
)
return
self
.
get_node
(
name
,
copy
=
copy
)
...
...
x2paddle/decoder/caffe_shape.py
浏览文件 @
7505c65d
...
@@ -32,8 +32,8 @@ def get_params_w_h(params):
...
@@ -32,8 +32,8 @@ def get_params_w_h(params):
if
not
isinstance
(
getattr
(
params
,
'pad'
),
int
):
if
not
isinstance
(
getattr
(
params
,
'pad'
),
int
):
if
len
(
params
.
pad
)
==
0
:
if
len
(
params
.
pad
)
==
0
:
pad_h
=
1
pad_h
=
0
pad_w
=
1
pad_w
=
0
elif
len
(
params
.
pad
)
==
1
:
elif
len
(
params
.
pad
)
==
1
:
pad_h
=
params
.
pad
[
0
]
pad_h
=
params
.
pad
[
0
]
pad_w
=
params
.
pad
[
0
]
pad_w
=
params
.
pad
[
0
]
...
@@ -101,7 +101,6 @@ def get_filter_output_shape(i_h, i_w, params, round_func):
...
@@ -101,7 +101,6 @@ def get_filter_output_shape(i_h, i_w, params, round_func):
(
kernel_h
-
1
)
+
1
))
/
float
(
stride_h
)
+
1
(
kernel_h
-
1
)
+
1
))
/
float
(
stride_h
)
+
1
o_w
=
(
i_w
+
2
*
pad_w
-
(
dila_w
*
o_w
=
(
i_w
+
2
*
pad_w
-
(
dila_w
*
(
kernel_w
-
1
)
+
1
))
/
float
(
stride_w
)
+
1
(
kernel_w
-
1
)
+
1
))
/
float
(
stride_w
)
+
1
return
(
int
(
round_func
(
o_h
)),
int
(
round_func
(
o_w
)))
return
(
int
(
round_func
(
o_h
)),
int
(
round_func
(
o_w
)))
...
@@ -111,6 +110,7 @@ def get_strided_kernel_output_shape(params, input_shape, round_func):
...
@@ -111,6 +110,7 @@ def get_strided_kernel_output_shape(params, input_shape, round_func):
round_func
)
round_func
)
has_c_o
=
hasattr
(
params
,
'num_output'
)
has_c_o
=
hasattr
(
params
,
'num_output'
)
c
=
params
.
num_output
if
has_c_o
else
input_shape
[
1
]
c
=
params
.
num_output
if
has_c_o
else
input_shape
[
1
]
return
[[
input_shape
[
0
],
c
,
o_h
,
o_w
]]
return
[[
input_shape
[
0
],
c
,
o_h
,
o_w
]]
...
@@ -168,3 +168,14 @@ def shape_softmax(layer, input_shape):
...
@@ -168,3 +168,14 @@ def shape_softmax(layer, input_shape):
def
shape_input
(
layer
,
input_shape
):
def
shape_input
(
layer
,
input_shape
):
return
[
list
(
layer
.
input_param
.
shape
[
0
].
dim
)]
return
[
list
(
layer
.
input_param
.
shape
[
0
].
dim
)]
def
shape_concat
(
layer
,
input_shape
):
params
=
layer
.
concat_param
axis
=
params
.
axis
output_shape
=
None
for
shape
in
input_shape
:
if
output_shape
is
None
:
output_shape
=
shape
else
:
output_shape
[
axis
]
+=
shape
[
axis
]
return
[
output_shape
]
\ No newline at end of file
x2paddle/op_mapper/caffe_op_mapper.py
浏览文件 @
7505c65d
...
@@ -106,11 +106,11 @@ class CaffeOpMapper(OpMapper):
...
@@ -106,11 +106,11 @@ class CaffeOpMapper(OpMapper):
raise
ValueError
(
'Unable to determine kernel parameter!'
)
raise
ValueError
(
'Unable to determine kernel parameter!'
)
return
default
return
default
def
get_kernel_parameters
(
self
,
kind
,
params
):
def
get_kernel_parameters
(
self
,
kind
,
params
,
kernel_default
=
[
1
,
1
]
):
assert
kind
in
[
'Convolution'
,
'Pooling'
,
'Deconvolution'
]
assert
kind
in
[
'Convolution'
,
'Pooling'
,
'Deconvolution'
]
k_h
=
self
.
get_kernel_value
(
params
.
kernel_h
,
params
.
kernel_size
,
0
)
k_h
=
self
.
get_kernel_value
(
params
.
kernel_h
,
params
.
kernel_size
,
0
,
kernel_default
[
0
]
)
k_w
=
self
.
get_kernel_value
(
params
.
kernel_w
,
params
.
kernel_size
,
1
)
k_w
=
self
.
get_kernel_value
(
params
.
kernel_w
,
params
.
kernel_size
,
1
,
kernel_default
[
1
]
)
s_h
=
self
.
get_kernel_value
(
params
.
stride_h
,
s_h
=
self
.
get_kernel_value
(
params
.
stride_h
,
params
.
stride
,
params
.
stride
,
0
,
0
,
...
@@ -216,8 +216,13 @@ class CaffeOpMapper(OpMapper):
...
@@ -216,8 +216,13 @@ class CaffeOpMapper(OpMapper):
def
Pooling
(
self
,
node
):
def
Pooling
(
self
,
node
):
params
=
node
.
layer
.
pooling_param
params
=
node
.
layer
.
pooling_param
shape
=
node
.
input_shape
[
0
]
global_pool
=
getattr
(
params
,
'global_pooling'
,
False
)
kernel_default
=
[
1
,
1
]
if
global_pool
:
kernel_default
=
[
shape
[
2
],
shape
[
3
]]
channel
,
kernel
,
stride
,
pad
,
dilation
,
group
=
self
.
get_kernel_parameters
(
channel
,
kernel
,
stride
,
pad
,
dilation
,
group
=
self
.
get_kernel_parameters
(
node
.
layer_type
,
params
)
node
.
layer_type
,
params
,
kernel_default
=
kernel_default
)
if
params
.
pool
==
0
:
if
params
.
pool
==
0
:
pool_type
=
'max'
pool_type
=
'max'
else
:
else
:
...
@@ -348,3 +353,55 @@ class CaffeOpMapper(OpMapper):
...
@@ -348,3 +353,55 @@ class CaffeOpMapper(OpMapper):
inputs
=
node
,
inputs
=
node
,
output
=
node
,
output
=
node
,
param_attr
=
attr
)
param_attr
=
attr
)
def
Slice
(
self
,
node
):
assert
len
(
node
.
inputs
)
==
1
,
'The count of Slice node
\'
s input is not 1.'
input
=
self
.
graph
.
get_bottom_node
(
node
,
idx
=
0
,
copy
=
True
)
params
=
node
.
layer
.
slice_param
axis
=
params
.
axis
points
=
list
(
params
.
slice_point
)
shape
=
node
.
input_shape
[
0
]
count
=
shape
[
axis
]
sections
=
[]
idx
=
0
for
p
in
points
:
if
idx
==
0
:
sections
.
append
(
p
-
0
)
elif
idx
==
len
(
points
)
-
1
:
sections
.
append
(
count
-
p
)
else
:
sections
.
append
(
points
[
idx
+
1
]
-
p
)
idx
+=
1
attr
=
{
'dim'
:
axis
,
'num_or_sections'
:
sections
,
'name'
:
string
(
node
.
layer_name
+
'_slice'
)
}
node
.
fluid_code
.
add_layer
(
"split"
,
inputs
=
input
,
output
=
node
,
param_attr
=
attr
)
def
Concat
(
self
,
node
):
assert
len
(
node
.
inputs
)
>
1
,
'The count of Concat node
\'
s input is not more than 1.'
inputs
=
[]
for
i
in
range
(
len
(
node
.
inputs
)):
input
=
self
.
graph
.
get_bottom_node
(
node
,
idx
=
i
,
copy
=
True
)
inputs
.
append
(
input
)
params
=
node
.
layer
.
concat_param
axis
=
params
.
axis
attr
=
{
'axis'
:
axis
,
'name'
:
string
(
node
.
layer_name
+
'_concat'
)
}
node
.
fluid_code
.
add_layer
(
"concat"
,
inputs
=
inputs
,
output
=
node
,
param_attr
=
attr
)
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录