-
Notifications
You must be signed in to change notification settings - Fork 8
/
demo.cc
executable file
·161 lines (138 loc) · 4.66 KB
/
demo.cc
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// headers in STL
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <string>
#include "centerpoint/centerpoint.h"
void Getinfo(void) {
cudaDeviceProp prop;
int count = 0;
cudaGetDeviceCount(&count);
printf("\nGPU has cuda devices: %d\n", count);
for (int i = 0; i < count; ++i) {
cudaGetDeviceProperties(&prop, i);
printf("----device id: %d info----\n", i);
printf(" GPU : %s \n", prop.name);
printf(" Capbility: %d.%d\n", prop.major, prop.minor);
printf(" Global memory: %luMB\n", prop.totalGlobalMem >> 20);
printf(" Const memory: %luKB\n", prop.totalConstMem >> 10);
printf(" Shared memory in a block: %luKB\n", prop.sharedMemPerBlock >> 10);
printf(" warp size: %d\n", prop.warpSize);
printf(" threads in a block: %d\n", prop.maxThreadsPerBlock);
printf(" block dim: (%d,%d,%d)\n", prop.maxThreadsDim[0],
prop.maxThreadsDim[1], prop.maxThreadsDim[2]);
printf(" grid dim: (%d,%d,%d)\n", prop.maxGridSize[0], prop.maxGridSize[1],
prop.maxGridSize[2]);
}
printf("\n");
}
int Txt2Arrary(float *&points_array, std::string file_name,
int num_feature = 4) {
std::ifstream in_file;
in_file.open(file_name.data());
assert(in_file.is_open());
std::vector<float> temp_points;
std::string c;
while (!in_file.eof()) {
in_file >> c;
temp_points.push_back(atof(c.c_str()));
}
points_array = new float[temp_points.size()];
for (size_t i = 0; i < temp_points.size(); ++i) {
points_array[i] = temp_points[i];
}
in_file.close();
return temp_points.size() / num_feature;
};
int Bin2Arrary(float *&points_array, std::string file_name,
int in_num_feature = 4, int out_num_feature = 4) {
std::ifstream in_file;
in_file.open(file_name.data(), ios::binary);
assert(in_file.is_open());
std::vector<float> temp_points;
float f;
while (!in_file.eof()) {
in_file.read((char *)&f, sizeof(f));
temp_points.push_back(f);
}
points_array = new float[temp_points.size()];
int size = temp_points.size() / in_num_feature;
for (int i = 0; i < size; ++i) {
for (int j = 0; j < out_num_feature; ++j) {
points_array[i * out_num_feature + j] =
temp_points[i * in_num_feature + j];
}
}
in_file.close();
return size;
};
void Boxes2Txt(const std::vector<Box> &boxes, std::string file_name) {
std::ofstream out_file;
out_file.open(file_name, std::ios::out);
if (out_file.is_open()) {
for (const auto &box : boxes) {
out_file << box.x << " ";
out_file << box.y << " ";
out_file << box.z << " ";
out_file << box.l << " ";
out_file << box.w << " ";
out_file << box.h << " ";
out_file << box.r << " ";
out_file << box.score << " ";
out_file << box.label << "\n";
}
}
out_file.close();
return;
};
void load_anchors(float *&anchor_data, std::string file_name) {
std::ifstream InFile;
InFile.open(file_name.data());
assert(InFile.is_open());
std::vector<float> temp_points;
std::string c;
while (!InFile.eof()) {
InFile >> c;
temp_points.push_back(atof(c.c_str()));
}
anchor_data = new float[temp_points.size()];
for (size_t i = 0; i < temp_points.size(); ++i) {
anchor_data[i] = temp_points[i];
}
InFile.close();
return;
}
void test(void) {
const std::string DB_CONF = "../bootstrap.yaml";
YAML::Node config = YAML::LoadFile(DB_CONF);
std::string pfe_file = config["PfeFile"].as<std::string>();
std::string backbone_file = config["BackboneFile"].as<std::string>();
std::string model_config = config["ModelConfig"].as<std::string>();
std::string file_name = config["InputFile"].as<std::string>();
std::cout << "pfe_file: " << pfe_file << std::endl;
std::cout << "backbone_file: " << backbone_file << std::endl;
std::cout << "config: " << model_config << std::endl;
std::cout << "data: " << file_name << std::endl;
CenterPoint cp(config, pfe_file, backbone_file, model_config);
float *points_array;
int in_num_points;
in_num_points =
Bin2Arrary(points_array, file_name, config["LoadDim"].as<int>(),
config["UseDim"].as<int>());
std::cout << "num points: " << in_num_points << std::endl;
for (int _ = 0; _ < 2; _++) {
std::vector<Box> out_detections;
cudaDeviceSynchronize();
cp.DoInference(points_array, in_num_points, out_detections);
cudaDeviceSynchronize();
size_t num_objects = out_detections.size();
std::cout << "detected objects: " << num_objects << std::endl;
std::string boxes_file_name = config["OutputFile"].as<std::string>();
Boxes2Txt(out_detections, boxes_file_name);
}
delete[] points_array;
};
int main(int argc, char **argv) {
Getinfo();
test();
}