Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
foss-2024-2-final
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Woosung Cho
foss-2024-2-final
Commits
d9bfa941
Commit
d9bfa941
authored
5 months ago
by
Woosung Cho
Browse files
Options
Downloads
Patches
Plain Diff
arduino code
parent
1366574f
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
easy_mnist.ino
+79
-0
79 additions, 0 deletions
easy_mnist.ino
with
79 additions
and
0 deletions
easy_mnist.ino
0 → 100644
+
79
−
0
View file @
d9bfa941
#include
<Chirale_TensorFlowLite.h>
#include
"tensorflow/lite/micro/all_ops_resolver.h"
#include
"tensorflow/lite/micro/micro_interpreter.h"
#include
"tensorflow/lite/schema/schema_generated.h"
#include
"arduino_model.h"
#include
"mnist_images.h"
const
tflite
::
Model
*
model
=
nullptr
;
tflite
::
MicroInterpreter
*
interpreter
=
nullptr
;
TfLiteTensor
*
input
=
nullptr
;
TfLiteTensor
*
output
=
nullptr
;
constexpr
int
kTensorArenaSize
=
20
*
1024
;
alignas
(
16
)
uint8_t
tensor_arena
[
kTensorArenaSize
];
void
setup
()
{
Serial
.
begin
(
9600
);
while
(
!
Serial
);
model
=
tflite
::
GetModel
(
arduino_model
);
if
(
model
->
version
()
!=
TFLITE_SCHEMA_VERSION
)
{
Serial
.
println
(
"Model provided and schema version are not equal!"
);
while
(
true
);
}
static
tflite
::
AllOpsResolver
resolver
;
static
tflite
::
MicroInterpreter
static_interpreter
(
model
,
resolver
,
tensor_arena
,
kTensorArenaSize
);
interpreter
=
&
static_interpreter
;
TfLiteStatus
allocate_status
=
interpreter
->
AllocateTensors
();
if
(
allocate_status
!=
kTfLiteOk
)
{
Serial
.
println
(
"AllocateTensors() failed"
);
while
(
true
);
}
input
=
interpreter
->
input
(
0
);
output
=
interpreter
->
output
(
0
);
Serial
.
println
(
"Ready for input data."
);
}
void
loop
()
{
if
(
Serial
.
available
()){
String
inputValue
=
Serial
.
readString
();
memcpy
(
input
->
data
.
uint8
,
image2
,
28
*
28
);
TfLiteStatus
invoke_status
=
interpreter
->
Invoke
();
if
(
invoke_status
!=
kTfLiteOk
)
{
Serial
.
println
(
"Invoke failed!"
);
return
;
}
int8_t
max_value
=
output
->
data
.
uint8
[
0
];
int8_t
predicted_digit
=
0
;
for
(
int
i
=
1
;
i
<
10
;
i
++
)
{
if
(
output
->
data
.
uint8
[
i
]
>
max_value
)
{
max_value
=
output
->
data
.
uint8
[
i
];
predicted_digit
=
i
-
1
;
}
}
Serial
.
print
(
"Predicted digit: "
);
Serial
.
println
(
predicted_digit
);
Serial
.
print
(
"Actual digit: "
);
Serial
.
println
(
image2_label
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment