Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
冰之2023
Mace
提交
61f2e9d5
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,发现更多精彩内容 >>
提交
61f2e9d5
编写于
12月 05, 2017
作者:
L
Liangliang He
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change resize bilinear output size from tensor to attributes
上级
1ec7e0d9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
17 addition
and
41 deletion
+17
-41
mace/kernels/opencl/resize_bilinear_opencl.cc
mace/kernels/opencl/resize_bilinear_opencl.cc
+3
-4
mace/kernels/resize_bilinear.h
mace/kernels/resize_bilinear.h
+11
-26
mace/ops/resize_bilinear.h
mace/ops/resize_bilinear.h
+1
-4
mace/ops/resize_bilinear_test.cc
mace/ops/resize_bilinear_test.cc
+2
-7
未找到文件。
mace/kernels/opencl/resize_bilinear_opencl.cc
浏览文件 @
61f2e9d5
...
...
@@ -13,7 +13,7 @@ namespace kernels {
template
<
typename
T
>
void
ResizeBilinearFunctor
<
DeviceType
::
OPENCL
,
T
>::
operator
()(
const
Tensor
*
input
,
const
Tensor
*
resize_dims
,
Tensor
*
output
)
{
const
Tensor
*
input
,
Tensor
*
output
)
{
const
index_t
batch
=
input
->
dim
(
0
);
const
index_t
in_height
=
input
->
dim
(
1
);
const
index_t
in_width
=
input
->
dim
(
2
);
...
...
@@ -21,9 +21,8 @@ void ResizeBilinearFunctor<DeviceType::OPENCL, T>::operator()(
const
index_t
channel_blocks
=
RoundUpDiv4
(
channels
);
index_t
out_height
;
index_t
out_width
;
GetOutputSize
(
resize_dims
,
&
out_height
,
&
out_width
);
index_t
out_height
=
out_height_
;
index_t
out_width
=
out_width_
;
MACE_CHECK
(
out_height
>
0
&&
out_width
>
0
);
std
::
vector
<
index_t
>
output_shape
{
batch
,
out_height
,
out_width
,
channels
};
if
(
input
->
is_image
())
{
...
...
mace/kernels/resize_bilinear.h
浏览文件 @
61f2e9d5
...
...
@@ -105,26 +105,16 @@ void ResizeImage(const T *images,
struct
ResizeBilinearFunctorBase
{
ResizeBilinearFunctorBase
(
const
std
::
vector
<
index_t
>
&
size
,
bool
align_corners
)
:
align_corners_
(
align_corners
),
size_
(
size
)
{}
:
align_corners_
(
align_corners
)
{
MACE_CHECK
(
size
.
size
()
==
2
);
out_height_
=
size
[
0
];
out_width_
=
size
[
1
];
}
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
<
int32_t
>
();
*
out_height
=
dims_data
[
0
];
*
out_width
=
dims_data
[
1
];
}
else
{
*
out_height
=
size_
[
0
];
*
out_width
=
size_
[
1
];
}
}
bool
align_corners_
;
std
::
vector
<
index_t
>
size_
;
index_t
out_height_
;
index_t
out_width_
;
};
template
<
DeviceType
D
,
typename
T
>
...
...
@@ -132,17 +122,14 @@ struct ResizeBilinearFunctor : ResizeBilinearFunctorBase {
ResizeBilinearFunctor
(
const
std
::
vector
<
index_t
>
&
size
,
bool
align_corners
)
:
ResizeBilinearFunctorBase
(
size
,
align_corners
)
{}
void
operator
()(
const
Tensor
*
input
,
const
Tensor
*
resize_dims
,
Tensor
*
output
)
{
void
operator
()(
const
Tensor
*
input
,
Tensor
*
output
)
{
const
index_t
batch
=
input
->
dim
(
0
);
const
index_t
in_height
=
input
->
dim
(
1
);
const
index_t
in_width
=
input
->
dim
(
2
);
const
index_t
channels
=
input
->
dim
(
3
);
index_t
out_height
;
index_t
out_width
;
GetOutputSize
(
resize_dims
,
&
out_height
,
&
out_width
);
index_t
out_height
=
out_height_
;
index_t
out_width
=
out_width_
;
MACE_CHECK
(
out_height
>
0
&&
out_width
>
0
);
std
::
vector
<
index_t
>
out_shape
{
batch
,
out_height
,
out_width
,
channels
};
output
->
Resize
(
out_shape
);
...
...
@@ -180,9 +167,7 @@ struct ResizeBilinearFunctor<DeviceType::OPENCL, T> : ResizeBilinearFunctorBase
ResizeBilinearFunctor
(
const
std
::
vector
<
index_t
>
&
size
,
bool
align_corners
)
:
ResizeBilinearFunctorBase
(
size
,
align_corners
)
{}
void
operator
()(
const
Tensor
*
input
,
const
Tensor
*
resize_dims
,
Tensor
*
output
);
void
operator
()(
const
Tensor
*
input
,
Tensor
*
output
);
};
}
// namespace kernels
...
...
mace/ops/resize_bilinear.h
浏览文件 @
61f2e9d5
...
...
@@ -21,15 +21,12 @@ class ResizeBilinearOp : public Operator<D, T> {
bool
Run
()
override
{
const
Tensor
*
input
=
this
->
Input
(
0
);
const
Tensor
*
resize_dims
=
this
->
Input
(
1
);
Tensor
*
output
=
this
->
Output
(
0
);
MACE_CHECK
(
input
->
dim_size
()
==
4
,
"input must be 4-dimensional."
,
input
->
dim_size
());
MACE_CHECK
(
resize_dims
->
dim_size
()
==
1
,
"resize dim must be 2-dimensional."
,
resize_dims
->
dim_size
());
functor_
(
input
,
resize_dims
,
output
);
functor_
(
input
,
output
);
return
true
;
}
...
...
mace/ops/resize_bilinear_test.cc
浏览文件 @
61f2e9d5
...
...
@@ -16,15 +16,14 @@ TEST_F(ResizeBilinearTest, CPUResizeBilinearWOAlignCorners) {
auto
&
net
=
test_net
();
OpDefBuilder
(
"ResizeBilinear"
,
"ResizeBilinearTest"
)
.
Input
(
"Input"
)
.
Input
(
"OutSize"
)
.
Output
(
"Output"
)
.
AddIntsArg
(
"size"
,
{
1
,
2
})
.
Finalize
(
net
.
NewOperatorDef
());
// Add input data
vector
<
float
>
input
(
24
);
std
::
iota
(
begin
(
input
),
end
(
input
),
0
);
net
.
AddInputFromArray
<
DeviceType
::
CPU
,
float
>
(
"Input"
,
{
1
,
2
,
4
,
3
},
input
);
net
.
AddInputFromArray
<
DeviceType
::
CPU
,
int
>
(
"OutSize"
,
{
2
},
{
1
,
2
});
// Run
net
.
RunOp
();
...
...
@@ -41,16 +40,15 @@ TEST_F(ResizeBilinearTest, ResizeBilinearWAlignCorners) {
auto
&
net
=
test_net
();
OpDefBuilder
(
"ResizeBilinear"
,
"ResizeBilinearTest"
)
.
Input
(
"Input"
)
.
Input
(
"OutSize"
)
.
Output
(
"Output"
)
.
AddIntArg
(
"align_corners"
,
1
)
.
AddIntsArg
(
"size"
,
{
1
,
2
})
.
Finalize
(
net
.
NewOperatorDef
());
// Add input data
vector
<
float
>
input
(
24
);
std
::
iota
(
begin
(
input
),
end
(
input
),
0
);
net
.
AddInputFromArray
<
DeviceType
::
CPU
,
float
>
(
"Input"
,
{
1
,
2
,
4
,
3
},
input
);
net
.
AddInputFromArray
<
DeviceType
::
CPU
,
int
>
(
"OutSize"
,
{
2
},
{
1
,
2
});
// Run
net
.
RunOp
();
...
...
@@ -80,11 +78,9 @@ void TestRandomResizeBilinear() {
// Add input data
net
.
AddRandomInput
<
D
,
float
>
(
"Input"
,
{
batch
,
in_height
,
in_width
,
channels
});
net
.
AddInputFromArray
<
D
,
int
>
(
"OutSize"
,
{
2
},
{
height
,
width
});
OpDefBuilder
(
"ResizeBilinear"
,
"ResizeBilinearTest"
)
.
Input
(
"Input"
)
.
Input
(
"OutSize"
)
.
Output
(
"Output"
)
.
AddIntArg
(
"align_corners"
,
align_corners
)
.
AddIntsArg
(
"size"
,
{
height
,
width
})
...
...
@@ -99,7 +95,6 @@ void TestRandomResizeBilinear() {
OpDefBuilder
(
"ResizeBilinear"
,
"ResizeBilinearTest"
)
.
Input
(
"InputImage"
)
.
Input
(
"OutSize"
)
.
Output
(
"OutputImage"
)
.
AddIntArg
(
"align_corners"
,
align_corners
)
.
AddIntsArg
(
"size"
,
{
height
,
width
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录