common.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #ifndef __YOLOV5_COMMON_H_
  2. #define __YOLOV5_COMMON_H_
  3. #include <fstream>
  4. #include <map>
  5. #include <sstream>
  6. #include <vector>
  7. #include <opencv2/opencv.hpp>
  8. #include "NvInfer.h"
  9. #include "yololayer.h"
  10. using namespace nvinfer1;
  11. cv::Rect get_rect(cv::Mat& img, float bbox[4]);
  12. float iou(float lbox[4], float rbox[4]);
  13. bool cmp(const Yolo::Detection& a, const Yolo::Detection& b);
  14. void nms(std::vector<Yolo::Detection>& res, float *output, float conf_thresh, float nms_thresh);
  15. // TensorRT weight files have a simple space delimited format:
  16. // [type] [size] <data x size in hex>
  17. std::map<std::string, Weights> loadWeights(const std::string file) ;
  18. IScaleLayer* addBatchNorm2d(INetworkDefinition *network, std::map<std::string, Weights>& weightMap, ITensor& input, std::string lname, float eps);
  19. ILayer* convBlock(INetworkDefinition *network, std::map<std::string, Weights>& weightMap, ITensor& input, int outch, int ksize, int s, int g, std::string lname);
  20. ILayer* focus(INetworkDefinition *network, std::map<std::string, Weights>& weightMap, ITensor& input, int inch, int outch, int ksize, std::string lname);
  21. ILayer* bottleneck(INetworkDefinition *network, std::map<std::string, Weights>& weightMap, ITensor& input, int c1, int c2, bool shortcut, int g, float e, std::string lname);
  22. ILayer* bottleneckCSP(INetworkDefinition *network, std::map<std::string, Weights>& weightMap, ITensor& input, int c1, int c2, int n, bool shortcut, int g, float e, std::string lname) ;
  23. ILayer* C3(INetworkDefinition *network, std::map<std::string, Weights>& weightMap, ITensor& input, int c1, int c2, int n, bool shortcut, int g, float e, std::string lname);
  24. ILayer* SPP(INetworkDefinition *network, std::map<std::string, Weights>& weightMap, ITensor& input, int c1, int c2, int k1, int k2, int k3, std::string lname) ;
  25. ILayer* SPPF(INetworkDefinition *network, std::map<std::string, Weights>& weightMap, ITensor& input, int c1, int c2, int k, std::string lname) ;
  26. std::vector<std::vector<float>> getAnchors(std::map<std::string, Weights>& weightMap, std::string lname);
  27. IPluginV2Layer* addYoLoLayer(INetworkDefinition *network, std::map<std::string, Weights>& weightMap, std::string lname, std::vector<IConvolutionLayer*> dets);
  28. #endif