Mnist works at the moment with trt8,others like yolo4tiny and mobilenet generate the engine files but crash after throwing nvifer1::CudaRuntimeError and when demo is being run ,it doesnt deserialize properly and crashes
This commit is contained in:
+35
-16
@@ -3,7 +3,7 @@
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
|
||||
bool Yolo3Detection::init(const std::string& tensor_path, const int n_classes, const int n_batches, const float conf_thresh) {
|
||||
bool Yolo3Detection::init(const std::string& tensor_path,const std::string& cfg_path,const std::string& name_path,const int n_classes, const int n_batches, const float conf_thresh) {
|
||||
|
||||
//convert network to tensorRT
|
||||
std::cout<<(tensor_path).c_str()<<"\n";
|
||||
@@ -14,28 +14,42 @@ bool Yolo3Detection::init(const std::string& tensor_path, const int n_classes, c
|
||||
tk::dnn::dataDim_t idim = netRT->input_dim;
|
||||
idim.n = nBatches;
|
||||
|
||||
std::vector<int> yolosLine = noYolosLine(cfg_path);
|
||||
noYolos = yolosLine;
|
||||
int channels,height,width;
|
||||
loadYoloInitInfo(channels,width,height,cfg_path);
|
||||
|
||||
if(netRT->pluginFactory->n_yolos < 2 ) {
|
||||
|
||||
|
||||
if(yolosLine.size() < 2 ) {
|
||||
FatalError("this is not yolo3");
|
||||
}
|
||||
|
||||
for(int i=0; i<netRT->pluginFactory->n_yolos; i++) {
|
||||
YoloRT *yRT = netRT->pluginFactory->yolos[i];
|
||||
classes = yRT->classes;
|
||||
num = yRT->num;
|
||||
nMasks = yRT->n_masks;
|
||||
|
||||
for(int i=0; i<noYolos.size(); i++) {
|
||||
std::vector<float> maskTemp,anchorsTemp;
|
||||
std::vector<std::string> classNamesTemp;
|
||||
int classes,nms_kind,coords,numTemp;
|
||||
float nmsthresh;
|
||||
loadYoloInfo(cfg_path,yolosLine[i],maskTemp,anchorsTemp,numTemp,classes,nmsthresh,nms_kind,coords);
|
||||
classNamesTemp = darknetReadNames(name_path);
|
||||
num = numTemp/maskTemp.size();
|
||||
nMasks = maskTemp.size();
|
||||
dnnType* maskTempF;
|
||||
dnnType* biasTempF;
|
||||
maskTempF = maskTemp.data();
|
||||
biasTempF = anchorsTemp.data();
|
||||
// make a yolo layer to interpret predictions
|
||||
yolo[i] = new tk::dnn::Yolo(nullptr, classes, nMasks, ""); // yolo without input and bias
|
||||
yolo[i]->mask_h = new dnnType[nMasks];
|
||||
yolo[i]->bias_h = new dnnType[num*nMasks*2];
|
||||
memcpy(yolo[i]->mask_h, yRT->mask, sizeof(dnnType)*nMasks);
|
||||
memcpy(yolo[i]->bias_h, yRT->bias, sizeof(dnnType)*num*nMasks*2);
|
||||
yolo[i]->input_dim = yolo[i]->output_dim = tk::dnn::dataDim_t(1, yRT->c, yRT->h, yRT->w);
|
||||
yolo[i]->classesNames = yRT->classesNames;
|
||||
yolo[i]->nms_thresh = yRT->nms_thresh;
|
||||
yolo[i]->nsm_kind = (tk::dnn::Yolo::nmsKind_t) yRT->nms_kind;
|
||||
yolo[i]->new_coords = yRT->new_coords;
|
||||
memcpy(yolo[i]->mask_h, maskTempF, sizeof(dnnType)*nMasks);
|
||||
memcpy(yolo[i]->bias_h, biasTempF, sizeof(dnnType)*num*nMasks*2);
|
||||
yolo[i]->input_dim = yolo[i]->output_dim = tk::dnn::dataDim_t(1, channels, height, width);
|
||||
yolo[i]->classesNames = classNamesTemp;
|
||||
yolo[i]->nms_thresh = nmsthresh;
|
||||
yolo[i]->nsm_kind = (tk::dnn::Yolo::nmsKind_t) nms_kind;
|
||||
yolo[i]->new_coords = coords;
|
||||
}
|
||||
|
||||
dets = tk::dnn::Yolo::allocateDetections(tk::dnn::Yolo::MAX_DETECTIONS, classes);
|
||||
@@ -94,10 +108,15 @@ void Yolo3Detection::preprocess(cv::Mat &frame, const int bi){
|
||||
|
||||
void Yolo3Detection::postprocess(const int bi, const bool mAP){
|
||||
|
||||
|
||||
|
||||
//get yolo outputs
|
||||
if(noYolos.size() < 2){
|
||||
FatalError("YOLOS WRONG!!");
|
||||
}
|
||||
std::vector<float *> rt_out;
|
||||
//dnnType *rt_out[netRT->pluginFactory->n_yolos];
|
||||
for(int i=0; i<netRT->pluginFactory->n_yolos; i++)
|
||||
for(int i=0; i<noYolos.size(); i++)
|
||||
rt_out.push_back((dnnType*)netRT->buffersRT[i+1] + netRT->buffersDIM[i+1].tot()*bi);
|
||||
|
||||
float x_ratio = float(originalSize[bi].width) / float(netRT->input_dim.w);
|
||||
@@ -105,7 +124,7 @@ void Yolo3Detection::postprocess(const int bi, const bool mAP){
|
||||
|
||||
// compute dets
|
||||
nDets = 0;
|
||||
for(int i=0; i<netRT->pluginFactory->n_yolos; i++) {
|
||||
for(int i=0; i<noYolos.size(); i++) {
|
||||
yolo[i]->dstData = rt_out[i];
|
||||
yolo[i]->computeDetections(dets, nDets, netRT->input_dim.w, netRT->input_dim.h, confThreshold, yolo[i]->new_coords);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user