Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
冰之2023
Mace
提交
5783680a
Mace
项目概览
冰之2023
/
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看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5783680a
编写于
11月 21, 2017
作者:
Y
Yin Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add QuantizedRelu test
上级
d246608c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
159 addition
and
11 deletion
+159
-11
mace/dsp/BUILD
mace/dsp/BUILD
+16
-0
mace/dsp/hexagon_control_wrapper.cc
mace/dsp/hexagon_control_wrapper.cc
+8
-7
mace/dsp/hexagon_control_wrapper.h
mace/dsp/hexagon_control_wrapper.h
+1
-1
mace/dsp/test/quantized_relu_test.cc
mace/dsp/test/quantized_relu_test.cc
+131
-0
mace/python/tools/tf_dsp_converter_lib.py
mace/python/tools/tf_dsp_converter_lib.py
+3
-3
未找到文件。
mace/dsp/BUILD
浏览文件 @
5783680a
...
...
@@ -46,3 +46,19 @@ cc_test(
":dsp"
,
],
)
cc_test
(
name
=
"dsp_op_test"
,
testonly
=
1
,
srcs
=
glob
([
"test/*_test.cc"
]),
copts
=
[
"-std=c++11"
],
linkopts
=
if_android
([
"-ldl"
,
"-lm"
,
]),
linkstatic
=
1
,
deps
=
[
"@gtest//:gtest_main"
,
":dsp"
,
],
)
mace/dsp/hexagon_control_wrapper.cc
浏览文件 @
5783680a
...
...
@@ -42,7 +42,7 @@ bool HexagonControlWrapper::Finalize() {
return
true
;
}
bool
HexagonControlWrapper
::
SetupGraph
(
NetDef
net_def
)
{
bool
HexagonControlWrapper
::
SetupGraph
(
const
NetDef
&
net_def
)
{
LOG
(
INFO
)
<<
"Hexagon setup graph"
;
// const node
for
(
const
TensorProto
&
tensor_proto
:
net_def
.
tensors
())
{
...
...
@@ -181,21 +181,22 @@ void HexagonControlWrapper::GetPerfInfo() {
std
::
unordered_map
<
uint32_t
,
float
>
node_id_counters
;
std
::
unordered_map
<
std
::
string
,
std
::
pair
<
int
,
float
>>
node_type_counters
;
float
total_duration
=
0.0
;
VLOG
(
0
)
<<
"items: "
<<
n_items
;
for
(
int
i
=
0
;
i
<
n_items
;
++
i
)
{
unsigned
int
node_id
=
perf_info
[
i
].
node_id
;
unsigned
int
node_type_id
=
perf_info
[
i
].
node_type
;
node_id_counters
[
node_id
]
=
((
static_cast
<
uint64_t
>
(
perf_info
[
i
].
counter_hi
)
<<
32
)
+
perf_info
[
i
].
counter_lo
)
*
1.0
f
/
perf_info
[
i
].
executions
;
LOG
(
INFO
)
<<
"node id: "
<<
perf_info
[
i
].
node_id
<<
", node type: "
<<
perf_info
[
i
].
node_type
<<
", executions: "
<<
perf_info
[
i
].
executions
<<
", duration: "
<<
node_id_counters
[
node_id
];
char
node_type_buf
[
1280
];
hexagon_nn_op_id_to_name
(
node_type_id
,
node_type_buf
,
1280
);
std
::
string
node_type
(
node_type_buf
);
LOG
(
INFO
)
<<
"node id: "
<<
perf_info
[
i
].
node_id
<<
", node type: "
<<
node_type
<<
", executions: "
<<
perf_info
[
i
].
executions
<<
", duration: "
<<
node_id_counters
[
node_id
];
if
(
node_type_counters
.
find
(
node_type
)
==
node_type_counters
.
end
())
{
node_type_counters
[
node_type
]
=
{
0
,
0.0
};
}
...
...
mace/dsp/hexagon_control_wrapper.h
浏览文件 @
5783680a
...
...
@@ -21,7 +21,7 @@ class HexagonControlWrapper {
bool
Config
();
bool
Init
();
bool
Finalize
();
bool
SetupGraph
(
NetDef
net_def
);
bool
SetupGraph
(
const
NetDef
&
net_def
);
bool
SetupGraph
(
const
std
::
string
&
model_file
);
bool
ExecuteGraph
(
const
Tensor
&
input_tensor
,
Tensor
*
output_tensor
)
{
LOG
(
INFO
)
<<
"Execute graph: "
<<
nn_id_
;
...
...
mace/dsp/test/quantized_relu_test.cc
0 → 100644
浏览文件 @
5783680a
//
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#include "mace/dsp/hexagon_control_wrapper.h"
#include "gtest/gtest.h"
using
namespace
mace
;
static
NetDef
BuildNetDef
()
{
NetDef
net
;
net
.
set_name
(
"quantized_relu_test"
);
// input op
OperatorDef
*
input_op
=
net
.
add_op
();
input_op
->
set_name
(
"input_node"
);
input_op
->
set_type
(
"INPUT"
);
input_op
->
set_node_id
(
0
);
input_op
->
set_padding
(
0
);
input_op
->
add_out_max_byte_size
(
1000
);
// relu op
OperatorDef
*
relu_op
=
net
.
add_op
();
relu_op
->
set_name
(
"relu"
);
relu_op
->
set_type
(
"QuantizedRelu_8"
);
relu_op
->
set_node_id
(
1
);
relu_op
->
set_padding
(
0
);
relu_op
->
add_input
(
"input_node"
);
relu_op
->
add_input
(
"input_min"
);
relu_op
->
add_input
(
"input_max"
);
relu_op
->
add_output
(
"relu:0"
);
relu_op
->
add_output
(
"relu:1"
);
relu_op
->
add_output
(
"relu:2"
);
NodeInput
*
input_node_input
=
relu_op
->
add_node_input
();
input_node_input
->
set_node_id
(
0
);
input_node_input
->
set_output_port
(
0
);
input_node_input
=
relu_op
->
add_node_input
();
input_node_input
->
set_node_id
(
10
);
input_node_input
->
set_output_port
(
0
);
input_node_input
=
relu_op
->
add_node_input
();
input_node_input
->
set_node_id
(
11
);
input_node_input
->
set_output_port
(
0
);
relu_op
->
add_out_max_byte_size
(
1000
);
relu_op
->
add_out_max_byte_size
(
1000
);
relu_op
->
add_out_max_byte_size
(
1000
);
// output op
OperatorDef
*
output_op
=
net
.
add_op
();
output_op
->
set_name
(
"__output__"
);
output_op
->
set_type
(
"OUTPUT"
);
output_op
->
set_op_id
(
2
);
input_node_input
=
output_op
->
add_node_input
();
input_node_input
->
set_node_id
(
1
);
input_node_input
->
set_output_port
(
0
);
// tensor
TensorProto
*
input_min_tensor
=
net
.
add_tensors
();
input_min_tensor
->
set_name
(
"input_min"
);
input_min_tensor
->
add_dims
(
1
);
input_min_tensor
->
set_data_type
(
DataType
::
DT_FLOAT
);
input_min_tensor
->
set_node_id
(
10
);
input_min_tensor
->
add_float_data
(
-
100.0
);
TensorProto
*
input_max_tensor
=
net
.
add_tensors
();
input_max_tensor
->
set_name
(
"input_max"
);
input_max_tensor
->
add_dims
(
1
);
input_max_tensor
->
set_data_type
(
DataType
::
DT_FLOAT
);
input_max_tensor
->
set_node_id
(
11
);
input_max_tensor
->
add_float_data
(
100.0
);
// input & output info
InputInfo
*
input_info
=
net
.
add_input_info
();
input_info
->
set_name
(
"input_node"
);
input_info
->
set_node_id
(
0
);
input_info
->
add_dims
(
1
);
input_info
->
add_dims
(
1
);
input_info
->
add_dims
(
1
);
input_info
->
add_dims
(
5
);
input_info
->
set_data_type
(
DataType
::
DT_UINT8
);
input_info
->
set_max_byte_size
(
1000
);
OutputInfo
*
output_info
=
net
.
add_output_info
();
output_info
->
set_name
(
"output_node"
);
output_info
->
set_node_id
(
1
);
output_info
->
add_dims
(
1
);
output_info
->
add_dims
(
1
);
output_info
->
add_dims
(
1
);
output_info
->
add_dims
(
5
);
output_info
->
set_data_type
(
DataType
::
DT_UINT8
);
output_info
->
set_max_byte_size
(
1000
);
return
net
;
}
TEST
(
QuantizedReluTest
,
QuantizedRelu
)
{
testing
::
internal
::
LogToStderr
();
HexagonControlWrapper
wrapper
;
wrapper
.
Init
();
wrapper
.
SetDebugLevel
(
3
);
wrapper
.
Config
();
NetDef
net
=
BuildNetDef
();
wrapper
.
SetupGraph
(
net
);
Allocator
*
cpu_allocator
=
GetDeviceAllocator
(
DeviceType
::
CPU
);
Tensor
input_tensor
(
cpu_allocator
,
DT_UINT8
);
Tensor
output_tensor
(
cpu_allocator
,
DT_UINT8
);
input_tensor
.
Resize
({
1
,
1
,
1
,
5
});
output_tensor
.
Resize
({
1
,
1
,
1
,
5
});
uint8_t
*
input_data
=
input_tensor
.
mutable_data
<
uint8_t
>
();
const
uint8_t
*
output_data
=
output_tensor
.
data
<
uint8_t
>
();
// -100.0 -50.0 0 50.0 100.0 -> s=0.782, q0=int(-fmin/s)=128,
// q=q0+f/s -> 0, 64, 128, 192, 256
input_data
[
0
]
=
0
;
input_data
[
1
]
=
64
;
input_data
[
2
]
=
128
;
input_data
[
3
]
=
192
;
input_data
[
4
]
=
255
;
// 0, 0, 0, 50, 100 -> s=0.782, q0=128
// q -> 128, 128, 128, 192, 255
VLOG
(
0
)
<<
wrapper
.
ExecuteGraph
(
input_tensor
,
&
output_tensor
);
wrapper
.
PrintLog
();
for
(
int
i
=
0
;
i
<
output_tensor
.
size
();
++
i
)
{
std
::
cout
<<
(
int32_t
)
output_data
[
i
]
<<
" "
;
}
std
::
cout
<<
std
::
endl
;
VLOG
(
0
)
<<
wrapper
.
TeardownGraph
();
wrapper
.
Finalize
();
}
\ No newline at end of file
mace/python/tools/tf_dsp_converter_lib.py
浏览文件 @
5783680a
...
...
@@ -147,7 +147,7 @@ def convert_ops(unresolved_ops, resolved_ops, net_def, output_node, dsp_ops):
def
add_output_node
(
net_def
,
output_node
):
op_def
=
net_def
.
op
.
add
()
op_def
.
name
=
'
output
'
op_def
.
name
=
'
__output__
'
op_def
.
type
=
'OUTPUT'
op_def
.
input
.
extend
([
get_tensor_name_from_op
(
output_node
,
0
)])
...
...
@@ -298,8 +298,8 @@ def convert_to_mace_pb(input_graph_def, input_node, output_node):
add_output_node
(
net_def
,
output_node
)
# optimized_net_def = reverse_batch_to_space_and_biasadd(net_def)
# sorted_net_def = graph_util.sort_mace_graph(optimized_net_def, output_node
)
net_def_with_node_id
=
add_node_id
(
net_def
)
sorted_net_def
=
graph_util
.
sort_mace_graph
(
net_def
,
'__output__'
)
net_def_with_node_id
=
add_node_id
(
sorted_
net_def
)
final_net_def
=
add_input_output_info
(
net_def_with_node_id
,
input_node
,
output_node
,
graph
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录