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
12e9c7d5
Commit
12e9c7d5
authored
Jul 11, 2018
by
Scott Thornton
Browse files
Formatting
parent
056c6fe2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
8 deletions
+10
-8
src/onnx/mnist.cpp
src/onnx/mnist.cpp
+9
-7
test/cpu_ops_test.cpp
test/cpu_ops_test.cpp
+1
-1
No files found.
src/onnx/mnist.cpp
View file @
12e9c7d5
...
...
@@ -38,7 +38,7 @@ std::vector<float> read_mnist_images(std::string full_path, int& number_of_image
file
.
read
(
reinterpret_cast
<
char
*>
(
&
number_of_images
),
sizeof
(
number_of_images
));
number_of_images
=
reverse_int
(
number_of_images
);
file
.
read
(
reinterpret_cast
<
char
*>
(
&
n_rows
),
sizeof
(
n_rows
));
file
.
read
(
reinterpret_cast
<
char
*>
(
&
n_rows
),
sizeof
(
n_rows
));
n_rows
=
reverse_int
(
n_rows
);
file
.
read
(
reinterpret_cast
<
char
*>
(
&
n_cols
),
sizeof
(
n_cols
));
n_cols
=
reverse_int
(
n_cols
);
...
...
@@ -96,12 +96,13 @@ std::vector<int32_t> read_mnist_labels(std::string full_path, int& number_of_lab
}
}
std
::
vector
<
float
>
softmax
(
std
::
vector
<
float
>
p
)
{
std
::
vector
<
float
>
softmax
(
std
::
vector
<
float
>
p
)
{
size_t
n
=
p
.
size
();
std
::
vector
<
float
>
result
(
n
);
std
::
transform
(
p
.
begin
(),
p
.
end
(),
result
.
begin
(),
[]
(
auto
x
)
{
return
std
::
exp
(
x
);});
std
::
transform
(
p
.
begin
(),
p
.
end
(),
result
.
begin
(),
[](
auto
x
)
{
return
std
::
exp
(
x
);
});
float
s
=
std
::
accumulate
(
result
.
begin
(),
result
.
end
(),
0.0
f
,
std
::
plus
<
float
>
());
std
::
transform
(
result
.
begin
(),
result
.
end
(),
result
.
begin
(),
[
=
]
(
auto
x
)
{
return
x
/
s
;});
std
::
transform
(
result
.
begin
(),
result
.
end
(),
result
.
begin
(),
[
=
](
auto
x
)
{
return
x
/
s
;
});
return
result
;
}
...
...
@@ -123,15 +124,16 @@ int main(int argc, char const* argv[])
auto
s
=
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
1
,
1
,
28
,
28
}};
std
::
cout
<<
s
<<
std
::
endl
;
auto
ptr
=
input
.
data
();
for
(
int
i
=
0
;
i
<
20
;
i
++
)
for
(
int
i
=
0
;
i
<
20
;
i
++
)
{
std
::
cout
<<
"label: "
<<
labels
[
i
]
<<
" ----> "
;
auto
input3
=
migraph
::
argument
{
s
,
&
ptr
[
784
*
i
]};
auto
input3
=
migraph
::
argument
{
s
,
&
ptr
[
784
*
i
]};
auto
result
=
prog
.
eval
({{
"Input3"
,
input3
}});
std
::
vector
<
float
>
logits
;
result
.
visit
([
&
](
auto
output
)
{
logits
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
probs
=
softmax
(
logits
);
for
(
auto
x
:
probs
)
std
::
cout
<<
x
<<
" "
;
for
(
auto
x
:
probs
)
std
::
cout
<<
x
<<
" "
;
std
::
cout
<<
std
::
endl
;
}
std
::
cout
<<
std
::
endl
;
...
...
test/cpu_ops_test.cpp
View file @
12e9c7d5
...
...
@@ -621,7 +621,7 @@ int main()
transpose_test
();
contiguous_test
();
softmax_test
();
//maxpool_test();
//
maxpool_test();
conv2d_test
();
conv2d_padding_test
();
conv2d_padding_stride_test
();
...
...
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