Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
48244d82
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看板
未验证
提交
48244d82
编写于
9月 05, 2019
作者:
J
Jason
提交者:
GitHub
9月 05, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4 from PaddlePaddle/develop
pull
上级
65565c48
4e087fd6
变更
17
展开全部
隐藏空白更改
内联
并排
Showing
17 changed file
with
13194 addition
and
7499 deletion
+13194
-7499
FAQ.md
FAQ.md
+1
-1
add_caffe_custom_layer.md
add_caffe_custom_layer.md
+17
-17
caffe_custom_layer.md
caffe_custom_layer.md
+0
-2
export_tf_model.md
export_tf_model.md
+1
-1
scripts/check_code_style.sh
scripts/check_code_style.sh
+0
-1
x2paddle/convert.py
x2paddle/convert.py
+3
-2
x2paddle/core/fluid_code.py
x2paddle/core/fluid_code.py
+6
-5
x2paddle/core/graph.py
x2paddle/core/graph.py
+2
-0
x2paddle/core/op_mapper.py
x2paddle/core/op_mapper.py
+23
-0
x2paddle/core/util.py
x2paddle/core/util.py
+0
-24
x2paddle/decoder/caffe_decoder.py
x2paddle/decoder/caffe_decoder.py
+0
-4
x2paddle/decoder/caffe_pb2.py
x2paddle/decoder/caffe_pb2.py
+13084
-7413
x2paddle/op_mapper/caffe_custom_layer/normalize.py
x2paddle/op_mapper/caffe_custom_layer/normalize.py
+2
-0
x2paddle/op_mapper/caffe_op_mapper.py
x2paddle/op_mapper/caffe_op_mapper.py
+51
-25
x2paddle/op_mapper/caffe_shape.py
x2paddle/op_mapper/caffe_shape.py
+2
-1
x2paddle/op_mapper/onnx_op_mapper.py
x2paddle/op_mapper/onnx_op_mapper.py
+1
-1
x2paddle_model_zoo.md
x2paddle_model_zoo.md
+1
-2
未找到文件。
FAQ.md
浏览文件 @
48244d82
## 常见问题
## 常见问题
**Q1. TensorFlow模型转换过程中,提示『Unknown shape for input tensor[tensor name: "input"], Please define shape of input here』?**
**Q1. TensorFlow模型转换过程中,提示『Unknown shape for input tensor[tensor name: "input"], Please define shape of input here』?**
A:该提示信息表示无法从TensorFlow的pb模型中获取到输入tensor(tensor名为"input:)的shape信息,所以需要用户手动在提示后输入详细的shape信息,如None,224,224,3 其中None表示Batch
A:该提示信息表示无法从TensorFlow的pb模型中获取到输入tensor(tensor名为"input:)的shape信息,所以需要用户手动在提示后输入详细的shape信息,如None,224,224,3 其中None表示Batch
**Q2. TensorFlow模型转换失败怎么解决?**
**Q2. TensorFlow模型转换失败怎么解决?**
...
...
add_caffe_custom_layer.md
浏览文件 @
48244d82
## 如何转换Caffe自定义Layer
## 如何转换Caffe自定义Layer
本文档介绍如何将Caffe自定义Layer转换为PaddlePaddle模型中的对应实现, 用户可根据自己需要,添加代码实现自定义层,从而支持模型的完整转换。
本文档介绍如何将Caffe自定义Layer转换为PaddlePaddle模型中的对应实现, 用户可根据自己需要,添加代码实现自定义层,从而支持模型的完整转换。
***步骤一 下载代码**
*
***步骤一 下载代码**
*
此处涉及修改源码,应先卸载x2paddle,并且下载源码,主要有以下两步完成:
此处涉及修改源码,应先卸载x2paddle,并且下载源码,主要有以下两步完成:
```
```
pip uninstall x2paddle
pip uninstall x2paddle
pip install git+https://github.com/PaddlePaddle/X2Paddle.git@develop
pip install git+https://github.com/PaddlePaddle/X2Paddle.git@develop
```
```
***步骤二 编译caffe.proto**
*
***步骤二 编译caffe.proto**
*
该步骤依赖protobuf编译器,其安装过程有以下两种方式:
该步骤依赖protobuf编译器,其安装过程有以下两种方式:
> 选择一:pip install protobuf
> 选择一:pip install protobuf
> 选择二:使用[官方源码](https://github.com/protocolbuffers/protobuf)进行编译
> 选择二:使用[官方源码](https://github.com/protocolbuffers/protobuf)进行编译
使用脚本./tools/compile.sh将caffe.proto(包含所需的自定义Layer信息)编译成我们所需的目标语言(Python)
使用脚本./tools/compile.sh将caffe.proto(包含所需的自定义Layer信息)编译成我们所需的目标语言(Python)
使用方式:
使用方式:
```
```
bash ./toos/compile.sh /home/root/caffe/src/caffe/proto
bash ./toos/compile.sh /home/root/caffe/src/caffe/proto
...
@@ -25,14 +25,14 @@ bash ./toos/compile.sh /home/root/caffe/src/caffe/proto
...
@@ -25,14 +25,14 @@ bash ./toos/compile.sh /home/root/caffe/src/caffe/proto
-
仿照./x2paddle/op_mapper/caffe_custom_layer中的其他文件,在mylayer.py中主要需要实现3个函数,下面以roipooling.py为例分析代码:
-
仿照./x2paddle/op_mapper/caffe_custom_layer中的其他文件,在mylayer.py中主要需要实现3个函数,下面以roipooling.py为例分析代码:
1.
`def roipooling_shape(input_shape, pooled_w=None, pooled_h=None)`
1.
`def roipooling_shape(input_shape, pooled_w=None, pooled_h=None)`
参数:
参数:
1.
input_shape(list):其中每个元素代表该层每个输入数据的shape,为必须传入的参数
1.
input_shape(list):其中每个元素代表该层每个输入数据的shape,为必须传入的参数
2.
pooled_w(int):代表ROI Pooling的kernel的宽,其命名与.prototxt中roi_pooling_param中的key一致
2.
pooled_w(int):代表ROI Pooling的kernel的宽,其命名与.prototxt中roi_pooling_param中的key一致
3.
pooled_h(int):代表ROI Pooling的kernel的高,其命名与.prototxt中roi_pooling_param中的key一致
3.
pooled_h(int):代表ROI Pooling的kernel的高,其命名与.prototxt中roi_pooling_param中的key一致
功能:计算出进行ROI Pooling后的shape
功能:计算出进行ROI Pooling后的shape
返回:一个list,其中每个元素代表每个输出数据的shape,由于ROI Pooling的输出数据只有一个,所以其list长度为1
返回:一个list,其中每个元素代表每个输出数据的shape,由于ROI Pooling的输出数据只有一个,所以其list长度为1
2.
`def roipooling_layer(inputs, input_shape=None, name=None, pooled_w=None, pooled_h=None, spatial_scale=None)`
2.
`def roipooling_layer(inputs, input_shape=None, name=None, pooled_w=None, pooled_h=None, spatial_scale=None)`
参数:
参数:
1. inputs(list):其中每个元素代表该层每个输入数据,为必须传入的参数
1. inputs(list):其中每个元素代表该层每个输入数据,为必须传入的参数
...
@@ -40,9 +40,9 @@ bash ./toos/compile.sh /home/root/caffe/src/caffe/proto
...
@@ -40,9 +40,9 @@ bash ./toos/compile.sh /home/root/caffe/src/caffe/proto
3. name(str):ROI Pooling层的名字,为必须传入的参数
3. name(str):ROI Pooling层的名字,为必须传入的参数
4. pooled_w(int):代表ROI Pooling的kernel的宽,其命名与.prototxt中roi_pooling_param中的key一致
4. pooled_w(int):代表ROI Pooling的kernel的宽,其命名与.prototxt中roi_pooling_param中的key一致
5. pooled_h(int):代表ROI Pooling的kernel的高,其命名与.prototxt中roi_pooling_param中的key一致
5. pooled_h(int):代表ROI Pooling的kernel的高,其命名与.prototxt中roi_pooling_param中的key一致
6. spatial_scale(float):用于将ROI坐标从输入比例转换为池化时使用的比例,其命名与.prototxt中roi_pooling_param中的key一致
6. spatial_scale(float):用于将ROI坐标从输入比例转换为池化时使用的比例,其命名与.prototxt中roi_pooling_param中的key一致
功能:运用PaddlePaddle完成组网来实现`roipooling_layer`的功能
功能:运用PaddlePaddle完成组网来实现`roipooling_layer`的功能
返回:一个Variable,为组网后的结果
返回:一个Variable,为组网后的结果
3.
`def roipooling_weights(name, data=None)`
3.
`def roipooling_weights(name, data=None)`
...
@@ -51,7 +51,7 @@ bash ./toos/compile.sh /home/root/caffe/src/caffe/proto
...
@@ -51,7 +51,7 @@ bash ./toos/compile.sh /home/root/caffe/src/caffe/proto
1. name(str):ROI Pooling层的名字,为必须传入的参数
1. name(str):ROI Pooling层的名字,为必须传入的参数
2. data(list):由Caffe模型.caffemodel获得的关于roipooling的参数,roipooling的参数为None
2. data(list):由Caffe模型.caffemodel获得的关于roipooling的参数,roipooling的参数为None
功能:为每个参数(例如kernel、bias等)命名;同时,若Caffe中该层参数与PaddlePaddle中参数的格式不一致,则变换操作也在该函数中实现。
功能:为每个参数(例如kernel、bias等)命名;同时,若Caffe中该层参数与PaddlePaddle中参数的格式不一致,则变换操作也在该函数中实现。
返回:一个list,包含每个参数的名字。
返回:一个list,包含每个参数的名字。
-
在roipooling.py中注册
`roipooling`
,主要运用下述代码实现:
-
在roipooling.py中注册
`roipooling`
,主要运用下述代码实现:
...
@@ -70,9 +70,9 @@ bash ./toos/compile.sh /home/root/caffe/src/caffe/proto
...
@@ -70,9 +70,9 @@ bash ./toos/compile.sh /home/root/caffe/src/caffe/proto
# 在X2Paddle目录下安装x2paddle
# 在X2Paddle目录下安装x2paddle
python setup.py install
python setup.py install
# 运行转换代码
# 运行转换代码
x2paddle --framework=caffe
x2paddle --framework=caffe
--prototxt=deploy.proto
--prototxt=deploy.proto
--weight=deploy.caffemodel
--weight=deploy.caffemodel
--save_dir=pd_model
--save_dir=pd_model
--caffe_proto=/home/root/caffe/src/caffe/proto/caffe_pb2.py
--caffe_proto=/home/root/caffe/src/caffe/proto/caffe_pb2.py
```
```
caffe_custom_layer.md
浏览文件 @
48244d82
...
@@ -10,5 +10,3 @@
...
@@ -10,5 +10,3 @@
| Normalize |
[
code
](
https://github.com/weiliu89/caffe/blob/ssd/src/caffe/layers/normalize_layer.cpp
)
|
| Normalize |
[
code
](
https://github.com/weiliu89/caffe/blob/ssd/src/caffe/layers/normalize_layer.cpp
)
|
| ROIPooling |
[
code
](
https://github.com/rbgirshick/caffe-fast-rcnn/blob/0dcd397b29507b8314e252e850518c5695efbb83/src/caffe/layers/roi_pooling_layer.cpp
)
|
| ROIPooling |
[
code
](
https://github.com/rbgirshick/caffe-fast-rcnn/blob/0dcd397b29507b8314e252e850518c5695efbb83/src/caffe/layers/roi_pooling_layer.cpp
)
|
| Axpy |
[
code
](
https://github.com/hujie-frank/SENet/blob/master/src/caffe/layers/axpy_layer.cpp
)
|
| Axpy |
[
code
](
https://github.com/hujie-frank/SENet/blob/master/src/caffe/layers/axpy_layer.cpp
)
|
export_tf_model.md
浏览文件 @
48244d82
...
@@ -28,7 +28,7 @@ def freeze_model(sess, output_tensor_names, freeze_model_path):
...
@@ -28,7 +28,7 @@ def freeze_model(sess, output_tensor_names, freeze_model_path):
f.write(out_graph.SerializeToString())
f.write(out_graph.SerializeToString())
print("freeze model saved in {}".format(freeze_model_path))
print("freeze model saved in {}".format(freeze_model_path))
# 加载模型参数
# 加载模型参数
sess = tf.Session()
sess = tf.Session()
inputs = tf.placeholder(dtype=tf.float32,
inputs = tf.placeholder(dtype=tf.float32,
...
...
scripts/check_code_style.sh
浏览文件 @
48244d82
...
@@ -7,7 +7,6 @@ function abort(){
...
@@ -7,7 +7,6 @@ function abort(){
trap
'abort'
0
trap
'abort'
0
set
-e
set
-e
cd
$TRAVIS_BUILD_DIR
cd
$TRAVIS_BUILD_DIR
export
PATH
=
/usr/bin:
$PATH
export
PATH
=
/usr/bin:
$PATH
pre-commit
install
pre-commit
install
...
...
x2paddle/convert.py
浏览文件 @
48244d82
...
@@ -179,6 +179,9 @@ def main():
...
@@ -179,6 +179,9 @@ def main():
x2paddle
.
__version__
))
x2paddle
.
__version__
))
return
return
assert
args
.
framework
is
not
None
,
"--framework is not defined(support tensorflow/caffe/onnx)"
assert
args
.
save_dir
is
not
None
,
"--save_dir is not defined"
try
:
try
:
import
paddle
import
paddle
v0
,
v1
,
v2
=
paddle
.
__version__
.
split
(
'.'
)
v0
,
v1
,
v2
=
paddle
.
__version__
.
split
(
'.'
)
...
@@ -187,8 +190,6 @@ def main():
...
@@ -187,8 +190,6 @@ def main():
return
return
except
:
except
:
print
(
"paddlepaddle not installed, use
\"
pip install paddlepaddle
\"
"
)
print
(
"paddlepaddle not installed, use
\"
pip install paddlepaddle
\"
"
)
assert
args
.
framework
is
not
None
,
"--framework is not defined(support tensorflow/caffe/onnx)"
assert
args
.
save_dir
is
not
None
,
"--save_dir is not defined"
if
args
.
framework
==
"tensorflow"
:
if
args
.
framework
==
"tensorflow"
:
assert
args
.
model
is
not
None
,
"--model should be defined while translating tensorflow model"
assert
args
.
model
is
not
None
,
"--model should be defined while translating tensorflow model"
...
...
x2paddle/core/fluid_code.py
浏览文件 @
48244d82
...
@@ -13,8 +13,9 @@
...
@@ -13,8 +13,9 @@
# limitations under the License.
# limitations under the License.
from
x2paddle.core.graph
import
GraphNode
from
x2paddle.core.graph
import
GraphNode
import
collections
from
x2paddle.core.util
import
*
from
x2paddle.core.util
import
*
import
collections
import
six
class
Layer
(
object
):
class
Layer
(
object
):
...
@@ -28,7 +29,7 @@ class Layer(object):
...
@@ -28,7 +29,7 @@ class Layer(object):
def
get_code
(
self
):
def
get_code
(
self
):
layer_code
=
""
layer_code
=
""
if
self
.
output
is
not
None
:
if
self
.
output
is
not
None
:
if
isinstance
(
self
.
output
,
s
tr
):
if
isinstance
(
self
.
output
,
s
ix
.
string_types
):
layer_code
=
self
.
output
+
" = "
layer_code
=
self
.
output
+
" = "
else
:
else
:
layer_code
=
self
.
output
.
layer_name
+
" = "
layer_code
=
self
.
output
.
layer_name
+
" = "
...
@@ -47,7 +48,7 @@ class Layer(object):
...
@@ -47,7 +48,7 @@ class Layer(object):
"[{}]"
.
format
(
input
.
index
)
+
", "
)
"[{}]"
.
format
(
input
.
index
)
+
", "
)
else
:
else
:
in_list
+=
(
input
.
layer_name
+
", "
)
in_list
+=
(
input
.
layer_name
+
", "
)
elif
isinstance
(
input
,
s
tr
):
elif
isinstance
(
input
,
s
ix
.
string_types
):
in_list
+=
(
input
+
", "
)
in_list
+=
(
input
+
", "
)
else
:
else
:
raise
Exception
(
raise
Exception
(
...
@@ -72,7 +73,7 @@ class Layer(object):
...
@@ -72,7 +73,7 @@ class Layer(object):
"[{}]"
.
format
(
self
.
inputs
.
index
)
+
", "
)
"[{}]"
.
format
(
self
.
inputs
.
index
)
+
", "
)
else
:
else
:
layer_code
+=
(
self
.
inputs
.
layer_name
+
", "
)
layer_code
+=
(
self
.
inputs
.
layer_name
+
", "
)
elif
isinstance
(
self
.
inputs
,
s
tr
):
elif
isinstance
(
self
.
inputs
,
s
ix
.
string_types
):
layer_code
+=
(
self
.
inputs
+
", "
)
layer_code
+=
(
self
.
inputs
+
", "
)
else
:
else
:
raise
Exception
(
"Unknown type of inputs."
)
raise
Exception
(
"Unknown type of inputs."
)
...
@@ -119,6 +120,6 @@ class FluidCode(object):
...
@@ -119,6 +120,6 @@ class FluidCode(object):
for
layer
in
self
.
layers
:
for
layer
in
self
.
layers
:
if
isinstance
(
layer
,
Layer
):
if
isinstance
(
layer
,
Layer
):
codes
.
append
(
layer
.
get_code
())
codes
.
append
(
layer
.
get_code
())
elif
isinstance
(
layer
,
s
tr
):
elif
isinstance
(
layer
,
s
ix
.
string_types
):
codes
.
append
(
layer
)
codes
.
append
(
layer
)
return
codes
return
codes
x2paddle/core/graph.py
浏览文件 @
48244d82
...
@@ -12,6 +12,8 @@
...
@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
from
__future__
import
print_function
from
__future__
import
division
import
collections
import
collections
import
copy
as
cp
import
copy
as
cp
...
...
x2paddle/core/op_mapper.py
浏览文件 @
48244d82
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
import
paddle.fluid
as
fluid
from
paddle.fluid.proto
import
framework_pb2
from
paddle.fluid.proto
import
framework_pb2
from
x2paddle.core.util
import
*
from
x2paddle.core.util
import
*
import
inspect
import
inspect
...
@@ -46,6 +47,28 @@ def export_paddle_param(param, param_name, dir):
...
@@ -46,6 +47,28 @@ def export_paddle_param(param, param_name, dir):
fp
.
close
()
fp
.
close
()
# This func will copy to generate code file
def
run_net
(
param_dir
=
"./"
):
import
os
inputs
,
outputs
=
x2paddle_net
()
for
i
,
out
in
enumerate
(
outputs
):
if
isinstance
(
out
,
list
):
for
out_part
in
out
:
outputs
.
append
(
out_part
)
del
outputs
[
i
]
exe
=
fluid
.
Executor
(
fluid
.
CPUPlace
())
exe
.
run
(
fluid
.
default_startup_program
())
def
if_exist
(
var
):
b
=
os
.
path
.
exists
(
os
.
path
.
join
(
param_dir
,
var
.
name
))
return
b
fluid
.
io
.
load_vars
(
exe
,
param_dir
,
fluid
.
default_main_program
(),
predicate
=
if_exist
)
class
OpMapper
(
object
):
class
OpMapper
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
paddle_codes
=
""
self
.
paddle_codes
=
""
...
...
x2paddle/core/util.py
浏览文件 @
48244d82
...
@@ -11,8 +11,6 @@
...
@@ -11,8 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
import
paddle.fluid
as
fluid
import
numpy
import
numpy
import
math
import
math
import
os
import
os
...
@@ -20,25 +18,3 @@ import os
...
@@ -20,25 +18,3 @@ import os
def
string
(
param
):
def
string
(
param
):
return
"
\'
{}
\'
"
.
format
(
param
)
return
"
\'
{}
\'
"
.
format
(
param
)
# This func will copy to generate code file
def
run_net
(
param_dir
=
"./"
):
import
os
inputs
,
outputs
=
x2paddle_net
()
for
i
,
out
in
enumerate
(
outputs
):
if
isinstance
(
out
,
list
):
for
out_part
in
out
:
outputs
.
append
(
out_part
)
del
outputs
[
i
]
exe
=
fluid
.
Executor
(
fluid
.
CPUPlace
())
exe
.
run
(
fluid
.
default_startup_program
())
def
if_exist
(
var
):
b
=
os
.
path
.
exists
(
os
.
path
.
join
(
param_dir
,
var
.
name
))
return
b
fluid
.
io
.
load_vars
(
exe
,
param_dir
,
fluid
.
default_main_program
(),
predicate
=
if_exist
)
x2paddle/decoder/caffe_decoder.py
浏览文件 @
48244d82
...
@@ -236,11 +236,7 @@ class CaffeDecoder(object):
...
@@ -236,11 +236,7 @@ class CaffeDecoder(object):
data
.
MergeFromString
(
open
(
self
.
model_path
,
'rb'
).
read
())
data
.
MergeFromString
(
open
(
self
.
model_path
,
'rb'
).
read
())
pair
=
lambda
layer
:
(
layer
.
name
,
self
.
normalize_pb_data
(
layer
))
pair
=
lambda
layer
:
(
layer
.
name
,
self
.
normalize_pb_data
(
layer
))
layers
=
data
.
layers
or
data
.
layer
layers
=
data
.
layers
or
data
.
layer
import
time
start
=
time
.
time
()
self
.
params
=
[
pair
(
layer
)
for
layer
in
layers
if
layer
.
blobs
]
self
.
params
=
[
pair
(
layer
)
for
layer
in
layers
if
layer
.
blobs
]
end
=
time
.
time
()
print
(
'cost:'
,
str
(
end
-
start
))
def
normalize_pb_data
(
self
,
layer
):
def
normalize_pb_data
(
self
,
layer
):
transformed
=
[]
transformed
=
[]
...
...
x2paddle/decoder/caffe_pb2.py
浏览文件 @
48244d82
此差异已折叠。
点击以展开。
x2paddle/op_mapper/caffe_custom_layer/normalize.py
浏览文件 @
48244d82
...
@@ -18,6 +18,8 @@ def normalize_layer(inputs,
...
@@ -18,6 +18,8 @@ def normalize_layer(inputs,
shape
=
[
1
]
if
channel_shared
else
[
input_shape
[
0
][
1
]],
shape
=
[
1
]
if
channel_shared
else
[
input_shape
[
0
][
1
]],
dtype
=
input
.
dtype
,
dtype
=
input
.
dtype
,
attr
=
name
+
'_scale'
)
attr
=
name
+
'_scale'
)
scale_param
=
fluid
.
layers
.
reshape
(
x
=
scale_param
,
\
shape
=
[
1
]
if
channel_shared
else
[
input_shape
[
0
][
1
]])
out
=
fluid
.
layers
.
elementwise_mul
(
x
=
l2_norm
,
out
=
fluid
.
layers
.
elementwise_mul
(
x
=
l2_norm
,
y
=
scale_param
,
y
=
scale_param
,
axis
=-
1
if
channel_shared
else
1
)
axis
=-
1
if
channel_shared
else
1
)
...
...
x2paddle/op_mapper/caffe_op_mapper.py
浏览文件 @
48244d82
...
@@ -135,7 +135,8 @@ class CaffeOpMapper(OpMapper):
...
@@ -135,7 +135,8 @@ class CaffeOpMapper(OpMapper):
if
isinstance
(
params
.
kernel_size
,
numbers
.
Number
):
if
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
:
elif
params
.
kernel_h
>
0
or
params
.
kernel_w
>
0
:
...
@@ -156,8 +157,8 @@ class CaffeOpMapper(OpMapper):
...
@@ -156,8 +157,8 @@ class CaffeOpMapper(OpMapper):
[
p_h
,
p_w
]
=
[
params
.
pad
]
*
2
[
p_h
,
p_w
]
=
[
params
.
pad
]
*
2
elif
len
(
params
.
pad
)
>
0
:
elif
len
(
params
.
pad
)
>
0
:
p_h
=
params
.
pad_h
if
params
.
pad_h
>
0
else
params
.
pad
[
0
]
p_h
=
params
.
pad_h
if
params
.
pad_h
>
0
else
params
.
pad
[
0
]
p_w
=
params
.
pad_w
if
params
.
pad_w
>
0
else
params
.
pad
[
len
(
params
.
pad
)
-
p_w
=
params
.
pad_w
if
params
.
pad_w
>
0
else
params
.
pad
[
1
]
len
(
params
.
pad
)
-
1
]
elif
params
.
pad_h
>
0
or
params
.
pad_w
>
0
:
elif
params
.
pad_h
>
0
or
params
.
pad_w
>
0
:
p_h
=
params
.
pad_h
p_h
=
params
.
pad_h
p_w
=
params
.
pad_w
p_w
=
params
.
pad_w
...
@@ -225,12 +226,17 @@ class CaffeOpMapper(OpMapper):
...
@@ -225,12 +226,17 @@ class CaffeOpMapper(OpMapper):
node
.
layer_type
,
params
)
node
.
layer_type
,
params
)
if
data
is
None
:
if
data
is
None
:
data
=
[]
data
=
[]
print
(
'The parameter of {} (type is {}) is not set. So we set the parameters as 0'
.
format
(
print
(
node
.
layer_name
,
node
.
layer_type
))
'The parameter of {} (type is {}) is not set. So we set the parameters as 0'
.
format
(
node
.
layer_name
,
node
.
layer_type
))
input_c
=
node
.
input_shape
[
0
][
1
]
input_c
=
node
.
input_shape
[
0
][
1
]
output_c
=
channel
output_c
=
channel
data
.
append
(
np
.
zeros
([
output_c
,
input_c
,
kernel
[
0
],
kernel
[
1
]]).
astype
(
'float32'
))
data
.
append
(
data
.
append
(
np
.
zeros
([
output_c
,])).
astype
(
'float32'
)
np
.
zeros
([
output_c
,
input_c
,
kernel
[
0
],
kernel
[
1
]]).
astype
(
'float32'
))
data
.
append
(
np
.
zeros
([
output_c
,
])).
astype
(
'float32'
)
else
:
else
:
data
=
self
.
adjust_parameters
(
node
)
data
=
self
.
adjust_parameters
(
node
)
self
.
weights
[
node
.
layer_name
+
'_weights'
]
=
data
[
0
]
self
.
weights
[
node
.
layer_name
+
'_weights'
]
=
data
[
0
]
...
@@ -272,12 +278,17 @@ class CaffeOpMapper(OpMapper):
...
@@ -272,12 +278,17 @@ class CaffeOpMapper(OpMapper):
node
.
layer_type
,
params
)
node
.
layer_type
,
params
)
if
data
is
None
:
if
data
is
None
:
data
=
[]
data
=
[]
print
(
'The parameter of {} (type is {}) is not set. So we set the parameters as 0'
.
format
(
print
(
node
.
layer_name
,
node
.
layer_type
))
'The parameter of {} (type is {}) is not set. So we set the parameters as 0'
.
format
(
node
.
layer_name
,
node
.
layer_type
))
input_c
=
node
.
input_shape
[
0
][
1
]
input_c
=
node
.
input_shape
[
0
][
1
]
output_c
=
channel
output_c
=
channel
data
.
append
(
np
.
zeros
([
output_c
,
input_c
,
kernel
[
0
],
kernel
[
1
]]).
astype
(
'float32'
))
data
.
append
(
data
.
append
(
np
.
zeros
([
output_c
,]).
astype
(
'float32'
))
np
.
zeros
([
output_c
,
input_c
,
kernel
[
0
],
kernel
[
1
]]).
astype
(
'float32'
))
data
.
append
(
np
.
zeros
([
output_c
,
]).
astype
(
'float32'
))
else
:
else
:
data
=
self
.
adjust_parameters
(
node
)
data
=
self
.
adjust_parameters
(
node
)
self
.
weights
[
node
.
layer_name
+
'_weights'
]
=
data
[
0
]
self
.
weights
[
node
.
layer_name
+
'_weights'
]
=
data
[
0
]
...
@@ -369,13 +380,17 @@ class CaffeOpMapper(OpMapper):
...
@@ -369,13 +380,17 @@ class CaffeOpMapper(OpMapper):
data
=
node
.
data
data
=
node
.
data
params
=
node
.
layer
.
inner_product_param
params
=
node
.
layer
.
inner_product_param
if
data
is
None
:
if
data
is
None
:
print
(
'The parameter of {} (type is {}) is not set. So we set the parameters as 0.'
.
format
(
print
(
node
.
layer_name
,
node
.
layer_type
))
'The parameter of {} (type is {}) is not set. So we set the parameters as 0.'
.
format
(
node
.
layer_name
,
node
.
layer_type
))
input_c
=
node
.
input_shape
[
0
][
1
]
input_c
=
node
.
input_shape
[
0
][
1
]
output_c
=
params
.
num_output
output_c
=
params
.
num_output
data
=
[]
data
=
[]
data
.
append
(
np
.
zeros
([
input_c
,
output_c
]).
astype
(
'float32'
).
astype
(
'float32'
))
data
.
append
(
data
.
append
(
np
.
zeros
([
output_c
]).
astype
(
'float32'
).
astype
(
'float32'
))
np
.
zeros
([
input_c
,
output_c
]).
astype
(
'float32'
).
astype
(
'float32'
))
data
.
append
(
np
.
zeros
([
output_c
]).
astype
(
'float32'
).
astype
(
'float32'
))
else
:
else
:
data
=
self
.
adjust_parameters
(
node
)
data
=
self
.
adjust_parameters
(
node
)
# Reshape the parameters to Paddle's ordering
# Reshape the parameters to Paddle's ordering
...
@@ -467,7 +482,7 @@ class CaffeOpMapper(OpMapper):
...
@@ -467,7 +482,7 @@ class CaffeOpMapper(OpMapper):
node
.
layer_name
,
node
.
layer_name
+
'_'
+
str
(
i
)))
node
.
layer_name
,
node
.
layer_name
+
'_'
+
str
(
i
)))
if
i
==
len
(
points
)
-
2
:
if
i
==
len
(
points
)
-
2
:
break
break
def
Concat
(
self
,
node
):
def
Concat
(
self
,
node
):
assert
len
(
assert
len
(
node
.
inputs
node
.
inputs
...
@@ -616,7 +631,8 @@ class CaffeOpMapper(OpMapper):
...
@@ -616,7 +631,8 @@ class CaffeOpMapper(OpMapper):
param_attr
=
attr
)
param_attr
=
attr
)
def
BatchNorm
(
self
,
node
):
def
BatchNorm
(
self
,
node
):
assert
len
(
node
.
inputs
)
==
1
,
'The count of BatchNorm node
\'
s input is not 1.'
assert
len
(
node
.
inputs
)
==
1
,
'The count of BatchNorm node
\'
s input is not 1.'
input
=
self
.
graph
.
get_bottom_node
(
node
,
idx
=
0
,
copy
=
True
)
input
=
self
.
graph
.
get_bottom_node
(
node
,
idx
=
0
,
copy
=
True
)
params
=
node
.
layer
.
batch_norm_param
params
=
node
.
layer
.
batch_norm_param
if
hasattr
(
params
,
'eps'
):
if
hasattr
(
params
,
'eps'
):
...
@@ -624,11 +640,16 @@ class CaffeOpMapper(OpMapper):
...
@@ -624,11 +640,16 @@ class CaffeOpMapper(OpMapper):
else
:
else
:
eps
=
1e-5
eps
=
1e-5
if
node
.
data
is
None
or
len
(
node
.
data
)
!=
3
:
if
node
.
data
is
None
or
len
(
node
.
data
)
!=
3
:
print
(
'The parameter of {} (type is {}) is not set. So we set the parameters as 0'
.
format
(
print
(
node
.
layer_name
,
node
.
layer_type
))
'The parameter of {} (type is {}) is not set. So we set the parameters as 0'
.
format
(
node
.
layer_name
,
node
.
layer_type
))
input_c
=
node
.
input_shape
[
0
][
1
]
input_c
=
node
.
input_shape
[
0
][
1
]
mean
=
np
.
zeros
([
input_c
,]).
astype
(
'float32'
)
mean
=
np
.
zeros
([
variance
=
np
.
zeros
([
input_c
,]).
astype
(
'float32'
)
input_c
,
]).
astype
(
'float32'
)
variance
=
np
.
zeros
([
input_c
,
]).
astype
(
'float32'
)
scale
=
0
scale
=
0
else
:
else
:
node
.
data
=
[
np
.
squeeze
(
i
)
for
i
in
node
.
data
]
node
.
data
=
[
np
.
squeeze
(
i
)
for
i
in
node
.
data
]
...
@@ -655,11 +676,16 @@ class CaffeOpMapper(OpMapper):
...
@@ -655,11 +676,16 @@ class CaffeOpMapper(OpMapper):
def
Scale
(
self
,
node
):
def
Scale
(
self
,
node
):
if
node
.
data
is
None
:
if
node
.
data
is
None
:
print
(
'The parameter of {} (type is {}) is not set. So we set the parameters as 0'
.
format
(
print
(
node
.
layer_name
,
node
.
layer_type
))
'The parameter of {} (type is {}) is not set. So we set the parameters as 0'
.
format
(
node
.
layer_name
,
node
.
layer_type
))
input_c
=
node
.
input_shape
[
0
][
1
]
input_c
=
node
.
input_shape
[
0
][
1
]
self
.
weights
[
node
.
layer_name
+
'_scale'
]
=
np
.
zeros
([
input_c
,]).
astype
(
'float32'
)
self
.
weights
[
node
.
layer_name
+
'_scale'
]
=
np
.
zeros
([
self
.
weights
[
node
.
layer_name
+
'_offset'
]
=
np
.
zeros
([
input_c
,]).
astype
(
'float32'
)
input_c
,
]).
astype
(
'float32'
)
self
.
weights
[
node
.
layer_name
+
'_offset'
]
=
np
.
zeros
([
input_c
,
]).
astype
(
'float32'
)
else
:
else
:
self
.
weights
[
node
.
layer_name
+
'_scale'
]
=
np
.
squeeze
(
node
.
data
[
0
])
self
.
weights
[
node
.
layer_name
+
'_scale'
]
=
np
.
squeeze
(
node
.
data
[
0
])
self
.
weights
[
node
.
layer_name
+
'_offset'
]
=
np
.
squeeze
(
node
.
data
[
1
])
self
.
weights
[
node
.
layer_name
+
'_offset'
]
=
np
.
squeeze
(
node
.
data
[
1
])
...
...
x2paddle/op_mapper/caffe_shape.py
浏览文件 @
48244d82
...
@@ -43,7 +43,8 @@ def get_kernel_parameters(params):
...
@@ -43,7 +43,8 @@ def get_kernel_parameters(params):
[
p_h
,
p_w
]
=
[
params
.
pad
]
*
2
[
p_h
,
p_w
]
=
[
params
.
pad
]
*
2
elif
len
(
params
.
pad
)
>
0
:
elif
len
(
params
.
pad
)
>
0
:
p_h
=
params
.
pad_h
if
params
.
pad_h
>
0
else
params
.
pad
[
0
]
p_h
=
params
.
pad_h
if
params
.
pad_h
>
0
else
params
.
pad
[
0
]
p_w
=
params
.
pad_w
if
params
.
pad_w
>
0
else
params
.
pad
[
len
(
params
.
pad
)
-
1
]
p_w
=
params
.
pad_w
if
params
.
pad_w
>
0
else
params
.
pad
[
len
(
params
.
pad
)
-
1
]
elif
params
.
pad_h
>
0
or
params
.
pad_w
>
0
:
elif
params
.
pad_h
>
0
or
params
.
pad_w
>
0
:
p_h
=
params
.
pad_h
p_h
=
params
.
pad_h
p_w
=
params
.
pad_w
p_w
=
params
.
pad_w
...
...
x2paddle/op_mapper/onnx_op_mapper.py
浏览文件 @
48244d82
...
@@ -94,7 +94,7 @@ class ONNXOpMapper(OpMapper):
...
@@ -94,7 +94,7 @@ class ONNXOpMapper(OpMapper):
print
(
op
)
print
(
op
)
return
False
return
False
def
directly_map
(
self
,
node
,
*
args
,
name
=
''
,
**
kwargs
):
def
directly_map
(
self
,
node
,
name
=
''
,
*
args
,
**
kwargs
):
inputs
=
node
.
layer
.
input
inputs
=
node
.
layer
.
input
outputs
=
node
.
layer
.
output
outputs
=
node
.
layer
.
output
op_type
=
node
.
layer_type
op_type
=
node
.
layer_type
...
...
x2paddle_model_zoo.md
浏览文件 @
48244d82
...
@@ -39,7 +39,7 @@
...
@@ -39,7 +39,7 @@
| ResNet50 |
[
code
](
https://github.com/soeaver/caffe-model/blob/master/cls/resnet/deploy_resnet50.prototxt
)
|
| ResNet50 |
[
code
](
https://github.com/soeaver/caffe-model/blob/master/cls/resnet/deploy_resnet50.prototxt
)
|
| Unet |
[
code
](
https://github.com/jolibrain/deepdetect/blob/master/templates/caffe/unet/deploy.prototxt
)
|
| Unet |
[
code
](
https://github.com/jolibrain/deepdetect/blob/master/templates/caffe/unet/deploy.prototxt
)
|
| VGGNet |
[
code
](
https://gist.github.com/ksimonyan/211839e770f7b538e2d8#file-vgg_ilsvrc_16_layers_deploy-prototxt
)
|
| VGGNet |
[
code
](
https://gist.github.com/ksimonyan/211839e770f7b538e2d8#file-vgg_ilsvrc_16_layers_deploy-prototxt
)
|
| FaceDetection |
[
code
](
https://github.com/ShiqiYu/libfacedetection/blob/master/models/caffe/yufacedetectnet-open-v1.prototxt
)
|
...
@@ -65,4 +65,3 @@
...
@@ -65,4 +65,3 @@
| mNASNet |
[
pytorch(personal practice)
](
https://github.com/rwightman/gen-efficientnet-pytorch
)
|9|
| mNASNet |
[
pytorch(personal practice)
](
https://github.com/rwightman/gen-efficientnet-pytorch
)
|9|
| EfficientNet |
[
pytorch(personal practice)
](
https://github.com/rwightman/gen-efficientnet-pytorch
)
|9|
| EfficientNet |
[
pytorch(personal practice)
](
https://github.com/rwightman/gen-efficientnet-pytorch
)
|9|
| SqueezeNet |
[
onnx official
](
https://s3.amazonaws.com/download.onnx/models/opset_9/squeezenet.tar.gz
)
|9|
| SqueezeNet |
[
onnx official
](
https://s3.amazonaws.com/download.onnx/models/opset_9/squeezenet.tar.gz
)
|9|
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录