InferTools.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #ifndef __INFERTOOLS_HPP_
  2. #define __INFERTOOLS_HPP_
  3. #include <iostream>
  4. #include <chrono>
  5. #include <cmath>
  6. #include "Util/logger.h"
  7. #include "Util/SqlPool.h"
  8. #include "cuda_utils.h"
  9. #include "yololayer.h"
  10. #include "logging.h"
  11. #include <cuda_runtime.h>
  12. #include "calibrator.h"
  13. #include "preprocess.h"
  14. #include "common.hpp"
  15. #include <opencv2/opencv.hpp>
  16. #include "CNStreamInferData.h"
  17. #include <mutex>
  18. #include "InfineFilter.hpp"
  19. #include "config.hpp"
  20. using namespace toolkit;
  21. using namespace std;
  22. namespace gsd
  23. {
  24. class InferTools
  25. {
  26. private:
  27. InferTools(){}
  28. public:
  29. using Ptr = std::shared_ptr<InferTools>;
  30. /**
  31. * @description: getPtr
  32. * @return {*}
  33. */
  34. static std::shared_ptr<InferTools> getPtr();
  35. /**
  36. * @description:
  37. * @param {string} engin
  38. * @return {*}
  39. */
  40. bool Init(std::string enginefile);
  41. /**
  42. * @description: 释放
  43. * @return {*}
  44. */
  45. void Destroy();
  46. /**
  47. * @description: 推理
  48. * @return {*}
  49. */
  50. bool Inference(std::shared_ptr<cv::Mat> img, CNStreamInferData::Ptr result);
  51. /**
  52. * @description: doInference
  53. * @param {IExecutionContext&} context
  54. * @param {cudaStream_t&} stream
  55. * @param {void} *
  56. * @param {float*} output
  57. * @param {int} batchSize
  58. * @return {*}
  59. */
  60. void doInference(IExecutionContext& context, cudaStream_t& stream, void **buffers, float* output, int batchSize);
  61. /**
  62. * @description: InferTools
  63. * @return {*}
  64. */
  65. ~InferTools(){
  66. }
  67. protected:
  68. int nms_Thresh = 0.4;
  69. int conf_Thresh = 0.5;
  70. int device = 0;
  71. std::string engine_name = "../data/modules/best6_fp16.engine";
  72. char *trtModelStream = nullptr;
  73. IRuntime* runtime = nullptr;
  74. ICudaEngine* engine = nullptr;
  75. IExecutionContext* context = nullptr;
  76. const char* INPUT_BLOB_NAME = "data";
  77. const char* OUTPUT_BLOB_NAME = "prob";
  78. cudaStream_t stream;
  79. uint8_t* img_host = nullptr;
  80. uint8_t* img_device = nullptr;
  81. float* buffers[2];
  82. int inputIndex;
  83. int outputIndex;
  84. mutex m_mutex;
  85. };
  86. } // namespace gsd
  87. #endif