-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaccuracy_check.cpp
More file actions
69 lines (67 loc) · 1.96 KB
/
Copy pathaccuracy_check.cpp
File metadata and controls
69 lines (67 loc) · 1.96 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "acc.hpp"
#include "graph/graph.hpp"
#include "layers/ConvLayer.hpp"
#include "layers/EWLayer.hpp"
#include "layers/FCLayer.hpp"
#include "layers/InputLayer.hpp"
#include "layers/OutputLayer.hpp"
#include "layers/PoolingLayer.hpp"
using namespace it_lab_ai;
int main() {
std::string image_path = IMAGE1_PATH;
cv::Mat image = cv::imread(image_path);
if (image.empty()) {
throw std::runtime_error("Failed to load image");
}
cv::Mat resized_image;
cv::resize(image, resized_image, cv::Size(227, 227));
std::vector<cv::Mat> channels;
cv::split(resized_image, channels);
int count_pic = 1;
std::vector<float> res(count_pic * 227 * 227 * 3);
int c = 0;
for (int i = 0; i < 227; ++i) {
for (int j = 0; j < 227; ++j) {
res[c] = channels[2].at<uchar>(i, j);
c++;
res[c] = channels[1].at<uchar>(i, j);
c++;
res[c] = channels[0].at<uchar>(i, j);
c++;
}
}
Shape sh({static_cast<size_t>(count_pic), 227, 227, 3});
Tensor t = make_tensor<float>(res, sh);
Graph graph(6);
Shape sh1({1, 5, 5, 3});
std::vector<float> vec;
vec.reserve(75);
for (int i = 0; i < 75; ++i) {
vec.push_back(3);
}
Tensor input = t;
Tensor output = make_tensor(vec, sh1);
InputLayer a1(kNhwc, kNchw, 1, 2);
std::vector<float> kernelvec = {1, 1, 1, 1, 1, 1, 1, 1, 1};
Shape sh2({3, 3});
Tensor kernel = make_tensor(kernelvec, sh2);
ConvolutionalLayer a2(1, 0, 0, kernel);
Shape poolshape = {2, 2};
EWLayer a3("linear", 2.0F, 3.0F);
PoolingLayer a4(poolshape, "average");
FCLayer a6;
OutputLayer a5;
graph.setInput(a1, input);
graph.makeConnection(a1, a2);
graph.makeConnection(a2, a3);
graph.makeConnection(a3, a4);
graph.makeConnection(a4, a5);
graph.makeConnection(a5, a6);
graph.setOutput(a5, output);
graph.inference();
std::vector<float> tmp = *output.as<float>();
std::vector<float> tmp_output = softmax<float>(*output.as<float>());
for (float i : tmp) {
std::cout << i << " ";
}
}