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

Function netAddUpsample

src/Detector/tensorrt_yolo/trt_utils.cpp:1311–1413  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1309}
1310
1311nvinfer1::ILayer* netAddUpsample(int /*layerIdx*/, std::map<std::string, std::string>& block,
1312 std::vector<float>& /*weights*/,
1313 std::vector<nvinfer1::Weights>& /*trtWeights*/, int& /*inputChannels*/,
1314 nvinfer1::ITensor* input, nvinfer1::INetworkDefinition* network)
1315{
1316 assert(block.at("type") == "upsample");
1317 nvinfer1::Dims inpDims = input->getDimensions();
1318 assert(inpDims.nbDims == 3);
1319 // assert(inpDims.d[1] == inpDims.d[2]);
1320 int n_scale = std::stoi(block.at("stride"));
1321
1322 int c1 = inpDims.d[0];
1323 float *deval = new float[c1*n_scale*n_scale];
1324 for (int i = 0; i < c1*n_scale*n_scale; i++)
1325 {
1326 deval[i] = 1.0;
1327 }
1328 nvinfer1::Weights wts{ DataType::kFLOAT, deval, c1*n_scale*n_scale };
1329 nvinfer1::Weights bias{ DataType::kFLOAT, nullptr, 0 };
1330 IDeconvolutionLayer* upsample = network->addDeconvolutionNd(*input, c1, DimsHW{ n_scale, n_scale }, wts, bias);
1331 upsample->setStrideNd(DimsHW{ n_scale, n_scale });
1332 upsample->setNbGroups(c1);
1333 return upsample;
1334
1335 #if 0
1336// add pre multiply matrix as a constant
1337 nvinfer1::Dims preDims{3,
1338 {1, stride * h, w},
1339 {nvinfer1::DimensionType::kCHANNEL, nvinfer1::DimensionType::kSPATIAL,
1340 nvinfer1::DimensionType::kSPATIAL}};
1341 int size = stride * h * w;
1342 nvinfer1::Weights preMul{nvinfer1::DataType::kFLOAT, nullptr, size};
1343 float* preWt = new float[size];
1344 /* (2*h * w)
1345 [ [1, 0, ..., 0],
1346 [1, 0, ..., 0],
1347 [0, 1, ..., 0],
1348 [0, 1, ..., 0],
1349 ...,
1350 ...,
1351 [0, 0, ..., 1],
1352 [0, 0, ..., 1] ]
1353 */
1354 for (int i = 0, idx = 0; i < h; ++i)
1355 {
1356 for (int s = 0; s < stride; ++s)
1357 {
1358 for (int j = 0; j < w; ++j, ++idx)
1359 {
1360 preWt[idx] = (i == j) ? 1.0f : 0.0f;
1361 }
1362 }
1363 }
1364 preMul.values = preWt;
1365 trtWeights.push_back(preMul);
1366 nvinfer1::IConstantLayer* preM = network->addConstant(preDims, preMul);
1367 assert(preM != nullptr);
1368 std::string preLayerName = "preMul_" + std::to_string(layerIdx);

Callers 1

createYOLOEngineMethod · 0.85

Calls 1

push_backMethod · 0.45

Tested by

no test coverage detected