Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
Mace
提交
abef71cf
Mace
项目概览
慢慢CG
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Mace
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
abef71cf
编写于
1月 30, 2018
作者:
L
liuqi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add shape information to input node.
上级
08314882
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
31 addition
and
2 deletion
+31
-2
python/tools/tf_converter.py
python/tools/tf_converter.py
+8
-1
python/tools/tf_converter_lib.py
python/tools/tf_converter_lib.py
+23
-1
未找到文件。
python/tools/tf_converter.py
浏览文件 @
abef71cf
...
...
@@ -34,8 +34,10 @@ def main(unused_args):
output_graph_def
=
tf_dsp_converter_lib
.
convert_to_mace_pb
(
input_graph_def
,
FLAGS
.
input_node
,
FLAGS
.
output_node
,
FLAGS
.
dsp_mode
)
else
:
input_shape
=
[
int
(
x
)
for
x
in
FLAGS
.
input_shape
.
split
(
','
)]
output_graph_def
=
tf_converter_lib
.
convert_to_mace_pb
(
input_graph_def
,
FLAGS
.
input_node
,
FLAGS
.
output_node
,
FLAGS
.
data_type
,
FLAGS
.
runtime
,
FLAGS
.
winograd
)
input_graph_def
,
FLAGS
.
input_node
,
input_shape
,
FLAGS
.
output_node
,
FLAGS
.
data_type
,
FLAGS
.
runtime
,
FLAGS
.
winograd
)
if
FLAGS
.
output_type
==
'source'
:
source_converter_lib
.
convert_to_source
(
output_graph_def
,
mode_pb_checksum
,
FLAGS
.
template
,
FLAGS
.
obfuscate
,
...
...
@@ -124,6 +126,11 @@ def parse_args():
type
=
int
,
default
=
0
,
help
=
"dsp run mode, defalut=0"
)
parser
.
add_argument
(
"--input_shape"
,
type
=
str
,
default
=
"1,512,512,3"
,
help
=
"input shape."
)
return
parser
.
parse_known_args
()
...
...
python/tools/tf_converter_lib.py
浏览文件 @
abef71cf
...
...
@@ -2,7 +2,12 @@ from lib.proto import mace_pb2
import
tensorflow
as
tf
import
numpy
as
np
import
math
import
copy
from
lib.python.tools
import
memory_optimizer
from
tensorflow.core.framework
import
attr_value_pb2
from
tensorflow.core.framework
import
graph_pb2
from
tensorflow.core.framework
import
tensor_shape_pb2
from
tensorflow.core.framework
import
node_def_pb2
# TODO: support NCHW formt, now only support NHWC.
padding_mode
=
{
...
...
@@ -903,10 +908,27 @@ class Optimizer:
new_net
=
self
.
fold_batch_norm
()
return
new_net
def
convert_to_mace_pb
(
input_graph_def
,
input_node
,
output_node
,
data_type
,
device
,
winograd
):
def
add_shape_info
(
input_graph_def
,
input_node
,
input_shape
):
inputs_replaced_graph
=
graph_pb2
.
GraphDef
()
for
node
in
input_graph_def
.
node
:
if
node
.
name
==
input_node
:
placeholder_node
=
copy
.
deepcopy
(
node
)
placeholder_node
.
attr
.
clear
()
placeholder_node
.
attr
[
'shape'
].
shape
.
dim
.
extend
([
tensor_shape_pb2
.
TensorShapeProto
.
Dim
(
size
=
i
)
for
i
in
input_shape
])
placeholder_node
.
attr
[
'dtype'
].
CopyFrom
(
node
.
attr
[
'dtype'
])
inputs_replaced_graph
.
node
.
extend
([
placeholder_node
])
else
:
inputs_replaced_graph
.
node
.
extend
([
copy
.
deepcopy
(
node
)])
return
inputs_replaced_graph
def
convert_to_mace_pb
(
input_graph_def
,
input_node
,
input_shape
,
output_node
,
data_type
,
device
,
winograd
):
net_def
=
mace_pb2
.
NetDef
()
dt
=
data_type_map
[
data_type
]
input_graph_def
=
add_shape_info
(
input_graph_def
,
input_node
,
input_shape
)
with
tf
.
Session
()
as
session
:
with
session
.
graph
.
as_default
()
as
graph
:
tf
.
import_graph_def
(
input_graph_def
,
name
=
""
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录