Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
Mace
提交
e8d5b186
Mace
项目概览
Xiaomi
/
Mace
通知
107
Star
40
Fork
27
代码
文件
提交
分支
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看板
提交
e8d5b186
编写于
2月 15, 2019
作者:
刘
刘托
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' into 'master'
Fix prior_box bug and delete reshape gpu register See merge request !982
上级
a7e5f64e
15754850
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
48 addition
and
68 deletion
+48
-68
mace/ops/prior_box.cc
mace/ops/prior_box.cc
+20
-24
mace/ops/prior_box_benchmark.cc
mace/ops/prior_box_benchmark.cc
+11
-13
mace/ops/prior_box_test.cc
mace/ops/prior_box_test.cc
+1
-2
mace/ops/reshape.cc
mace/ops/reshape.cc
+0
-21
mace/python/tools/converter_tool/caffe_converter.py
mace/python/tools/converter_tool/caffe_converter.py
+14
-3
mace/python/tools/converter_tool/shape_inference.py
mace/python/tools/converter_tool/shape_inference.py
+2
-5
未找到文件。
mace/ops/prior_box.cc
浏览文件 @
e8d5b186
...
...
@@ -31,7 +31,6 @@ class PriorBoxOp : public Operation {
min_size_
(
Operation
::
GetRepeatedArgs
<
float
>
(
"min_size"
)),
max_size_
(
Operation
::
GetRepeatedArgs
<
float
>
(
"max_size"
)),
aspect_ratio_
(
Operation
::
GetRepeatedArgs
<
float
>
(
"aspect_ratio"
)),
flip_
(
Operation
::
GetOptionalArg
<
bool
>
(
"flip"
,
true
)),
clip_
(
Operation
::
GetOptionalArg
<
bool
>
(
"clip"
,
false
)),
variance_
(
Operation
::
GetRepeatedArgs
<
float
>
(
"variance"
)),
offset_
(
Operation
::
GetOptionalArg
<
float
>
(
"offset"
,
0.5
))
{}
...
...
@@ -43,28 +42,30 @@ class PriorBoxOp : public Operation {
Tensor
*
output
=
this
->
Output
(
OUTPUT
);
const
std
::
vector
<
index_t
>
&
input_shape
=
input
->
shape
();
const
std
::
vector
<
index_t
>
&
data_shape
=
data
->
shape
();
const
index_t
input_w
=
input_shape
[
3
];
const
index_t
input_h
=
input_shape
[
2
];
const
index_t
i
mage_w
=
data
_shape
[
3
];
const
index_t
i
nput_w
=
input
_shape
[
3
];
const
index_t
image_h
=
data_shape
[
2
];
float
step_h
=
static_cast
<
float
>
(
image_h
)
/
static_cast
<
float
>
(
input_h
)
;
float
step_
w
=
static_cast
<
float
>
(
image_w
)
/
static_cast
<
float
>
(
input_w
);
if
(
Operation
::
GetOptionalArg
<
float
>
(
"step_h"
,
0
)
!=
0
&&
Operation
::
GetOptionalArg
<
float
>
(
"step_w"
,
0
)
!=
0
)
{
step_h
=
Operation
::
GetOptionalArg
<
float
>
(
"step_h"
,
0
);
step_w
=
Operation
::
GetOptionalArg
<
float
>
(
"step_w"
,
0
);
const
index_t
image_w
=
data_shape
[
3
]
;
float
step_
h
=
Operation
::
GetOptionalArg
<
float
>
(
"step_h"
,
0
);
float
step_w
=
Operation
::
GetOptionalArg
<
float
>
(
"step_w"
,
0
);
if
(
step_h
<=
1e-6
||
step_w
<=
1e-6
)
{
step_h
=
static_cast
<
float
>
(
image_h
)
/
static_cast
<
float
>
(
input_h
);
step_w
=
static_cast
<
float
>
(
image_w
)
/
static_cast
<
float
>
(
input_w
);
}
const
index_t
num_min_size
=
min_size_
.
size
();
MACE_CHECK
(
num_min_size
>
0
,
"min_size is required!"
);
const
index_t
num_max_size
=
max_size_
.
size
();
const
index_t
num_aspect_ratio
=
aspect_ratio_
.
size
();
MACE_CHECK
(
num_aspect_ratio
>
0
,
"aspect_ratio is required!"
);
index_t
num_prior
=
num_min_size
*
num_aspect_ratio
+
num_min_size
+
num_max_size
;
if
(
flip_
)
num_prior
+=
num_min_size
*
num_aspect_ratio
;
index_t
num_prior
=
num_min_size
*
num_aspect_ratio
;
if
(
num_max_size
>
0
)
{
MACE_CHECK
(
max_size_
.
size
()
==
min_size_
.
size
());
for
(
size_t
i
=
0
;
i
<
max_size_
.
size
();
++
i
)
{
MACE_CHECK
(
max_size_
[
i
]
>
min_size_
[
i
],
"max_size must be greater than min_size."
);
num_prior
+=
1
;
}
}
index_t
dim
=
4
*
input_w
*
input_h
*
num_prior
;
std
::
vector
<
index_t
>
output_shape
=
{
1
,
2
,
dim
};
...
...
@@ -79,7 +80,7 @@ class PriorBoxOp : public Operation {
float
center_x
=
(
offset_
+
j
)
*
step_w
;
for
(
index_t
k
=
0
;
k
<
num_min_size
;
++
k
)
{
float
min_s
=
min_size_
[
k
];
box_w
=
box_h
=
min_s
*
0.5
;
box_w
=
box_h
=
min_s
*
0.5
f
;
output_data
[
idx
+
0
]
=
(
center_x
-
box_w
)
/
image_w
;
output_data
[
idx
+
1
]
=
(
center_y
-
box_h
)
/
image_h
;
output_data
[
idx
+
2
]
=
(
center_x
+
box_w
)
/
image_w
;
...
...
@@ -96,6 +97,9 @@ class PriorBoxOp : public Operation {
}
for
(
int
l
=
0
;
l
<
num_aspect_ratio
;
++
l
)
{
float
ar
=
aspect_ratio_
[
l
];
if
(
fabsf
(
ar
-
1.
f
)
<
1e-6
)
{
continue
;
}
box_w
=
min_s
*
sqrt
(
ar
)
*
0.5
f
;
box_h
=
min_s
/
sqrt
(
ar
)
*
0.5
f
;
output_data
[
idx
+
0
]
=
(
center_x
-
box_w
)
/
image_w
;
...
...
@@ -103,13 +107,6 @@ class PriorBoxOp : public Operation {
output_data
[
idx
+
2
]
=
(
center_x
+
box_w
)
/
image_w
;
output_data
[
idx
+
3
]
=
(
center_y
+
box_h
)
/
image_h
;
idx
+=
4
;
if
(
flip_
)
{
output_data
[
idx
+
0
]
=
(
center_x
-
box_h
)
/
image_w
;
output_data
[
idx
+
1
]
=
(
center_y
-
box_w
)
/
image_h
;
output_data
[
idx
+
2
]
=
(
center_x
+
box_h
)
/
image_w
;
output_data
[
idx
+
3
]
=
(
center_y
+
box_w
)
/
image_h
;
idx
+=
4
;
}
}
}
}
...
...
@@ -140,7 +137,6 @@ class PriorBoxOp : public Operation {
std
::
vector
<
float
>
min_size_
;
std
::
vector
<
float
>
max_size_
;
std
::
vector
<
float
>
aspect_ratio_
;
bool
flip_
;
bool
clip_
;
std
::
vector
<
float
>
variance_
;
const
float
offset_
;
...
...
mace/ops/prior_box_benchmark.cc
浏览文件 @
e8d5b186
...
...
@@ -15,15 +15,14 @@
#include "mace/core/testing/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace
mace
{
namespace
ops
{
namespace
test
{
namespace
{
template
<
DeviceType
D
,
typename
T
>
template
<
DeviceType
D
,
typename
T
>
void
PriorBox
(
int
iters
,
float
min_size
,
float
max_size
,
float
aspect_ratio
,
int
flip
,
int
iters
,
float
min_size
,
float
max_size
,
float
aspect_ratio
,
int
clip
,
float
variance0
,
float
variance1
,
float
offset
,
int
h
)
{
mace
::
testing
::
StopTiming
();
...
...
@@ -40,7 +39,6 @@ void PriorBox(
.
AddFloatsArg
(
"min_size"
,
{
min_size
})
.
AddFloatsArg
(
"max_size"
,
{
max_size
})
.
AddFloatsArg
(
"aspect_ratio"
,
{
aspect_ratio
})
.
AddIntArg
(
"flip"
,
flip
)
.
AddIntArg
(
"clip"
,
clip
)
.
AddFloatsArg
(
"variance"
,
{
variance0
,
variance0
,
variance1
,
variance1
})
.
AddFloatArg
(
"offset"
,
offset
)
...
...
@@ -59,16 +57,16 @@ void PriorBox(
}
}
// namespace
#define MACE_BM_PRIOR_BOX(MIN, MAX, AR,
FLIP, CLIP, V0, V1, OFFSET, H)
\
static void MACE_BM_PRIOR_BOX_##MIN##_##MAX##_##AR##_##
FLIP##_##CLIP##_##V0##
\
_##V1##_##OFFSET##_##H(int iters) {
\
PriorBox<DeviceType::CPU, float>(iters, MIN, MAX, AR,
FLIP, CLIP, V0, V1,
\
OFFSET, H);
\
}
\
MACE_BENCHMARK(MACE_BM_PRIOR_BOX_##MIN##_##MAX##_##AR##_##
FLIP##_##CLIP##_##
\
V0##_
##V1##_##OFFSET##_##H)
#define MACE_BM_PRIOR_BOX(MIN, MAX, AR,
CLIP, V0, V1, OFFSET, H)
\
static void MACE_BM_PRIOR_BOX_##MIN##_##MAX##_##AR##_##
CLIP##_##V0##_##V1##_
\
##OFFSET##_##H(int iters) {
\
PriorBox<DeviceType::CPU, float>(iters, MIN, MAX, AR,
CLIP, V0, V1,
\
OFFSET, H); \
} \
MACE_BENCHMARK(MACE_BM_PRIOR_BOX_##MIN##_##MAX##_##AR##_##
CLIP##_##V0##_
\
##V1##_##OFFSET##_##H)
MACE_BM_PRIOR_BOX
(
285
,
300
,
2
,
1
,
0
,
1
,
2
,
1
,
128
);
MACE_BM_PRIOR_BOX
(
285
,
300
,
2
,
0
,
1
,
2
,
1
,
128
);
}
// namespace test
}
// namespace ops
...
...
mace/ops/prior_box_test.cc
浏览文件 @
e8d5b186
...
...
@@ -32,8 +32,7 @@ TEST_F(PriorBoxOpTest, Simple) {
.
Output
(
"OUTPUT"
)
.
AddFloatsArg
(
"min_size"
,
{
285
})
.
AddFloatsArg
(
"max_size"
,
{
300
})
.
AddFloatsArg
(
"aspect_ratio"
,
{
2
,
3
})
.
AddIntArg
(
"flip"
,
1
)
.
AddFloatsArg
(
"aspect_ratio"
,
{
1
,
2
,
0.5
,
3
,
0.33333333333
})
.
AddIntArg
(
"clip"
,
0
)
.
AddFloatsArg
(
"variance"
,
{
0.1
,
0.1
,
0.2
,
0.2
})
.
AddFloatArg
(
"offset"
,
0.5
)
...
...
mace/ops/reshape.cc
浏览文件 @
e8d5b186
...
...
@@ -103,27 +103,6 @@ void RegisterReshape(OpRegistryBase *op_registry) {
DeviceType
::
CPU
,
float
);
MACE_REGISTER_OP
(
op_registry
,
"Reshape"
,
ReshapeOp
,
DeviceType
::
CPU
,
int32_t
);
#ifdef MACE_ENABLE_OPENCL
MACE_REGISTER_OP
(
op_registry
,
"Reshape"
,
ReshapeOp
,
DeviceType
::
GPU
,
float
);
MACE_REGISTER_OP
(
op_registry
,
"Reshape"
,
ReshapeOp
,
DeviceType
::
GPU
,
half
);
#endif // MACE_ENABLE_OPENCL
MACE_REGISTER_OP_CONDITION
(
op_registry
,
OpConditionBuilder
(
"Reshape"
)
.
SetDevicePlacerFunc
(
[](
OpConstructContext
*
context
)
->
std
::
set
<
DeviceType
>
{
auto
op
=
context
->
operator_def
();
if
(
op
->
output_shape_size
()
!=
op
->
output_size
())
{
return
{
DeviceType
::
CPU
,
DeviceType
::
GPU
};
}
if
(
op
->
output_shape
(
0
).
dims_size
()
!=
4
)
{
return
{
DeviceType
::
CPU
};
}
return
{
DeviceType
::
CPU
,
DeviceType
::
GPU
};
}));
}
}
// namespace ops
...
...
mace/python/tools/converter_tool/caffe_converter.py
浏览文件 @
e8d5b186
...
...
@@ -717,14 +717,25 @@ class CaffeConverter(base_converter.ConverterInterface):
max_size_arg
=
op
.
arg
.
add
()
max_size_arg
.
name
=
MaceKeyword
.
mace_max_size_str
max_size_arg
.
floats
.
extend
(
list
(
param
.
max_size
))
aspect_ratio_arg
=
op
.
arg
.
add
()
aspect_ratio_arg
.
name
=
MaceKeyword
.
mace_aspect_ratio_str
aspect_ratio_arg
.
floats
.
extend
(
list
(
param
.
aspect_ratio
))
flip_arg
=
op
.
arg
.
add
()
flip_arg
.
name
=
MaceKeyword
.
mace_flip_str
flip_arg
.
i
=
1
if
param
.
HasField
(
'flip'
):
flip_arg
.
i
=
int
(
param
.
flip
)
aspect_ratio
=
[
1.0
]
for
i
in
param
.
aspect_ratio
:
already_exist
=
False
for
ar
in
aspect_ratio
:
if
abs
(
i
-
ar
)
<
1e-6
:
already_exist
=
True
break
if
not
already_exist
:
aspect_ratio
.
append
(
i
)
if
flip_arg
.
i
:
aspect_ratio
.
append
(
1.0
/
i
)
aspect_ratio_arg
=
op
.
arg
.
add
()
aspect_ratio_arg
.
name
=
MaceKeyword
.
mace_aspect_ratio_str
aspect_ratio_arg
.
floats
.
extend
(
list
(
aspect_ratio
))
clip_arg
=
op
.
arg
.
add
()
clip_arg
.
name
=
MaceKeyword
.
mace_clip_str
clip_arg
.
i
=
0
...
...
mace/python/tools/converter_tool/shape_inference.py
浏览文件 @
e8d5b186
...
...
@@ -246,11 +246,8 @@ class ShapeInference(object):
min_size
=
ConverterUtil
.
get_arg
(
op
,
MaceKeyword
.
mace_min_size_str
).
floats
# noqa
max_size
=
ConverterUtil
.
get_arg
(
op
,
MaceKeyword
.
mace_max_size_str
).
floats
# noqa
aspect_ratio
=
ConverterUtil
.
get_arg
(
op
,
MaceKeyword
.
mace_aspect_ratio_str
).
floats
# noqa
flip
=
ConverterUtil
.
get_arg
(
op
,
MaceKeyword
.
mace_flip_str
).
i
# noqa
num_prior
=
(
len
(
min_size
)
*
len
(
aspect_ratio
)
+
len
(
min_size
)
+
len
(
max_size
))
if
flip
:
num_prior
=
num_prior
+
len
(
min_size
)
*
len
(
aspect_ratio
)
num_prior
=
len
(
aspect_ratio
)
*
len
(
min_size
)
+
len
(
max_size
)
output_shape
[
2
]
=
num_prior
*
input_h
*
input_w
*
4
self
.
add_output_shape
(
op
,
[
output_shape
])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录