Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
1a00c049
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看板
未验证
提交
1a00c049
编写于
8月 06, 2019
作者:
J
Jason
提交者:
GitHub
8月 06, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #80 from SunAhong1993/develop
fix the --caffe_proto
上级
d6af8cf0
29ffa10e
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
10203 addition
and
20 deletion
+10203
-20
README.md
README.md
+1
-1
x2paddle/convert.py
x2paddle/convert.py
+8
-7
x2paddle/decoder/caffe_decoder.py
x2paddle/decoder/caffe_decoder.py
+31
-12
x2paddle/decoder/caffe_pb2.py
x2paddle/decoder/caffe_pb2.py
+10163
-0
未找到文件。
README.md
浏览文件 @
1a00c049
...
@@ -40,7 +40,7 @@ x2paddle --framework=caffe --prototxt=deploy.proto --weight=deploy.caffemodel --
...
@@ -40,7 +40,7 @@ x2paddle --framework=caffe --prototxt=deploy.proto --weight=deploy.caffemodel --
|--weight | 当framework为caffe时,该参数指定caffe模型的参数文件路径 |
|--weight | 当framework为caffe时,该参数指定caffe模型的参数文件路径 |
|--save_dir | 指定转换后的模型保存目录路径 |
|--save_dir | 指定转换后的模型保存目录路径 |
|--model | 当framework为tensorflow时,该参数指定tensorflow的pb模型文件路径 |
|--model | 当framework为tensorflow时,该参数指定tensorflow的pb模型文件路径 |
|--caffe_proto | [可选]由caffe.proto编译成caffe_pb2.py文件的存放路径,当没有安装caffe或者使用自定义Layer时使用 |
|--caffe_proto | [可选]由caffe.proto编译成caffe_pb2.py文件的存放路径,当没有安装caffe或者使用自定义Layer时使用
,默认为None
|
## 使用转换后的模型
## 使用转换后的模型
转换后的模型包括
`model_with_code`
和
`inference_model`
两个目录。
转换后的模型包括
`model_with_code`
和
`inference_model`
两个目录。
...
...
x2paddle/convert.py
浏览文件 @
1a00c049
...
@@ -45,11 +45,12 @@ def arg_parser():
...
@@ -45,11 +45,12 @@ def arg_parser():
type
=
_text_type
,
type
=
_text_type
,
default
=
None
,
default
=
None
,
help
=
"define which deeplearning framework"
)
help
=
"define which deeplearning framework"
)
parser
.
add_argument
(
"--caffe_proto"
,
parser
.
add_argument
(
"-c"
,
"--caffe_proto"
,
type
=
_text_type
,
"-c"
,
default
=
None
,
type
=
_text_type
,
help
=
"caffe proto file of caffe model"
)
default
=
None
,
help
=
"the .py file compiled by caffe proto file of caffe model"
)
parser
.
add_argument
(
"--version"
,
parser
.
add_argument
(
"--version"
,
"-v"
,
"-v"
,
action
=
"store_true"
,
action
=
"store_true"
,
...
@@ -92,8 +93,8 @@ def tf2paddle(model_path, save_dir):
...
@@ -92,8 +93,8 @@ def tf2paddle(model_path, save_dir):
def
caffe2paddle
(
proto
,
weight
,
save_dir
,
caffe_proto
):
def
caffe2paddle
(
proto
,
weight
,
save_dir
,
caffe_proto
):
if
caffe_proto
is
not
None
:
if
caffe_proto
is
not
None
:
import
os
import
os
if
not
os
.
path
.
isfile
(
caffe_proto
+
'caffe_pb2.py'
):
if
caffe_proto
is
not
None
and
not
os
.
path
.
isfile
(
caffe_proto
):
print
(
"The
file that resolve caffe
is not exist."
)
print
(
"The
.py file compiled by caffe.proto
is not exist."
)
return
return
else
:
else
:
try
:
try
:
...
...
x2paddle/decoder/caffe_decoder.py
浏览文件 @
1a00c049
...
@@ -22,18 +22,21 @@ from x2paddle.op_mapper import caffe_shape
...
@@ -22,18 +22,21 @@ from x2paddle.op_mapper import caffe_shape
class
CaffeResolver
(
object
):
class
CaffeResolver
(
object
):
def
__init__
(
self
,
caffe_proto
_folder
=
None
):
def
__init__
(
self
,
caffe_proto
):
self
.
proto_path
=
caffe_proto
_folder
self
.
proto_path
=
caffe_proto
if
self
.
proto_path
==
None
:
if
self
.
proto_path
is
None
:
self
.
use_default
=
True
self
.
use_default
=
True
else
:
else
:
self
.
use_default
=
False
self
.
use_default
=
False
self
.
import_caffe
()
self
.
import_caffe
()
def
import_caffepb
(
self
):
def
import_caffepb
(
self
):
sys
.
path
.
append
(
self
.
proto_path
)
(
filepath
,
import
caffe_pb2
tempfilename
)
=
os
.
path
.
split
(
os
.
path
.
abspath
(
self
.
proto_path
))
return
caffe_pb2
(
filename
,
extension
)
=
os
.
path
.
splitext
(
tempfilename
)
sys
.
path
.
append
(
filepath
)
out
=
__import__
(
filename
)
return
out
def
import_caffe
(
self
):
def
import_caffe
(
self
):
self
.
caffe
=
None
self
.
caffe
=
None
...
@@ -139,9 +142,17 @@ class CaffeGraph(Graph):
...
@@ -139,9 +142,17 @@ class CaffeGraph(Graph):
dim
=
[
dims
[
0
],
dims
[
1
],
dims
[
2
],
dims
[
3
]
dim
=
[
dims
[
0
],
dims
[
1
],
dims
[
2
],
dims
[
3
]
]))).
to_proto
().
layer
[
0
])
]))).
to_proto
().
layer
[
0
])
except
:
except
:
raise
ImportError
(
print
(
'The .proto file does not work for the old style prototxt. You must install the caffe or modify the old style to new style in .protottx file.'
"The .py file compiled by .proto file does not work for the old style prototxt. "
)
)
print
(
"There are 2 solutions for you as below:"
)
print
(
"1. install caffe and don
\'
t set
\'
--caffe_proto
\'
."
)
print
(
"2. modify your .prototxt from the old style to the new style."
)
sys
.
exit
(
-
1
)
data
.
name
=
self
.
model
.
input
[
i
]
data
.
name
=
self
.
model
.
input
[
i
]
data
.
top
[
0
]
=
self
.
model
.
input
[
i
]
data
.
top
[
0
]
=
self
.
model
.
input
[
i
]
else
:
else
:
...
@@ -155,9 +166,17 @@ class CaffeGraph(Graph):
...
@@ -155,9 +166,17 @@ class CaffeGraph(Graph):
dim
=
[
dims
[
0
],
dims
[
1
],
dims
[
2
],
dims
[
3
]
dim
=
[
dims
[
0
],
dims
[
1
],
dims
[
2
],
dims
[
3
]
]))).
to_proto
().
layer
[
0
])
]))).
to_proto
().
layer
[
0
])
except
:
except
:
raise
ImportError
(
print
(
'The .proto file does not work for the old style prototxt. You must install the caffe or modify the old style to new style in .protottx file.'
"The .py file compiled by .proto file does not work for the old style prototxt. "
)
print
(
"There are 2 solutions for you as below:"
)
print
(
"1. install caffe and don
\'
t set
\'
--caffe_proto
\'
."
)
print
(
"2. modify your .prototxt from the old style to the new style."
)
)
sys
.
exit
(
-
1
)
data
.
name
=
self
.
model
.
input
[
i
]
data
.
name
=
self
.
model
.
input
[
i
]
data
.
top
[
0
]
=
self
.
model
.
input
[
i
]
data
.
top
[
0
]
=
self
.
model
.
input
[
i
]
layers
=
[
data
]
+
layers
layers
=
[
data
]
+
layers
...
@@ -202,11 +221,11 @@ class CaffeGraph(Graph):
...
@@ -202,11 +221,11 @@ class CaffeGraph(Graph):
class
CaffeDecoder
(
object
):
class
CaffeDecoder
(
object
):
def
__init__
(
self
,
proto_path
,
model_path
,
caffe_proto
_folder
=
None
):
def
__init__
(
self
,
proto_path
,
model_path
,
caffe_proto
=
None
):
self
.
proto_path
=
proto_path
self
.
proto_path
=
proto_path
self
.
model_path
=
model_path
self
.
model_path
=
model_path
self
.
resolver
=
CaffeResolver
(
caffe_proto
_folder
=
caffe_proto_folder
)
self
.
resolver
=
CaffeResolver
(
caffe_proto
=
caffe_proto
)
self
.
net
=
self
.
resolver
.
NetParameter
()
self
.
net
=
self
.
resolver
.
NetParameter
()
with
open
(
proto_path
,
'rb'
)
as
proto_file
:
with
open
(
proto_path
,
'rb'
)
as
proto_file
:
proto_str
=
proto_file
.
read
()
proto_str
=
proto_file
.
read
()
...
...
x2paddle/decoder/caffe_pb2.py
0 → 100644
浏览文件 @
1a00c049
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录