-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgraph_build.cpp
More file actions
61 lines (50 loc) · 1.63 KB
/
Copy pathgraph_build.cpp
File metadata and controls
61 lines (50 loc) · 1.63 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
#include "build.cpp"
#include "build.hpp"
namespace fs = std::filesystem;
using namespace it_lab_ai;
int main(int argc, char* argv[]) {
std::string image_folder = IMAGE1_PATH;
std::vector<std::string> image_paths;
bool parallel = false;
if (argc > 1 && std::string(argv[1]) == "--parallel") {
std::cout << "Parallel mode" << std::endl;
parallel = true;
}
for (const auto& entry : fs::directory_iterator(image_folder)) {
if (entry.path().extension() == ".png") {
image_paths.push_back(entry.path().string());
}
}
if (image_paths.empty()) {
throw std::runtime_error("No PNG images found in the folder");
}
for (const auto& image_path : image_paths) {
cv::Mat image = cv::imread(image_path);
if (image.empty()) {
std::cerr << "Failed to load image: " << image_path << std::endl;
continue;
}
cv::cvtColor(image, image, cv::COLOR_BGR2GRAY);
std::vector<cv::Mat> channels;
cv::split(image, channels);
std::vector<float> res(28 * 28);
for (int i = 0; i < 28; ++i) {
for (int j = 0; j < 28; ++j) {
res[i * 28 + j] = channels[0].at<uchar>(j, i);
}
}
Shape sh({1, 1, 28, 28});
Tensor input = make_tensor<float>(res, sh);
Shape sh1({1, 5, 5, 3});
std::vector<float> vec(75, 3);
Tensor output = make_tensor(vec, sh1);
build_graph(input, output, true, parallel);
std::vector<float> tmp_output = softmax<float>(*output.as<float>());
for (size_t i = 0; i < tmp_output.size(); i++) {
if (tmp_output[i] >= 1e-6) {
std::cout << "Image: " << image_path << " -> Class: " << i << std::endl;
}
}
}
return 0;
}