MCPcopy Create free account
hub / github.com/Smorodov/Multitarget-tracker / netAddConvLinear

Function netAddConvLinear

src/Detector/tensorrt_yolo/trt_utils.cpp:533–585  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

531}
532
533nvinfer1::ILayer* netAddConvLinear(int layerIdx, std::map<std::string, std::string>& block,
534 std::vector<float>& weights,
535 std::vector<nvinfer1::Weights>& trtWeights, int& weightPtr,
536 int& inputChannels, nvinfer1::ITensor* input,
537 nvinfer1::INetworkDefinition* network)
538{
539 assert(block.at("type") == "convolutional");
540 assert(block.find("batch_normalize") == block.end());
541 assert(block.at("activation") == "linear");
542 assert(block.find("filters") != block.end());
543 assert(block.find("pad") != block.end());
544 assert(block.find("size") != block.end());
545 assert(block.find("stride") != block.end());
546
547 int filters = std::stoi(block.at("filters"));
548 int padding = std::stoi(block.at("pad"));
549 int kernelSize = std::stoi(block.at("size"));
550 int stride = std::stoi(block.at("stride"));
551 int pad;
552 if (padding)
553 pad = (kernelSize - 1) / 2;
554 else
555 pad = 0;
556 // load the convolution layer bias
557 nvinfer1::Weights convBias{nvinfer1::DataType::kFLOAT, nullptr, filters};
558 float* val = new float[filters];
559 for (int i = 0; i < filters; ++i)
560 {
561 val[i] = weights[weightPtr];
562 weightPtr++;
563 }
564 convBias.values = val;
565 trtWeights.push_back(convBias);
566 // load the convolutional layer weights
567 int size = filters * inputChannels * kernelSize * kernelSize;
568 nvinfer1::Weights convWt{nvinfer1::DataType::kFLOAT, nullptr, size};
569 val = new float[size];
570 for (int i = 0; i < size; ++i)
571 {
572 val[i] = weights[weightPtr];
573 weightPtr++;
574 }
575 convWt.values = val;
576 trtWeights.push_back(convWt);
577 nvinfer1::IConvolutionLayer* conv = network->addConvolutionNd(*input, filters, nvinfer1::DimsHW{kernelSize, kernelSize}, convWt, convBias);
578 assert(conv != nullptr);
579 std::string convLayerName = "conv_" + std::to_string(layerIdx);
580 conv->setName(convLayerName.c_str());
581 conv->setStrideNd(nvinfer1::DimsHW{stride, stride});
582 conv->setPaddingNd(nvinfer1::DimsHW{pad, pad});
583
584 return conv;
585}
586
587nvinfer1::ILayer* net_conv_bn_mish(int layerIdx,
588 std::map<std::string, std::string>& block,

Callers 1

createYOLOEngineMethod · 0.85

Calls 2

endMethod · 0.80
push_backMethod · 0.45

Tested by

no test coverage detected