-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
78 lines (64 loc) · 3.09 KB
/
main.cpp
File metadata and controls
78 lines (64 loc) · 3.09 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
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <fstream>
#include "video_thread.h"
#include "config.h"
#include "utils.h"
#include <fstream>
#include <opencv2/opencv.hpp>
int main(){
// set the video and model path
try
{
std::cout<<cv::getBuildInformation() << std::endl; // Print OpenCV build information
std::cout<<cv::cuda::getCudaEnabledDeviceCount() << " CUDA devices available." << std::endl; // Print number of CUDA devices available
const std::string videoSource = "../../input/blade.avi"; // Path to the video file
const std::string StuModelPath = "../../input/LiMR_student_16.engine"; // Path to the student model ONNX file
const std::string TeaModelPath = "../../input/LiMR_teacher_16.engine"; // Path to the teacher model ONNX file
const std::string StuOnnxPath = "../../input/LiMR_student.onnx"; // Path to the student model ONNX file
const std::string TeaOnnxPath = "../../input/LiMR_teacher.onnx"; // Path to the teacher model ONNX file
// const std::string imgSource = "../../input/IMG_9260.png "; // Path to the image file, if any
const std::string imgSource = " "; // Path to the image file, if any
const std::string type = "F32"; // Data type for the model, can be "F32" or "INT8"
// if you use code 'config.set_flag(trt.BuilderFlag.FP16) ' to build the model, you should also set type to "F32"
// because the input and output nodes of model is still FP32, only the internal computation is in FP16
Config NormalConfig(videoSource,
StuModelPath,
TeaModelPath,
imgSource,
type);
// check if the engine files exist, if not, build them
if(!std::ifstream(StuModelPath).good()) {
std::cout << "Building student model engine..." << std::endl;
build_engine(StuOnnxPath,
StuModelPath,
NormalConfig.batchSize,
NormalConfig.inputWidth,
NormalConfig.inputHeight,
NormalConfig.outputWidth,
NormalConfig.outputHeight);
} else {
std::cout << "Student model engine already exists." << std::endl;
}
if (!std::ifstream(TeaModelPath).good()) {
std::cout << "Building teacher model engine..." << std::endl;
build_engine(TeaOnnxPath,
TeaModelPath,
NormalConfig.batchSize,
NormalConfig.inputWidth,
NormalConfig.inputHeight,
NormalConfig.outputWidth,
NormalConfig.outputHeight);
} else {
std::cout << "Teacher model engine already exists." << std::endl;
}
VideoThread::VideoCaptureThread videoThread(NormalConfig);
videoThread.start();
return 0;
}
catch (const std::exception& e)
{
std::cerr << "Exception: " << e.what() << std::endl;
system("pause");
return 1;
}
}