Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
NanoSoC Testboard SDK
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
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SoCLabs
NanoSoC Testboard SDK
Commits
ed4d9aeb
Commit
ed4d9aeb
authored
Sep 9, 2024
by
Fanis Baikas
Browse files
Options
Downloads
Patches
Plain Diff
Changed names of data files paths and added colour to classification results
parent
e9f230e1
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#11598
passed
Sep 9, 2024
Stage: build
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
nanosoc_board/C_Cxx/fast_knn_demo/fast_knn_demo.cpp
+30
-17
30 additions, 17 deletions
nanosoc_board/C_Cxx/fast_knn_demo/fast_knn_demo.cpp
with
30 additions
and
17 deletions
nanosoc_board/C_Cxx/fast_knn_demo/fast_knn_demo.cpp
+
30
−
17
View file @
ed4d9aeb
...
...
@@ -40,6 +40,7 @@ PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr);
Pen
BG
=
graphics
.
create_pen
(
0
,
0
,
0
);
Pen
WHITE
=
graphics
.
create_pen
(
255
,
255
,
255
);
Pen
RED
=
graphics
.
create_pen
(
255
,
0
,
0
);
Pen
GREEN
=
graphics
.
create_pen
(
0
,
255
,
0
);
bool
BUTTON_Y_pressed
=
false
;
bool
BUTTON_X_pressed
=
false
;
int
x
=
0
;
...
...
@@ -56,18 +57,23 @@ std::string console[CONSOLE_FIFO_DEPTH];
#define DATA_SENT_GPIO_PIN 3
#define NUM_UNLABELLED_IMGS 36
#define NUM_LABELLED_IMGS 1
3
0
#define NUM_LABELLED_IMGS 1
5
0
#define NUM_OF_CLASSES 10
#define NUM_LABELLED_IMAGES_PER_CLASS NUM_LABELLED_IMGS/NUM_OF_CLASSES
#define kNN_k 5
// String arrays that hold the names of image data files
std
::
string
labelled_files
[
NUM_OF_CLASSES
][
NUM_LABELLED_IMAGES_PER_CLASS
];
std
::
string
unlabelled_files
[
NUM_UNLABELLED_IMGS
];
// Image data buffers
uint8_t
unlabelled_buffer
[
NUM_UNLABELLED_IMGS
][
784
];
uint8_t
labelled_buffer
[
NUM_LABELLED_IMGS
][
784
];
// Image label buffers
uint8_t
labelled_imgs_labels
[
NUM_LABELLED_IMGS
];
uint8_t
test_imgs_labels
[
NUM_UNLABELLED_IMGS
];
// Nanosoc image buffer address
int
nanosoc_img_buffer_addr
;
...
...
@@ -84,19 +90,19 @@ uintptr_t sw_reset_reg_addr = FAST_KNN_REGS_BASE + offsetof(FAST_KNN_regs_typede
// Path to labelled images
std
::
string
labelled_image_dirs
[
10
]
=
{
"./
data/labelled_images/image0
"
,
"./
data/labelled_images/image1
"
,
"./
data/labelled_images/image2
"
,
"./
data/labelled_images/image3
"
,
"./
data/labelled_images/image4
"
,
"./
data/labelled_images/image5
"
,
"./
data/labelled_images/image6
"
,
"./
data/labelled_images/image7
"
,
"./
data/labelled_images/image8
"
,
"./
data/labelled_images/image9
"
};
"./
fmnist_data/train/0_t-shirt_top
"
,
"./
fmnist_data/train/1_trouser
"
,
"./
fmnist_data/train/2_pullover
"
,
"./
fmnist_data/train/3_dress
"
,
"./
fmnist_data/train/4_coat
"
,
"./
fmnist_data/train/5_sandal
"
,
"./
fmnist_data/train/6_shirt
"
,
"./
fmnist_data/train/7_sneaker
"
,
"./
fmnist_data/train/8_bag
"
,
"./
fmnist_data/train/9_ankle_boot
"
};
// Path to unlabelled images
std
::
string
unlabelled_image_dir
=
"0:/
data/unlabelled_imag
es"
;
std
::
string
unlabelled_image_dir
=
"0:/
fmnist_data/t
es
t
"
;
std
::
string
classes
[]
=
{
"T-Shirt"
,
...
...
@@ -345,7 +351,11 @@ void DEMO_ROUTINE(){
result_location
.
y
=
img_y_grid
[
ytext
]
+
60
;
// KNN finished, plot the result
graphics
.
set_pen
(
WHITE
);
if
(
predicted_label
==
test_imgs_labels
[
current_unlab_img
-
1
])
graphics
.
set_pen
(
GREEN
);
else
graphics
.
set_pen
(
RED
);
graphics
.
text
(
classes
[
predicted_label
],
result_location
,
result_location
.
x
+
56
);
xtext
++
;
if
(
xtext
>=
3
){
...
...
@@ -650,7 +660,10 @@ int main() {
char
fil_buf
[
8
]
=
""
;
char
*
pEnd
;
int
k
=
0
;
printf
(
"File name: %s, Unlabelled img %u
\n
"
,
unlabelled_files
[
i
].
c_str
(),
i
);
// Parse ground truth label of test image
sscanf
(
unlabelled_files
[
i
].
c_str
(),
"%hhu_*.txt"
,
&
test_imgs_labels
[
i
]);
printf
(
"File name: %s, Unlabelled img %u, label: %hhu
\n
"
,
unlabelled_files
[
i
].
c_str
(),
i
,
test_imgs_labels
[
i
]);
while
(
f_gets
(
fil_buf
,
8
,
&
fil
)){
unlabelled_buffer
[
i
][
k
]
=
strtol
(
fil_buf
,
&
pEnd
,
16
);
// printf("0x%02x ", unlabelled_buffer[j][k]);
...
...
@@ -669,9 +682,9 @@ int main() {
// Download program to nanosoc
f_chdir
(
"./programs"
);
fr
=
f_open
(
&
fil
,
"
te
st_
gpio
.hex"
,
FA_READ
);
fr
=
f_open
(
&
fil
,
"
fa
st_
knn
.hex"
,
FA_READ
);
if
(
FR_OK
!=
fr
&&
FR_EXIST
!=
fr
){
printf
(
"f_open(
te
st_
gpio
.hex) error: %s (%d)
\n
"
,
FRESULT_str
(
fr
),
fr
);
printf
(
"f_open(
fa
st_
knn
.hex) error: %s (%d)
\n
"
,
FRESULT_str
(
fr
),
fr
);
printf
(
"Can't open demo program. Is SD card inserted?
\n
"
);
return
1
;
}
...
...
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