Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
as350144
Mace
提交
65e6f075
Mace
项目概览
as350144
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
2
Star
1
Fork
1
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
65e6f075
编写于
11月 08, 2017
作者:
L
Liangliang He
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add size attributes in resize bilinear op to improve opencl kernel
上级
1998fd46
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
44 addition
and
34 deletion
+44
-34
mace/kernels/opencl/resize_bilinear_opencl.cc
mace/kernels/opencl/resize_bilinear_opencl.cc
+3
-9
mace/kernels/resize_bilinear.h
mace/kernels/resize_bilinear.h
+32
-19
mace/ops/resize_bilinear.h
mace/ops/resize_bilinear.h
+1
-0
mace/ops/resize_bilinear_benchmark.cc
mace/ops/resize_bilinear_benchmark.cc
+1
-0
mace/ops/resize_bilinear_test.cc
mace/ops/resize_bilinear_test.cc
+7
-6
未找到文件。
mace/kernels/opencl/resize_bilinear_opencl.cc
浏览文件 @
65e6f075
...
...
@@ -19,15 +19,9 @@ void ResizeBilinearFunctor<DeviceType::OPENCL, float>::operator()(
index_t
out_height
;
index_t
out_width
;
{
MACE_CHECK
(
resize_dims
->
dim_size
()
==
1
);
Tensor
::
MappingGuard
resize_dims_mapper
(
resize_dims
);
auto
dims_data
=
resize_dims
->
data
<
index_t
>
();
out_height
=
dims_data
[
0
];
out_width
=
dims_data
[
1
];
}
std
::
vector
<
index_t
>
out_shape
{
batch
,
channels
,
out_height
,
out_width
};
GetOutputSize
(
resize_dims
,
&
out_height
,
&
out_width
);
MACE_CHECK
(
out_height
>
0
&&
out_width
>
0
);
std
::
vector
<
index_t
>
out_shape
{
batch
,
channels
,
out_height
,
out_width
};
output
->
Resize
(
out_shape
);
float
height_scale
=
...
...
mace/kernels/resize_bilinear.h
浏览文件 @
65e6f075
//
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#ifndef MACE_KERNELS_RESIZE_BILINEAR_H_
#define MACE_KERNELS_RESIZE_BILINEAR_H_
...
...
@@ -101,30 +100,24 @@ void ResizeImage(const T *images,
}
template
<
DeviceType
D
,
typename
T
>
struct
ResizeBilinearFunctor
{
bool
align_corners_
;
ResizeBilinearFunctor
(
bool
align_corners
)
:
align_corners_
(
align_corners
)
{}
class
ResizeBilinearFunctor
{
public:
ResizeBilinearFunctor
(
const
std
::
vector
<
index_t
>
&
size
,
bool
align_corners
)
:
align_corners_
(
align_corners
),
size_
(
size
)
{}
void
operator
()(
const
Tensor
*
input
,
const
Tensor
*
resize_dims
,
Tensor
*
output
)
{
index_t
n
=
input
->
dim
(
0
);
index_t
channels
=
input
->
dim
(
1
);
index_t
in_height
=
input
->
dim
(
2
);
index_t
in_width
=
input
->
dim
(
3
);
const
index_t
batch
=
input
->
dim
(
0
);
const
index_t
channels
=
input
->
dim
(
1
);
const
index_t
in_height
=
input
->
dim
(
2
);
const
index_t
in_width
=
input
->
dim
(
3
);
index_t
out_height
;
index_t
out_width
;
{
MACE_CHECK
(
resize_dims
->
dim_size
()
==
1
);
Tensor
::
MappingGuard
resize_dims_mapper
(
resize_dims
);
auto
dims_data
=
resize_dims
->
data
<
index_t
>
();
out_height
=
dims_data
[
0
];
out_width
=
dims_data
[
1
];
}
vector
<
index_t
>
out_shape
{
n
,
channels
,
out_height
,
out_width
};
GetOutputSize
(
resize_dims
,
&
out_height
,
&
out_width
);
MACE_CHECK
(
out_height
>
0
&&
out_width
>
0
);
std
::
vector
<
index_t
>
out_shape
{
batch
,
channels
,
out_height
,
out_width
};
output
->
Resize
(
out_shape
);
Tensor
::
MappingGuard
input_mapper
(
input
);
...
...
@@ -150,9 +143,29 @@ struct ResizeBilinearFunctor {
ComputeInterpolationWeights
(
out_height
,
in_height
,
height_scale
,
ys
.
data
());
ComputeInterpolationWeights
(
out_width
,
in_width
,
width_scale
,
xs
.
data
());
ResizeImage
(
input_data
,
n
,
in_height
,
in_width
,
out_height
,
out_width
,
ResizeImage
(
input_data
,
batch
,
in_height
,
in_width
,
out_height
,
out_width
,
channels
,
xs
,
ys
,
output_data
);
}
protected:
void
GetOutputSize
(
const
Tensor
*
resize_dims
,
index_t
*
out_height
,
index_t
*
out_width
)
{
if
(
size_
[
0
]
<
0
||
size_
[
1
]
<
0
)
{
MACE_CHECK
(
resize_dims
!=
nullptr
&&
resize_dims
->
dim_size
()
==
1
);
Tensor
::
MappingGuard
resize_dims_mapper
(
resize_dims
);
auto
dims_data
=
resize_dims
->
data
<
index_t
>
();
*
out_height
=
dims_data
[
0
];
*
out_width
=
dims_data
[
1
];
}
else
{
*
out_height
=
size_
[
0
];
*
out_width
=
size_
[
1
];
}
}
private:
bool
align_corners_
;
std
::
vector
<
index_t
>
size_
;
};
template
<
>
...
...
mace/ops/resize_bilinear.h
浏览文件 @
65e6f075
...
...
@@ -16,6 +16,7 @@ class ResizeBilinearOp : public Operator<D, T> {
ResizeBilinearOp
(
const
OperatorDef
&
operator_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
operator_def
,
ws
),
functor_
(
OperatorBase
::
GetRepeatedArgument
<
index_t
>
(
"size"
,
{
-
1
,
-
1
}),
OperatorBase
::
GetSingleArgument
<
bool
>
(
"align_corners"
,
false
))
{}
bool
Run
()
override
{
...
...
mace/ops/resize_bilinear_benchmark.cc
浏览文件 @
65e6f075
...
...
@@ -23,6 +23,7 @@ static void ResizeBilinearBenchmark(int iters,
.
Input
(
"Input"
)
.
Input
(
"OutSize"
)
.
Output
(
"Output"
)
.
AddIntsArg
(
"size"
,
{
output_height
,
output_width
})
.
Finalize
(
net
.
NewOperatorDef
());
// Add input data
...
...
mace/ops/resize_bilinear_test.cc
浏览文件 @
65e6f075
...
...
@@ -66,12 +66,12 @@ void TestRandomResizeBilinear() {
srand
(
time
(
nullptr
));
testing
::
internal
::
LogToStderr
();
for
(
int
round
=
0
;
round
<
10
;
++
round
)
{
in
dex_
t
batch
=
1
+
rand
()
%
5
;
in
dex_
t
channels
=
1
+
rand
()
%
100
;
in
dex_
t
height
=
1
+
rand
()
%
100
;
in
dex_
t
width
=
1
+
rand
()
%
100
;
in
dex_
t
in_height
=
1
+
rand
()
%
100
;
in
dex_
t
in_width
=
1
+
rand
()
%
100
;
int
batch
=
1
+
rand
()
%
5
;
int
channels
=
1
+
rand
()
%
100
;
int
height
=
1
+
rand
()
%
100
;
int
width
=
1
+
rand
()
%
100
;
int
in_height
=
1
+
rand
()
%
100
;
int
in_width
=
1
+
rand
()
%
100
;
// Construct graph
OpsTestNet
net
;
...
...
@@ -80,6 +80,7 @@ void TestRandomResizeBilinear() {
.
Input
(
"OutSize"
)
.
Output
(
"Output"
)
.
AddIntArg
(
"align_corners"
,
1
)
.
AddIntsArg
(
"size"
,
{
height
,
width
})
.
Finalize
(
net
.
NewOperatorDef
());
// Add input data
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录