-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.cpp
More file actions
48 lines (39 loc) · 1.28 KB
/
main.cpp
File metadata and controls
48 lines (39 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <cmath>
#include "input_image.h" //contains the first sample taken from the MNIST test set
#include "mbed.h"
#include "models/my_model/my_model.hpp" //gernerated model file"
#include "uTensor.h"
using namespace uTensor;
int argmax(const Tensor &logits) {
uint32_t num_elems = logits->num_elems();
float max_value = static_cast<float>(logits(0));
int max_index = 0;
for (int i = 1; i < num_elems; ++i) {
float value = static_cast<float>(logits(i));
if (value >= max_value) {
max_value = value;
max_index = i;
}
}
return max_index;
}
static MyModel model;
int main(int argc, char **argv) {
printf("\n");
printf("Simple MNIST end-to-end uTensor cli example (device)\n");
size_t num_samples = *(&ref_labels + 1) - ref_labels;
for (size_t i = 0; i < num_samples; ++i) {
// create the input/output tensor
Tensor input_image = new RomTensor({1, 28, 28, 1}, flt, arr_input_image[i]);
Tensor logits = new RamTensor({1, 10}, flt);
model.set_inputs({{MyModel::input_0, input_image}})
.set_outputs({{MyModel::output_0, logits}})
.eval();
int max_index = argmax(logits);
input_image.free();
logits.free();
printf("pred label: %d, expecting: %d\r\n", max_index, ref_labels[i]);
}
return 0;
}