Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
67fe580d
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看板
提交
67fe580d
编写于
1月 25, 2019
作者:
J
jiangjiajun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add demo & doc
上级
e75e3a67
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
102 addition
and
2 deletion
+102
-2
tensorflow2fluid/convert.py
tensorflow2fluid/convert.py
+52
-0
tensorflow2fluid/demo/inception_v3/export_to_ckpt.py
tensorflow2fluid/demo/inception_v3/export_to_ckpt.py
+45
-0
tensorflow2fluid/doc/如何从TensorFlow迁移至Paddle.md
tensorflow2fluid/doc/如何从TensorFlow迁移至Paddle.md
+0
-0
tensorflow2fluid/src/paddle_emitter.py
tensorflow2fluid/src/paddle_emitter.py
+5
-2
未找到文件。
tensorflow2fluid/convert.py
0 → 100644
浏览文件 @
67fe580d
from
src.paddle_emitter
import
PaddleEmitter
from
src.tensorflow_parser
import
TensorflowCkptParser
from
src.tensorflow_parser
import
TensorflowPbParser
from
six
import
text_type
as
_text_type
import
argparse
import
sys
import
os
def
_get_parser
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"--meta_file"
,
"-m"
,
type
=
_text_type
,
default
=
None
,
help
=
"meta file path for checkpoint format"
)
parser
.
add_argument
(
"--ckpt_dir"
,
"-c"
,
type
=
_text_type
,
default
=
None
,
help
=
"checkpoint directory"
)
parser
.
add_argument
(
"--pb_file"
,
"-p"
,
type
=
_text_type
,
default
=
None
,
help
=
"pb model file path"
)
parser
.
add_argument
(
"--in_nodes"
,
"-i"
,
type
=
_text_type
,
nargs
=
"+"
,
default
=
None
,
help
=
"input nodes name"
)
parser
.
add_argument
(
"--input_shape"
,
"-is"
,
type
=
_text_type
,
nargs
=
"+"
,
default
=
None
,
help
=
"input tensor shape"
)
parser
.
add_argument
(
"--output_nodes"
,
"-o"
,
type
=
_text_type
,
nargs
=
"+"
,
default
=
None
,
help
=
"output nodes name"
)
parser
.
add_argument
(
"--save_dir"
,
"-s"
,
type
=
_text_type
,
default
=
None
,
help
=
"path to save transformed paddle model"
)
return
parser
def
_convert
(
args
):
if
args
.
meta_file
is
None
and
args
.
pb_file
is
None
:
raise
Exception
(
"Need to define --meta_file or --pb_file"
)
assert
args
.
in_nodes
is
not
None
assert
args
.
output_nodes
is
not
None
assert
args
.
input_shape
is
not
None
assert
args
.
save_dir
is
not
None
if
os
.
path
.
exists
(
args
.
save_dir
):
sys
.
stderr
.
write
(
"save_dir already exists, change to a new path
\n
"
)
return
os
.
makedirs
(
args
.
save_dir
)
input_shape
=
list
()
for
shape_str
in
args
.
input_shape
:
items
=
shape_str
.
split
(
','
)
for
i
in
range
(
len
(
items
)):
if
items
[
i
]
!=
"None"
:
items
[
i
]
=
int
(
items
[
i
])
input_shape
.
append
(
items
)
if
args
.
meta_file
is
not
None
:
parser
=
TensorflowCkptParser
(
args
.
meta_file
,
args
.
ckpt_dir
,
args
.
output_nodes
,
input_shape
,
args
.
in_nodes
)
else
:
parser
=
TensorflowPbParser
(
args
.
pb_file
,
args
.
output_nodes
,
input_shape
,
args
.
in_nodes
)
emitter
=
PaddleEmitter
(
parser
,
args
.
save_dir
)
emitter
.
run
()
if
__name__
==
"__main__"
:
parser
=
_get_parser
()
args
=
parser
.
parse_args
()
_convert
(
args
)
tensorflow2fluid/demo/inception_v3/export_to_ckpt.py
0 → 100644
浏览文件 @
67fe580d
from
tensorflow.contrib.slim.nets
import
inception
from
tensorflow.contrib.framework.python.ops
import
arg_scope
import
tensorflow.contrib.slim
as
slim
import
tensorflow
as
tf
import
numpy
import
sys
numpy
.
random
.
seed
(
13
)
ckpt_file
=
sys
.
argv
[
1
]
checkpoint_dir
=
sys
.
argv
[
2
]
def
get_tuned_variables
():
CHECKPOINT_EXCLUDE_SCOPES
=
'InceptionV3/Logits,InceptionV3/AuxLogits'
exclusions
=
[
scope
.
strip
()
for
scope
in
CHECKPOINT_EXCLUDE_SCOPES
.
split
(
','
)]
variables_to_restore
=
[]
for
var
in
slim
.
get_model_variables
():
excluded
=
False
for
exclusion
in
exclusions
:
if
var
.
op
.
name
.
startswith
(
exclusion
):
excluded
=
True
break
if
not
excluded
:
variables_to_restore
.
append
(
var
)
return
variables_to_restore
def
load_model
():
img_size
=
inception
.
inception_v3
.
default_image_size
img
=
tf
.
placeholder
(
tf
.
float32
,
shape
=
[
None
,
img_size
,
img_size
,
3
],
name
=
'inputs'
)
with
slim
.
arg_scope
(
inception
.
inception_v3_arg_scope
()):
logits
,
_
=
inception
.
inception_v3
(
img
,
num_classes
=
1000
,
is_training
=
False
)
sess
=
tf
.
Session
()
init
=
tf
.
global_variables_initializer
()
sess
.
run
(
init
)
load_model
=
tf
.
contrib
.
slim
.
assign_from_checkpoint_fn
(
ckpt_file
,
get_tuned_variables
(),
ignore_missing_vars
=
True
)
load_model
(
sess
)
return
sess
def
save_checkpoint
(
sess
):
saver
=
tf
.
train
.
Saver
()
saver
.
save
(
sess
,
checkpoint_dir
+
"/model"
)
if
__name__
==
"__main__"
:
sess
=
load_model
()
save_checkpoint
(
sess
)
tensorflow2fluid/doc/如何从TensorFlow迁移至Paddle.md
0 → 100644
浏览文件 @
67fe580d
tensorflow2fluid/src/paddle_emitter.py
浏览文件 @
67fe580d
...
...
@@ -124,8 +124,8 @@ class PaddleEmitter(object):
ref_name_recorder
=
open
(
self
.
save_dir
+
"/ref_name.txt"
,
'w'
)
total_nodes_num
=
len
(
self
.
graph
.
topological_sort
)
translated_nodes_count
=
0
sys
.
stderr
.
write
(
"Start to translate all the nodes(Total_num:{})
\n
"
.
translated_nodes_count
=
1
sys
.
stderr
.
write
(
"
\n
Start to translate all the nodes(Total_num:{})
\n
"
.
format
(
total_nodes_num
))
for
node
in
self
.
graph
.
topological_sort
:
sys
.
stderr
.
write
(
...
...
@@ -168,6 +168,9 @@ class PaddleEmitter(object):
filew
.
write
(
self
.
body_code
)
filew
.
close
()
sys
.
stderr
.
write
(
"Model translated!
\n\n
"
)
sys
.
stderr
.
flush
()
return
self
.
body_code
def
emit_placeholder
(
self
,
node
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录