Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
108533b2
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看板
未验证
提交
108533b2
编写于
10月 29, 2019
作者:
S
SunAhong1993
提交者:
GitHub
10月 29, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1 from PaddlePaddle/develop
add
上级
f75e11dc
a72829d0
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
360 addition
and
174 deletion
+360
-174
README.md
README.md
+3
-3
op_list.md
op_list.md
+52
-0
x2paddle/decoder/tf_decoder.py
x2paddle/decoder/tf_decoder.py
+5
-1
x2paddle/op_mapper/tf_op_mapper.py
x2paddle/op_mapper/tf_op_mapper.py
+5
-66
x2paddle/op_mapper/tf_op_mapper_nhwc.py
x2paddle/op_mapper/tf_op_mapper_nhwc.py
+52
-12
x2paddle/optimizer/tf_optimizer.py
x2paddle/optimizer/tf_optimizer.py
+242
-92
x2paddle_model_zoo.md
x2paddle_model_zoo.md
+1
-0
未找到文件。
README.md
浏览文件 @
108533b2
...
@@ -5,7 +5,7 @@ X2Paddle支持将其余深度学习框架训练得到的模型,转换至Paddle
...
@@ -5,7 +5,7 @@ X2Paddle支持将其余深度学习框架训练得到的模型,转换至Paddle
X2Paddle is a toolkit for converting trained model to PaddlePaddle from other deep learning frameworks.
X2Paddle is a toolkit for converting trained model to PaddlePaddle from other deep learning frameworks.
## 转换模型库
## 转换模型库
X2Paddle在多个主流的CV模型上,测试过TensorFlow/Caffe/ONNX模型的转换,可以在
[
X2Paddle-Model-Zoo
](
x2paddle_model_zoo.md
)
查看我们的模型测试列表。如果你在新的模型上进行了测试转换,也欢迎继续补充该列表;如若无法转换,可通过ISSUE反馈给我们,我们会尽快跟进。
X2Paddle在多个主流的CV模型上,测试过TensorFlow/Caffe/ONNX模型的转换,可以在
[
X2Paddle-Model-Zoo
](
x2paddle_model_zoo.md
)
查看我们的模型测试列表
,可以在
[
OP-LIST
](
op_list.md
)
中查看目前X2Paddle支持的OP列表
。如果你在新的模型上进行了测试转换,也欢迎继续补充该列表;如若无法转换,可通过ISSUE反馈给我们,我们会尽快跟进。
## 环境依赖
## 环境依赖
...
@@ -29,7 +29,7 @@ python setup.py install
...
@@ -29,7 +29,7 @@ python setup.py install
### 安装方式二
### 安装方式二
我们会定期更新pip源上的x2paddle版本
我们会定期更新pip源上的x2paddle版本
```
```
pip install x2paddle
pip install x2paddle
--index https://pypi.Python.org/simple/
```
```
## 使用方法
## 使用方法
### TensorFlow
### TensorFlow
...
@@ -38,7 +38,7 @@ x2paddle --framework=tensorflow --model=tf_model.pb --save_dir=pd_model
...
@@ -38,7 +38,7 @@ x2paddle --framework=tensorflow --model=tf_model.pb --save_dir=pd_model
```
```
### Caffe
### Caffe
```
```
x2paddle --framework=caffe --prototxt=deploy.proto --weight=deploy.caffemodel --save_dir=pd_model
x2paddle --framework=caffe --prototxt=deploy.proto
txt
--weight=deploy.caffemodel --save_dir=pd_model
```
```
### ONNX
### ONNX
```
```
...
...
op_list.md
0 → 100644
浏览文件 @
108533b2
# X2Paddle支持OP列表
> 目前X2Paddle支持40+的TensorFlow OP,30+的Caffe Layer,覆盖了大部分CV分类模型常用的操作。我们在如下列表中给出了目前X2Paddle支持的全部OP。
**注:**
目前,部分OP暂未支持,如您在转换过程中出现OP不支持的情况,可自行添加或反馈给我们。欢迎通过
[
ISSUE反馈
](
https://github.com/PaddlePaddle/X2Paddle/issues/new
)
的方式告知我们(模型名,代码实现或模型获取方式),我们会及时跟进:)
## TensorFlow
| 序号 | OP | 序号 | OP | 序号 | OP | 序号 | OP |
|------|------|------|------|------|------|------|------|
| 1 | Relu | 2 | Relu6 | 3 | Shape | 4 | Abs |
| 5 | Sigmoid | 6 | Exp | 7 | Rsqrt | 8 | swish_f32 |
| 9 | Tanh | 10 | LeakyRelu | 11 | Add | 12 | RealDiv |
| 13 | Sub | 14 | Maximum | 15 | Mul | 16 | FloorDiv |
| 17 | Placeholder | 18 | Const | 19 | Transpose | 20 | FusedBatchNorm |
| 21 | Conv2D | 22 | BiasAdd | 23 | MaxPool | 24 | DepthwiseConv2dNative |
| 25 | Reshape | 26 | AvgPool | 27 | SplitV | 28 | SquaredDifference |
| 29 | Tile | 30 | Pack | 31 | Pad | 32 | ResizeBilinear |
| 33 | Mean | 34 | MatMul | 35 | ArgMax | 36 | StridedSlice |
| 37 | Slice | 38 | Sum | 39 | Max | 40 | Conv2DBackpropInput |
| 41 | Cast | 42 | Split | 43 | Squeeze | 44 | ResizeNearestNeighbor |
| 45 | Softmax | 46 | Range | 47 | ConcatV2 |
## Caffe
| 序号 | OP | 序号 | OP | 序号 | OP | 序号 | OP |
|------|------|------|------|------|------|------|------|
| 1 | Input | 2 | Convolution | 3 | Deconvolution | 4 | Pooling |
| 5 | LRN | 6 | InnerProduct | 7 | Softmax | 8 | Slice |
| 9 | Concat | 10 | PReLU | 11 | Accuracy | 12 | Eltwise |
| 13 | BatchNorm | 14 | Scale | 15 | Reshape | 16 | ArgMax |
| 17 | Crop | 18 | Flatten | 19 | Power | 20 | Reduction |
| 21 | Axpy | 22 | ROIPolling | 23 | Permute | 24 | DetectionOutput |
| 25 | Normalize | 26 | Select | 27 | ShuffleChannel | 28 | ConvolutionDepthwise |
| 29 | ReLU | 30 | AbsVal | 31 | Sigmoid | 32 | TanH |
## ONNX
| 序号 | OP | 序号 | OP | 序号 | OP | 序号 | OP |
|------|------|------|------|------|------|------|------|
| 1 | Relu | 2 | LeakyRelu | 3 | Elu | 4 | ThresholdedRelu |
| 5 | Prelu | 6 | Tanh | 7 | Shrink | 8 | Sigmoid |
| 9 | Pow | 10 | Softplus | 11 | Softsign | 12 | HardSigmoid |
| 13 | Exp | 14 | Add | 15 | Div | 16 | Sub |
| 17 | Mul | 18 | Shape | 19 | Clip | 20 | AveragePool |
| 21 | Sqrt | 22 | ReduceSum | 23 | ReduceMin | 24 | ReduceMean |
| 25 | Constant | 26 | Pad | 27 | Unsqueeze | 28 | Resize |
| 29 | Upsample | 30 | Expand | 31 | Gather | 32 | Slice |
| 33 | Cast | 34 | Split | 35 | Reshape | 36 | ConstantOfShape |
| 37 | Ceil | 38 | Concat | 39 | Flatten | 40 | ConvTranspose |
| 41 | MatMul | 42 | Sum | 43 | Transpose | 44 | BatchNormalization |
| 45 | Squeeze | 46 | Equal | 47 | Identity | 48 | GlobalAveragePool |
| 49 | MaxPool | 50 | Conv | 51 | Gemm |
x2paddle/decoder/tf_decoder.py
浏览文件 @
108533b2
...
@@ -312,7 +312,11 @@ class TFDecoder(object):
...
@@ -312,7 +312,11 @@ class TFDecoder(object):
right_shape_been_input
=
False
right_shape_been_input
=
False
while
not
right_shape_been_input
:
while
not
right_shape_been_input
:
shape
=
input
(
"Shape of Input(e.g. None,224,224,3): "
)
try
:
shape
=
raw_input
(
"Shape of Input(e.g. None,224,224,3): "
)
except
:
shape
=
input
(
"Shape of Input(e.g. None,224,224,3): "
)
if
shape
.
count
(
"None"
)
>
1
:
if
shape
.
count
(
"None"
)
>
1
:
print
(
"Only 1 dimension can be None, type again:)"
)
print
(
"Only 1 dimension can be None, type again:)"
)
else
:
else
:
...
...
x2paddle/op_mapper/tf_op_mapper.py
浏览文件 @
108533b2
...
@@ -168,7 +168,11 @@ class TFOpMapper(OpMapper):
...
@@ -168,7 +168,11 @@ class TFOpMapper(OpMapper):
x_input
=
y
x_input
=
y
y_input
=
x
y_input
=
x
x_shape
=
y
.
out_shapes
[
0
]
x_shape
=
y
.
out_shapes
[
0
]
if
len
(
x_shape
)
==
0
:
x_shape
=
[
1
]
y_shape
=
x
.
out_shapes
[
0
]
y_shape
=
x
.
out_shapes
[
0
]
if
len
(
y_shape
)
==
0
:
y_shape
=
[
1
]
else
:
else
:
if
len
(
x_shape
)
==
1
and
len
(
y_shape
)
==
4
and
x_shape
[
if
len
(
x_shape
)
==
1
and
len
(
y_shape
)
==
4
and
x_shape
[
0
]
==
y_shape
[
-
1
]
and
y_shape
.
count
(
-
1
)
<
1
:
0
]
==
y_shape
[
-
1
]
and
y_shape
.
count
(
-
1
)
<
1
:
...
@@ -1006,7 +1010,7 @@ class TFOpMapper(OpMapper):
...
@@ -1006,7 +1010,7 @@ class TFOpMapper(OpMapper):
attr
=
{
attr
=
{
"bias_attr"
:
False
,
"bias_attr"
:
False
,
"param_attr"
:
string
(
kernel
.
layer_name
),
"param_attr"
:
string
(
kernel
.
layer_name
),
"num_filters"
:
k_size
[
3
],
"num_filters"
:
k_size
[
2
],
"filter_size"
:
k_size
[
0
:
2
],
"filter_size"
:
k_size
[
0
:
2
],
"stride"
:
strides
[
2
:
4
],
"stride"
:
strides
[
2
:
4
],
"dilation"
:
dilations
[
2
:
4
],
"dilation"
:
dilations
[
2
:
4
],
...
@@ -1112,40 +1116,6 @@ class TFOpMapper(OpMapper):
...
@@ -1112,40 +1116,6 @@ class TFOpMapper(OpMapper):
output
=
node
,
output
=
node
,
param_attr
=
attr
)
param_attr
=
attr
)
def
ResizeNearestNeighbor
(
self
,
node
):
input
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
resize_shape
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
],
copy
=
True
)
self
.
add_omit_nodes
(
resize_shape
.
layer_name
,
node
.
layer_name
)
if
resize_shape
.
layer_type
==
"Const"
:
resize_shape
=
resize_shape
.
value
.
tolist
()
else
:
resize_shape
=
self
.
decoder
.
infer_shape_tensor
(
resize_shape
)
align_corners
=
node
.
get_attr
(
"align_corners"
)
attr
=
{
"align_corners"
:
align_corners
,
"out_shape"
:
resize_shape
}
node
.
fluid_code
.
add_layer
(
"resize_nearest"
,
inputs
=
input
,
output
=
node
,
param_attr
=
attr
)
def
ResizeBilinear
(
self
,
node
):
input
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
resize_shape
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
],
copy
=
True
)
self
.
add_omit_nodes
(
resize_shape
.
layer_name
,
node
.
layer_name
)
if
resize_shape
.
layer_type
==
"Const"
:
resize_shape
=
resize_shape
.
value
.
tolist
()
else
:
resize_shape
=
self
.
decoder
.
infer_shape_tensor
(
resize_shape
)
align_corners
=
node
.
get_attr
(
"align_corners"
)
attr
=
{
"align_corners"
:
align_corners
,
"out_shape"
:
resize_shape
,
"align_mode"
:
1
}
node
.
fluid_code
.
add_layer
(
"resize_bilinear"
,
inputs
=
input
,
output
=
node
,
param_attr
=
attr
)
def
ResizeNearestNeighbor
(
self
,
node
):
def
ResizeNearestNeighbor
(
self
,
node
):
input
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
input
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
resize_shape
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
],
copy
=
True
)
resize_shape
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
],
copy
=
True
)
...
@@ -1191,37 +1161,6 @@ class TFOpMapper(OpMapper):
...
@@ -1191,37 +1161,6 @@ class TFOpMapper(OpMapper):
output
=
node
,
output
=
node
,
param_attr
=
None
)
param_attr
=
None
)
def
RandomUniform
(
self
,
node
):
shape
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
self
.
add_omit_nodes
(
shape
.
layer_name
,
node
.
layer_name
)
if
shape
.
layer_type
==
"Const"
:
shape
=
shape
.
value
.
tolist
()
else
:
shape
=
self
.
decoder
.
infer_shape_tensor
(
shape
)
if
node
.
tf_data_format
==
"NHWC"
and
len
(
shape
)
==
4
:
shape
=
[
shape
[
i
]
for
i
in
[
0
,
3
,
1
,
2
]]
attr
=
{
"shape"
:
shape
,
"min"
:
0.0
,
"max"
:
0.9999
}
if
shape
[
0
]
<
0
:
input
=
self
.
batch_node
node
.
fluid_code
.
add_layer
(
"uniform_random_batch_size_like"
,
inputs
=
input
,
output
=
node
,
param_attr
=
attr
)
else
:
node
.
fluid_code
.
add_layer
(
"uniform_random"
,
inputs
=
None
,
output
=
node
,
param_attr
=
attr
)
def
GreaterEqual
(
self
,
node
):
x
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
y
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
],
copy
=
True
)
inputs
=
{
"x"
:
x
,
"y"
:
y
}
node
.
fluid_code
.
add_layer
(
"greater_equal"
,
inputs
=
inputs
,
output
=
node
,
param_attr
=
None
)
def
RandomUniform
(
self
,
node
):
def
RandomUniform
(
self
,
node
):
shape
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
shape
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
self
.
add_omit_nodes
(
shape
.
layer_name
,
node
.
layer_name
)
self
.
add_omit_nodes
(
shape
.
layer_name
,
node
.
layer_name
)
...
...
x2paddle/op_mapper/tf_op_mapper_nhwc.py
浏览文件 @
108533b2
...
@@ -121,10 +121,29 @@ class TFOpMapperNHWC(OpMapper):
...
@@ -121,10 +121,29 @@ class TFOpMapperNHWC(OpMapper):
pd_param_name
=
list
(
param
.
values
())[
0
]
pd_param_name
=
list
(
param
.
values
())[
0
]
tf_param
=
node
.
get_attr
(
tf_param_name
)
tf_param
=
node
.
get_attr
(
tf_param_name
)
attr
[
pd_param_name
]
=
tf_param
attr
[
pd_param_name
]
=
tf_param
node
.
fluid_code
.
add_layer
(
op_info
[
0
],
inputs
=
input
,
if
len
(
input
.
out_shapes
[
0
])
==
4
and
op_info
[
0
]
!=
'shape'
:
output
=
node
,
attr1
=
{
"perm"
:
[
0
,
3
,
1
,
2
]}
param_attr
=
attr
)
node
.
fluid_code
.
add_layer
(
'transpose'
,
inputs
=
input
,
output
=
node
,
param_attr
=
attr1
)
input
=
node
node
.
fluid_code
.
add_layer
(
op_info
[
0
],
inputs
=
input
,
output
=
node
,
param_attr
=
attr
)
input
=
node
attr2
=
{
"perm"
:
[
0
,
2
,
3
,
1
]}
node
.
fluid_code
.
add_layer
(
'transpose'
,
inputs
=
input
,
output
=
node
,
param_attr
=
attr2
)
else
:
node
.
fluid_code
.
add_layer
(
op_info
[
0
],
inputs
=
input
,
output
=
node
,
param_attr
=
attr
)
def
elementwise_map
(
self
,
node
):
def
elementwise_map
(
self
,
node
):
assert
node
.
layer_type
in
self
.
elementwise_ops
assert
node
.
layer_type
in
self
.
elementwise_ops
...
@@ -149,7 +168,11 @@ class TFOpMapperNHWC(OpMapper):
...
@@ -149,7 +168,11 @@ class TFOpMapperNHWC(OpMapper):
x_input
=
y
x_input
=
y
y_input
=
x
y_input
=
x
x_shape
=
y
.
out_shapes
[
0
]
x_shape
=
y
.
out_shapes
[
0
]
if
len
(
x_shape
)
==
0
:
x_shape
=
[
1
]
y_shape
=
x
.
out_shapes
[
0
]
y_shape
=
x
.
out_shapes
[
0
]
if
len
(
y_shape
)
==
0
:
y_shape
=
[
1
]
else
:
else
:
raise
Exception
(
"Unexpected situation happend"
)
raise
Exception
(
"Unexpected situation happend"
)
...
@@ -193,11 +216,30 @@ class TFOpMapperNHWC(OpMapper):
...
@@ -193,11 +216,30 @@ class TFOpMapperNHWC(OpMapper):
output
=
"y_tmp"
,
output
=
"y_tmp"
,
param_attr
=
attr
)
param_attr
=
attr
)
y_input
=
"y_tmp"
y_input
=
"y_tmp"
inputs
=
{
"x"
:
x_input
,
"y"
:
y_input
}
if
len
(
x_shape
)
==
4
and
len
(
y_shape
)
==
4
:
node
.
fluid_code
.
add_layer
(
op_type
,
node
.
fluid_code
.
add_layer
(
"transpose"
,
inputs
=
inputs
,
inputs
=
x_input
,
output
=
node
,
output
=
x_input
,
param_attr
=
None
)
param_attr
=
{
'perm'
:
[
0
,
3
,
1
,
2
]})
node
.
fluid_code
.
add_layer
(
"transpose"
,
inputs
=
y_input
,
output
=
y_input
,
param_attr
=
{
'perm'
:
[
0
,
3
,
1
,
2
]})
inputs
=
{
"x"
:
x_input
,
"y"
:
y_input
}
node
.
fluid_code
.
add_layer
(
op_type
,
inputs
=
inputs
,
output
=
node
,
param_attr
=
None
)
node
.
fluid_code
.
add_layer
(
"transpose"
,
inputs
=
node
,
output
=
node
,
param_attr
=
{
'perm'
:
[
0
,
2
,
3
,
1
]})
else
:
inputs
=
{
"x"
:
x_input
,
"y"
:
y_input
}
node
.
fluid_code
.
add_layer
(
op_type
,
inputs
=
inputs
,
output
=
node
,
param_attr
=
None
)
def
Placeholder
(
self
,
node
):
def
Placeholder
(
self
,
node
):
shape
=
node
.
out_shapes
[
0
]
shape
=
node
.
out_shapes
[
0
]
...
@@ -965,7 +1007,7 @@ class TFOpMapperNHWC(OpMapper):
...
@@ -965,7 +1007,7 @@ class TFOpMapperNHWC(OpMapper):
attr
=
{
attr
=
{
"bias_attr"
:
False
,
"bias_attr"
:
False
,
"param_attr"
:
string
(
kernel
.
layer_name
),
"param_attr"
:
string
(
kernel
.
layer_name
),
"num_filters"
:
k_size
[
3
],
"num_filters"
:
k_size
[
2
],
"filter_size"
:
k_size
[
0
:
2
],
"filter_size"
:
k_size
[
0
:
2
],
"stride"
:
strides
[
2
:
4
],
"stride"
:
strides
[
2
:
4
],
"dilation"
:
dilations
[
2
:
4
],
"dilation"
:
dilations
[
2
:
4
],
...
@@ -978,9 +1020,7 @@ class TFOpMapperNHWC(OpMapper):
...
@@ -978,9 +1020,7 @@ class TFOpMapperNHWC(OpMapper):
if
pad_mode
==
"SAME"
:
if
pad_mode
==
"SAME"
:
if
node
.
tf_data_format
==
"NHWC"
:
if
node
.
tf_data_format
==
"NHWC"
:
print
(
out_shape
)
out_shape
=
[
out_shape
[
i
]
for
i
in
[
0
,
3
,
1
,
2
]]
out_shape
=
[
out_shape
[
i
]
for
i
in
[
0
,
3
,
1
,
2
]]
print
(
out_shape
)
for
i
in
range
(
4
):
for
i
in
range
(
4
):
if
out_shape
[
i
]
<
0
:
if
out_shape
[
i
]
<
0
:
out_shape
[
i
]
=
999999
out_shape
[
i
]
=
999999
...
...
x2paddle/optimizer/tf_optimizer.py
浏览文件 @
108533b2
此差异已折叠。
点击以展开。
x2paddle_model_zoo.md
浏览文件 @
108533b2
...
@@ -65,3 +65,4 @@
...
@@ -65,3 +65,4 @@
| 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|
|Ultra-Light-Fast-Generic-Face-Detector-1MB|
[
onnx_model
](
https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB/tree/master/models/onnx
)
| |
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录