Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
08b3f215
Commit
08b3f215
authored
Jul 03, 2019
by
Shucai Xiao
Browse files
add onnx test for reduce_mean
parent
1644d4fc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
2 deletions
+36
-2
src/onnx/onnx.cpp
src/onnx/onnx.cpp
+34
-0
test/onnx/onnx_test.cpp
test/onnx/onnx_test.cpp
+2
-2
No files found.
src/onnx/onnx.cpp
View file @
08b3f215
...
...
@@ -96,6 +96,7 @@ struct onnx_parser
add_mem_op
(
"LSTM"
,
&
onnx_parser
::
parse_lstm
);
add_mem_op
(
"Pad"
,
&
onnx_parser
::
parse_pad
);
add_mem_op
(
"ReduceSum"
,
&
onnx_parser
::
parse_reduce_sum
);
add_mem_op
(
"ReduceMean"
,
&
onnx_parser
::
parse_reduce_mean
);
// init the activation function map
init_actv_func
();
...
...
@@ -1321,6 +1322,39 @@ struct onnx_parser
}
}
instruction_ref
parse_reduce_mean
(
const
std
::
string
&
,
attribute_map
attributes
,
std
::
vector
<
instruction_ref
>
args
)
{
std
::
size_t
n_dim
=
args
.
front
()
->
get_shape
().
lens
().
size
();
// default to reduce over all dimensions
std
::
vector
<
int64_t
>
axes
(
n_dim
);
std
::
iota
(
axes
.
begin
(),
axes
.
end
(),
0
);
if
(
contains
(
attributes
,
"axes"
))
{
axes
.
clear
();
auto
&&
attr_axes
=
attributes
[
"axes"
].
ints
();
axes
=
std
::
vector
<
int64_t
>
(
attr_axes
.
begin
(),
attr_axes
.
end
());
}
int
keep_dims
=
1
;
if
(
contains
(
attributes
,
"keepdims"
))
{
keep_dims
=
parse_value
(
attributes
.
at
(
"keepdims"
)).
at
<
int
>
();
}
if
(
keep_dims
==
1
)
{
return
prog
.
add_instruction
(
op
::
reduce_mean
{
axes
},
std
::
move
(
args
));
}
else
{
auto
ins
=
prog
.
add_instruction
(
op
::
reduce_mean
{
axes
},
std
::
move
(
args
));
return
prog
.
add_instruction
(
op
::
squeeze
{
axes
},
ins
);
}
}
void
parse_from
(
std
::
istream
&
is
)
{
onnx
::
ModelProto
model
;
...
...
test/onnx/onnx_test.cpp
View file @
08b3f215
...
...
@@ -862,8 +862,8 @@ TEST_CASE(reducemean_test1)
TEST_CASE
(
reducemean_test2
)
{
migraphx
::
program
p
;
auto
l0
=
p
.
add_parameter
(
"x"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
3
,
4
,
5
,
6
}});
auto
l1
=
p
.
add_instruction
(
migraphx
::
op
::
reduce_
sum
{{
2
}},
l0
);
auto
l0
=
p
.
add_parameter
(
"x"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
3
,
4
,
5
,
6
}});
p
.
add_instruction
(
migraphx
::
op
::
reduce_
mean
{{
2
}},
l0
);
auto
prog
=
migraphx
::
parse_onnx
(
"reducemean_test2.onnx"
);
EXPECT
(
p
==
prog
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment