Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
Mace
提交
f39cc3ce
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看板
提交
f39cc3ce
编写于
2月 18, 2019
作者:
李
李寅
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'nan' into 'master'
Avoid dividing by zero for cosine similarity See merge request !985
上级
1be8257c
1783d8f3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
18 addition
and
17 deletion
+18
-17
mace/core/runtime/hexagon/hexagon_control_wrapper.cc
mace/core/runtime/hexagon/hexagon_control_wrapper.cc
+9
-12
mace/ops/testing/test_utils.h
mace/ops/testing/test_utils.h
+9
-5
未找到文件。
mace/core/runtime/hexagon/hexagon_control_wrapper.cc
浏览文件 @
f39cc3ce
...
...
@@ -238,9 +238,8 @@ bool HexagonControlWrapper::SetupGraph(const NetDef &net_def,
// input info
num_inputs_
=
0
;
for
(
const
InputInfo
&
input_info
:
net_def
.
input_info
())
{
std
::
vector
<
index_t
>
input_shape
;
input_shape
.
insert
(
input_shape
.
begin
(),
input_info
.
dims
().
begin
(),
input_info
.
dims
().
end
());
std
::
vector
<
index_t
>
input_shape
(
input_info
.
dims
().
begin
(),
input_info
.
dims
().
end
());
while
(
input_shape
.
size
()
<
4
)
{
input_shape
.
insert
(
input_shape
.
begin
(),
1
);
}
...
...
@@ -252,9 +251,8 @@ bool HexagonControlWrapper::SetupGraph(const NetDef &net_def,
// output info
num_outputs_
=
0
;
for
(
const
OutputInfo
&
output_info
:
net_def
.
output_info
())
{
std
::
vector
<
index_t
>
output_shape
;
output_shape
.
insert
(
output_shape
.
begin
(),
output_info
.
dims
().
begin
(),
output_info
.
dims
().
end
());
std
::
vector
<
index_t
>
output_shape
(
output_info
.
dims
().
begin
(),
output_info
.
dims
().
end
());
while
(
output_shape
.
size
()
<
4
)
{
output_shape
.
insert
(
output_shape
.
begin
(),
1
);
}
...
...
@@ -478,12 +476,11 @@ bool HexagonControlWrapper::ExecuteGraphNew(
&
outputs
[
index
+
3
]);
}
int
res
=
hexagon_nn_execute_new
(
nn_id_
,
inputs
.
data
(),
num_inputs
*
NUM_METADATA
,
outputs
.
data
(),
num_outputs
*
NUM_METADATA
);
int
res
=
hexagon_nn_execute_new
(
nn_id_
,
inputs
.
data
(),
num_inputs
*
NUM_METADATA
,
outputs
.
data
(),
num_outputs
*
NUM_METADATA
);
for
(
size_t
i
=
0
;
i
<
num_outputs
;
++
i
)
{
size_t
index
=
i
*
NUM_METADATA
;
...
...
mace/ops/testing/test_utils.h
浏览文件 @
f39cc3ce
...
...
@@ -138,6 +138,7 @@ inline bool IsSameSize(const Tensor &x, const Tensor &y) {
inline
std
::
string
ShapeToString
(
const
Tensor
&
x
)
{
std
::
stringstream
stream
;
stream
<<
"["
;
for
(
int
i
=
0
;
i
<
x
.
dim_size
();
i
++
)
{
if
(
i
>
0
)
stream
<<
","
;
int64_t
dim
=
x
.
dim
(
i
);
...
...
@@ -174,8 +175,8 @@ inline void ExpectEqual<double>(const double &a, const double &b) {
}
inline
void
AssertSameDims
(
const
Tensor
&
x
,
const
Tensor
&
y
)
{
ASSERT_TRUE
(
IsSameSize
(
x
,
y
))
<<
"x.shape
["
<<
ShapeToString
(
x
)
<<
"]
vs "
<<
"y.shape
[ "
<<
ShapeToString
(
y
)
<<
"]"
;
ASSERT_TRUE
(
IsSameSize
(
x
,
y
))
<<
"x.shape
"
<<
ShapeToString
(
x
)
<<
"
vs "
<<
"y.shape
"
<<
ShapeToString
(
y
)
;
}
template
<
typename
EXP_TYPE
,
...
...
@@ -282,7 +283,7 @@ void ExpectTensorNear(const Tensor &x,
template
<
typename
T
>
void
ExpectTensorSimilar
(
const
Tensor
&
x
,
const
Tensor
&
y
,
const
double
abs
_err
=
1e-5
)
{
const
double
rel
_err
=
1e-5
)
{
AssertSameDims
(
x
,
y
);
Tensor
::
MappingGuard
x_mapper
(
&
x
);
Tensor
::
MappingGuard
y_mapper
(
&
y
);
...
...
@@ -294,8 +295,11 @@ void ExpectTensorSimilar(const Tensor &x,
x_norm
+=
x_data
[
i
]
*
x_data
[
i
];
y_norm
+=
y_data
[
i
]
*
y_data
[
i
];
}
double
similarity
=
dot_product
/
(
sqrt
(
x_norm
)
*
sqrt
(
y_norm
));
EXPECT_NEAR
(
1.0
,
similarity
,
abs_err
);
double
norm_product
=
sqrt
(
x_norm
)
*
sqrt
(
y_norm
);
double
error
=
rel_err
*
std
::
abs
(
dot_product
);
EXPECT_NEAR
(
dot_product
,
norm_product
,
error
)
<<
"Shape "
<<
ShapeToString
(
x
);
}
}
// namespace test
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录