赞
踩
在yolov5中CSP组件是使用最多的,那么在tensorRT中是如何的呢?结合组件模型的结构图看逻辑就很清晰了。
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) { Weights emptywts{ DataType::kFLOAT, nullptr, 0 }; //e为膨胀系数 int c_ = (int)((float)c2 * e); //这里使用1*1的卷积核实现降维 auto cv1 = convBlock(network, weightMap, input, c_, 1, 1, 1, lname + ".cv1"); //cv2 做普通1*1卷积,有个疑问这里为什么是用1*1的卷积核? auto cv2 = network->addConvolutionNd(input, c_, DimsHW{ 1, 1 }, weightMap[lname + ".cv2.weight"], emptywts); ITensor *y1 = cv1->getOutput(0); for (int i = 0; i < n; i++) { auto b = bottleneck(network, weightMap, *y1, c_, c_, shortcut, g, 1.0, lname + ".m." + std::to_string(i)); y1 = b->getOutput(0); } auto cv3 = network->addConvolutionNd(*y1, c_, DimsHW{ 1, 1 }, weightMap[lname + ".cv3.weight"], emptywts); ITensor* inputTensors[] = { cv3->getOutput(0), cv2->getOutput(0) }; auto cat = network->addConcatenation(inputTensors, 2); IScaleLayer* bn = addBatchNorm2d(network, weightMap, *cat->getOutput(0), lname + ".bn", 1e-4); auto lr = network->addActivation(*bn->getOutput(0), ActivationType::kLEAKY_RELU); lr->setAlpha(0.1); auto cv4 = convBlock(network, weightMap, *lr->getOutput(0), c2, 1, 1, 1, lname + ".cv4"); return cv4; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。