-
Notifications
You must be signed in to change notification settings - Fork 4
/
demo.cc
executable file
·177 lines (154 loc) · 5.25 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// headers in STL
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <string>
#include "pointpillars/pointpillars.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 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()));
}
points_array = new float[temp_points.size()];
for (size_t i = 0; i < temp_points.size(); ++i) {
points_array[i] = temp_points[i];
}
InFile.close();
return temp_points.size() / num_feature;
// printf("Done");
};
int Bin2Arrary(float *&points_array, std::string file_name,
int in_num_feature = 4, int out_num_feature = 4) {
std::ifstream InFile;
InFile.open(file_name.data(), ios::binary);
assert(InFile.is_open());
std::vector<float> temp_points;
float f;
while (!InFile.eof()) {
InFile.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];
}
}
InFile.close();
return size;
// printf("Done");
};
void Boxes2Txt(const std::vector<float> &boxes,
const std::vector<int> &labels,
const std::vector<float> &scores,
std::string file_name,
int num_feature = 7) {
std::ofstream ofFile;
ofFile.open(file_name, std::ios::out);
if (ofFile.is_open()) {
for (size_t i = 0; i < boxes.size() / num_feature; ++i) {
for (int j = 0; j < num_feature; ++j) {
ofFile << boxes.at(i * num_feature + j) << " ";
}
ofFile << scores.at(i) << " ";
ofFile << labels.at(i) << " ";
ofFile << "\n";
}
}
ofFile.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, backbone_file;
if (config["UseOnnx"].as<bool>()) {
pfe_file = config["PfeOnnx"].as<std::string>();
backbone_file = config["BackboneOnnx"].as<std::string>();
} else {
pfe_file = config["PfeTrt"].as<std::string>();
backbone_file = config["BackboneTrt"].as<std::string>();
}
std::cout << "pfe_file: " << pfe_file << std::endl;
std::cout << "backbone_file: " << backbone_file << std::endl;
const std::string pp_config = config["ModelConfig"].as<std::string>();
std::string file_name = config["InputFile"].as<std::string>();
std::cout << "config: " << pp_config << std::endl;
std::cout << "data: " << file_name << std::endl;
PointPillars pp(config["UseOnnx"].as<bool>(), pfe_file, backbone_file,
pp_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; _ < 4; _++) {
std::vector<float> out_detections;
std::vector<int> out_labels;
std::vector<float> out_scores;
cudaDeviceSynchronize();
pp.DoInference(points_array, in_num_points, &out_detections, &out_labels,
&out_scores);
cudaDeviceSynchronize();
size_t BoxFeature = 7;
size_t num_objects = out_detections.size() / BoxFeature;
std::cout << "detected objects: " << num_objects << std::endl;
assert(num_objects == out_labels.size());
assert(num_objects == out_scores.size());
std::string boxes_file_name = config["OutputFile"].as<std::string>();
Boxes2Txt(out_detections, out_labels, out_scores, boxes_file_name);
}
delete[] points_array;
};
int main(int argc, char **argv) {
Getinfo();
test();
}