#ifndef __TRT_UTILS_H__
|
#define __TRT_UTILS_H__
|
|
/* OpenCV headers */
|
//#include <opencv/cv.h>
|
#include <opencv2/opencv.hpp>
|
#include <opencv2/core/core.hpp>
|
#include <opencv2/dnn/dnn.hpp>
|
#include <opencv2/highgui/highgui.hpp>
|
#include <opencv2/imgproc/imgproc.hpp>
|
|
#include "mish.h"
|
#include "chunk.h"
|
#include "hardswish.h"
|
#include <set>
|
#include <math.h>
|
#include <algorithm>
|
#include "NvInfer.h"
|
|
#include "ds_image.h"
|
#include "plugin_factory.h"
|
//#include "logging.h"
|
class DsImage;
|
struct BBox
|
{
|
float x1, y1, x2, y2;
|
};
|
|
struct BBoxInfo
|
{
|
BBox box;
|
int label;
|
int classId; // For coco benchmarking
|
float prob;
|
};
|
|
class Logger : public nvinfer1::ILogger
|
{
|
public:
|
Logger(Severity severity = Severity::kWARNING)
|
{
|
|
}
|
|
~Logger()
|
{
|
|
}
|
nvinfer1::ILogger& getTRTLogger()
|
{
|
return *this;
|
}
|
|
void log(nvinfer1::ILogger::Severity severity, const char* msg) override
|
{
|
// suppress info-level messages
|
if (severity == Severity::kINFO) return;
|
|
switch (severity)
|
{
|
case Severity::kINTERNAL_ERROR: std::cerr << "INTERNAL_ERROR: " << msg << std::endl; break;
|
case Severity::kERROR: std::cerr << "ERROR: " << msg << std::endl; break;
|
case Severity::kWARNING: std::cerr << "WARNING: " << msg << std::endl; break;
|
case Severity::kINFO: std::cerr << "INFO: " << msg << std::endl; break;
|
case Severity::kVERBOSE: break;
|
// default: std::cerr <<"UNKNOW:"<< msg << std::endl;break;
|
}
|
}
|
};
|
float clamp(const float val, const float minVal, const float maxVal);
|
// Common helper functions
|
cv::Mat blobFromDsImages(const std::vector<DsImage>& inputImages, const int& inputH,
|
const int& inputW);
|
|
bool fileExists(const std::string fileName, bool verbose = true);
|
|
nvinfer1::ICudaEngine* loadTRTEngine(const std::string planFilePath, PluginFactory* pluginFactory,
|
Logger& logger);
|
uint64_t get3DTensorVolume(nvinfer1::Dims inputDims);
|
|
std::vector<BBoxInfo> nmsAllClasses(const float nmsThresh, std::vector<BBoxInfo>& binfo,
|
const uint32_t numClasses, const std::string &model_type);
|
|
std::vector<BBoxInfo> nonMaximumSuppression(const float nmsThresh, std::vector<BBoxInfo> binfo);
|
#endif
|