chore: import upstream snapshot with attribution
Docker Image CI / build-ubuntu2004 (push) Has been cancelled
Docker Image CI / build-ubuntu2004 (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
#
|
||||
# SPDX-FileCopyrightText: Copyright (c) 1993-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
add_plugin_source(
|
||||
detectionLayerPlugin.cpp
|
||||
detectionLayerPlugin.h
|
||||
)
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#
|
||||
# SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
---
|
||||
name: DetectionLayer_TRT
|
||||
interface: "IPluginV2Ext"
|
||||
versions:
|
||||
"1":
|
||||
attributes:
|
||||
- num_classes
|
||||
- keep_topk
|
||||
- score_threshold
|
||||
- iou_threshold
|
||||
attribute_types:
|
||||
num_classes: int32
|
||||
keep_topk: int32
|
||||
score_threshold: float32
|
||||
iou_threshold: float32
|
||||
attribute_length:
|
||||
num_classes: 1
|
||||
keep_topk: 1
|
||||
score_threshold: 1
|
||||
iou_threshold: 1
|
||||
attribute_options:
|
||||
num_classes:
|
||||
min: "0"
|
||||
max: "=pinf"
|
||||
keep_topk:
|
||||
min: "0"
|
||||
max: "=pinf"
|
||||
score_threshold:
|
||||
min: "=0"
|
||||
max: "=pinf"
|
||||
iou_threshold:
|
||||
min: "0"
|
||||
max: "=pinf"
|
||||
attributes_required:
|
||||
- num_classes
|
||||
- keep_topk
|
||||
- score_threshold
|
||||
- iou_threshold
|
||||
...
|
||||
@@ -0,0 +1,78 @@
|
||||
# DetectionLayer Plugin [DEPRECATED]
|
||||
|
||||
**This plugin is deprecated since TensorRT 10.12 and will be removed in a future release. No alternatives are planned to be provided.**
|
||||
|
||||
**Table Of Contents**
|
||||
- [Description](#description)
|
||||
* [Structure](#structure)
|
||||
- [Parameters](#parameters)
|
||||
- [Additional resources](#additional-resources)
|
||||
- [License](#license)
|
||||
- [Changelog](#changelog)
|
||||
- [Known issues](#known-issues)
|
||||
|
||||
## Description
|
||||
|
||||
The `DetectionLayer` plugin performs bounding boxes refinement of MaskRCNN's detection head and generate the final detection output of MaskRCNN. It is used in sampleMaskRCNN.
|
||||
|
||||
|
||||
### Structure
|
||||
|
||||
This plugin supports the NCHW format. It takes three input tensors: `delta_bbox`, `score` and `roi`
|
||||
|
||||
`delta_bbox` is the refinement information of roi boxes generated from `ProposalLayer`. `delta_bbox` tensor's shape is `[N, rois, num_classes*4, 1, 1]` where `N` is batch size,
|
||||
`rois` is the total number of ROI boxes candidates per image, and `num_classes*4` means 4 refinement elements (`[dy, dx, dh, dw]`) for each roi box as different classes.
|
||||
|
||||
`score` is the predicted class scores of ROI boxes generated from `ProposalLayer` of shape `[N, rois, num_classes, 1, 1]`. There is `argmax`operation in `Detectionlayer` to determine the final class of detection
|
||||
candidates.
|
||||
|
||||
`roi` is the coordinates of ROI boxes candidates from `ProposalLayer` of shape `[N, rois, 4]`.
|
||||
|
||||
This plugin generates output of shape `[N, keep_topk, 6]` where `keep_topk` is the maximum number of detections left after NMS and '6' means 6 elements of an detection `[y1, x1, y2, x2,
|
||||
class_label, score]`
|
||||
|
||||
## Parameters
|
||||
|
||||
This plugin has the plugin creator class `DetectionlayerPluginCreator` and the plugin class `Detectionlayer`.
|
||||
|
||||
The following parameters were used to create `Detectionlayer` instance:
|
||||
|
||||
| Type | Parameter | Description
|
||||
|--------------------|------------------------------------|--------------------------------------------------------
|
||||
|`int` |`num_classes` |Number of detection classes(including `background`). `num_classes=81` for COCO dataset
|
||||
|`int` |`keep_topk` |Number of detections will be kept after NMS.
|
||||
|`float` |`score_threshold` |Confidence threshold value. This plugin will drop a detection if its class confidence(score) is under "score_threshold".
|
||||
|`float` |`iou_threshold` |IOU threshold value used in NMS.
|
||||
|
||||
## Limitations
|
||||
|
||||
The number of anchors is capped at 1024 to support embedded devices with smaller shared memory capacity.
|
||||
|
||||
To enable support for a device with higher memory, calls to `sortPerClass`, `PerClassNMS` and `KeepTopKGather` can be modified in `RefineBatchClassNMS` ([maskRCNNKernels.cu](https://github.com/NVIDIA/TensorRT/blob/main/plugin/common/kernels/maskRCNNKernels.cu)).
|
||||
|
||||
## Additional resources
|
||||
|
||||
The following resources provide a deeper understanding of the `Detectionlayer` plugin:
|
||||
|
||||
- [MaskRCNN](https://github.com/matterport/Mask_RCNN)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
For terms and conditions for use, reproduction, and distribution, see the [TensorRT Software License Agreement](https://docs.nvidia.com/deeplearning/sdk/tensorrt-sla/index.html)
|
||||
documentation.
|
||||
|
||||
|
||||
## Changelog
|
||||
|
||||
May 2025
|
||||
Add deprecation note.
|
||||
|
||||
January 2022: The [Limitations](#limitations) section was added to this `README.md` file to document limitations of the plugin related to the maximum number of anchors it can support.
|
||||
|
||||
June 2019: First release of this `README.md` file.
|
||||
|
||||
|
||||
## Known issues
|
||||
|
||||
There are no known issues in this plugin.
|
||||
@@ -0,0 +1,356 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 1993-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "detectionLayerPlugin.h"
|
||||
#include "common/plugin.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
using namespace nvinfer1;
|
||||
using namespace plugin;
|
||||
using nvinfer1::plugin::DetectionLayer;
|
||||
using nvinfer1::plugin::DetectionLayerPluginCreator;
|
||||
|
||||
namespace
|
||||
{
|
||||
char const* const kDETECTIONLAYER_PLUGIN_VERSION{"1"};
|
||||
char const* const kDETECTIONLAYER_PLUGIN_NAME{"DetectionLayer_TRT"};
|
||||
} // namespace
|
||||
|
||||
DetectionLayerPluginCreator::DetectionLayerPluginCreator()
|
||||
{
|
||||
mPluginAttributes.clear();
|
||||
mPluginAttributes.emplace_back(PluginField("num_classes", nullptr, PluginFieldType::kINT32, 1));
|
||||
mPluginAttributes.emplace_back(PluginField("keep_topk", nullptr, PluginFieldType::kINT32, 1));
|
||||
mPluginAttributes.emplace_back(PluginField("score_threshold", nullptr, PluginFieldType::kFLOAT32, 1));
|
||||
mPluginAttributes.emplace_back(PluginField("iou_threshold", nullptr, PluginFieldType::kFLOAT32, 1));
|
||||
|
||||
mFC.nbFields = mPluginAttributes.size();
|
||||
mFC.fields = mPluginAttributes.data();
|
||||
}
|
||||
|
||||
char const* DetectionLayerPluginCreator::getPluginName() const noexcept
|
||||
{
|
||||
return kDETECTIONLAYER_PLUGIN_NAME;
|
||||
}
|
||||
|
||||
char const* DetectionLayerPluginCreator::getPluginVersion() const noexcept
|
||||
{
|
||||
return kDETECTIONLAYER_PLUGIN_VERSION;
|
||||
}
|
||||
|
||||
PluginFieldCollection const* DetectionLayerPluginCreator::getFieldNames() noexcept
|
||||
{
|
||||
return &mFC;
|
||||
}
|
||||
|
||||
IPluginV2Ext* DetectionLayerPluginCreator::createPlugin(char const* /*name*/, PluginFieldCollection const* fc) noexcept
|
||||
{
|
||||
using namespace std::string_view_literals;
|
||||
try
|
||||
{
|
||||
PLUGIN_VALIDATE(fc != nullptr);
|
||||
plugin::validateRequiredAttributesExist({"num_classes", "keep_topk", "score_threshold", "iou_threshold"}, fc);
|
||||
PluginField const* fields = fc->fields;
|
||||
for (int32_t i = 0; i < fc->nbFields; ++i)
|
||||
{
|
||||
std::string_view const attrName = fields[i].name;
|
||||
if (attrName == "num_classes"sv)
|
||||
{
|
||||
PLUGIN_VALIDATE(fields[i].type == PluginFieldType::kINT32);
|
||||
mNbClasses = *(static_cast<int32_t const*>(fields[i].data));
|
||||
}
|
||||
if (attrName == "keep_topk"sv)
|
||||
{
|
||||
PLUGIN_VALIDATE(fields[i].type == PluginFieldType::kINT32);
|
||||
mKeepTopK = *(static_cast<int32_t const*>(fields[i].data));
|
||||
}
|
||||
if (attrName == "score_threshold"sv)
|
||||
{
|
||||
PLUGIN_VALIDATE(fields[i].type == PluginFieldType::kFLOAT32);
|
||||
mScoreThreshold = *(static_cast<float const*>(fields[i].data));
|
||||
}
|
||||
if (attrName == "iou_threshold"sv)
|
||||
{
|
||||
PLUGIN_VALIDATE(fields[i].type == PluginFieldType::kFLOAT32);
|
||||
mIOUThreshold = *(static_cast<float const*>(fields[i].data));
|
||||
}
|
||||
}
|
||||
return new DetectionLayer(mNbClasses, mKeepTopK, mScoreThreshold, mIOUThreshold);
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
caughtError(e);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
IPluginV2Ext* DetectionLayerPluginCreator::deserializePlugin(
|
||||
char const* /*name*/, void const* data, size_t length) noexcept
|
||||
{
|
||||
try
|
||||
{
|
||||
return new DetectionLayer(data, length);
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
caughtError(e);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DetectionLayer::DetectionLayer(int32_t numClasses, int32_t keepTopk, float scoreThreshold, float iouThreshold)
|
||||
: mNbClasses(numClasses)
|
||||
, mKeepTopK(keepTopk)
|
||||
, mScoreThreshold(scoreThreshold)
|
||||
, mIOUThreshold(iouThreshold)
|
||||
{
|
||||
mBackgroundLabel = 0;
|
||||
PLUGIN_VALIDATE(mNbClasses > 0);
|
||||
PLUGIN_VALIDATE(mKeepTopK > 0);
|
||||
PLUGIN_VALIDATE(mScoreThreshold >= 0.F);
|
||||
PLUGIN_VALIDATE(mIOUThreshold > 0.F);
|
||||
|
||||
mParam.backgroundLabelId = 0;
|
||||
mParam.numClasses = mNbClasses;
|
||||
mParam.keepTopK = mKeepTopK;
|
||||
mParam.scoreThreshold = mScoreThreshold;
|
||||
mParam.iouThreshold = mIOUThreshold;
|
||||
|
||||
mType = DataType::kFLOAT;
|
||||
}
|
||||
|
||||
int32_t DetectionLayer::getNbOutputs() const noexcept
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32_t DetectionLayer::initialize() noexcept
|
||||
{
|
||||
try
|
||||
{
|
||||
// Init the mValidCnt and mDecodedBboxes for max batch size.
|
||||
std::vector<int32_t> tempValidCnt(mMaxBatchSize, mAnchorsCnt);
|
||||
|
||||
mValidCnt = std::make_shared<CudaBind<int32_t>>(mMaxBatchSize);
|
||||
|
||||
PLUGIN_CUASSERT(cudaMemcpy(mValidCnt->mPtr, static_cast<void*>(tempValidCnt.data()),
|
||||
sizeof(int32_t) * mMaxBatchSize, cudaMemcpyHostToDevice));
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
caughtError(e);
|
||||
}
|
||||
return STATUS_FAILURE;
|
||||
}
|
||||
|
||||
void DetectionLayer::terminate() noexcept {}
|
||||
|
||||
void DetectionLayer::destroy() noexcept
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
bool DetectionLayer::supportsFormat(DataType type, PluginFormat format) const noexcept
|
||||
{
|
||||
return (type == DataType::kFLOAT && format == PluginFormat::kLINEAR);
|
||||
}
|
||||
|
||||
char const* DetectionLayer::getPluginType() const noexcept
|
||||
{
|
||||
return kDETECTIONLAYER_PLUGIN_NAME;
|
||||
}
|
||||
|
||||
char const* DetectionLayer::getPluginVersion() const noexcept
|
||||
{
|
||||
return kDETECTIONLAYER_PLUGIN_VERSION;
|
||||
}
|
||||
|
||||
IPluginV2Ext* DetectionLayer::clone() const noexcept
|
||||
{
|
||||
try
|
||||
{
|
||||
auto plugin = std::make_unique<DetectionLayer>(*this);
|
||||
plugin->setPluginNamespace(mNameSpace.c_str());
|
||||
return plugin.release();
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
caughtError(e);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void DetectionLayer::setPluginNamespace(char const* libNamespace) noexcept
|
||||
{
|
||||
try
|
||||
{
|
||||
PLUGIN_VALIDATE(libNamespace != nullptr);
|
||||
mNameSpace = libNamespace;
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
caughtError(e);
|
||||
}
|
||||
}
|
||||
|
||||
char const* DetectionLayer::getPluginNamespace() const noexcept
|
||||
{
|
||||
return mNameSpace.c_str();
|
||||
}
|
||||
|
||||
size_t DetectionLayer::getSerializationSize() const noexcept
|
||||
{
|
||||
return sizeof(int32_t) * 2 + sizeof(float) * 2 + sizeof(int32_t) * 2;
|
||||
}
|
||||
|
||||
void DetectionLayer::serialize(void* buffer) const noexcept
|
||||
{
|
||||
auto* d = reinterpret_cast<uint8_t*>(buffer);
|
||||
auto* const a = d;
|
||||
write(d, mNbClasses);
|
||||
write(d, mKeepTopK);
|
||||
write(d, mScoreThreshold);
|
||||
write(d, mIOUThreshold);
|
||||
write(d, mMaxBatchSize);
|
||||
write(d, mAnchorsCnt);
|
||||
PLUGIN_ASSERT(d == a + getSerializationSize());
|
||||
}
|
||||
|
||||
DetectionLayer::DetectionLayer(void const* data, size_t length)
|
||||
{
|
||||
auto const* d = reinterpret_cast<uint8_t const*>(data);
|
||||
auto const* const a = d;
|
||||
mNbClasses = read<int32_t>(d);
|
||||
mKeepTopK = read<int32_t>(d);
|
||||
mScoreThreshold = read<float>(d);
|
||||
mIOUThreshold = read<float>(d);
|
||||
mMaxBatchSize = read<int32_t>(d);
|
||||
mAnchorsCnt = read<int32_t>(d);
|
||||
PLUGIN_VALIDATE(d == a + length);
|
||||
|
||||
mParam.backgroundLabelId = 0;
|
||||
mParam.numClasses = mNbClasses;
|
||||
mParam.keepTopK = mKeepTopK;
|
||||
mParam.scoreThreshold = mScoreThreshold;
|
||||
mParam.iouThreshold = mIOUThreshold;
|
||||
|
||||
mType = DataType::kFLOAT;
|
||||
}
|
||||
|
||||
void DetectionLayer::checkValidInputs(nvinfer1::Dims const* inputs, int32_t nbInputDims)
|
||||
{
|
||||
// classifier_delta_bbox[N, anchors, num_classes*4, 1, 1]
|
||||
// classifier_class[N, anchors, num_classes, 1, 1]
|
||||
// rpn_rois[N, anchors, 4]
|
||||
PLUGIN_VALIDATE(nbInputDims == 3);
|
||||
// delta_bbox
|
||||
PLUGIN_VALIDATE(inputs[0].nbDims == 4 && inputs[0].d[1] == mNbClasses * 4);
|
||||
// score
|
||||
PLUGIN_VALIDATE(inputs[1].nbDims == 4 && inputs[1].d[1] == mNbClasses);
|
||||
// roi
|
||||
PLUGIN_VALIDATE(inputs[2].nbDims == 2 && inputs[2].d[1] == 4);
|
||||
}
|
||||
|
||||
size_t DetectionLayer::getWorkspaceSize(int32_t batchSize) const noexcept
|
||||
{
|
||||
RefineDetectionWorkSpace refine(batchSize, mAnchorsCnt, mParam, mType);
|
||||
return refine.totalSize;
|
||||
}
|
||||
|
||||
Dims DetectionLayer::getOutputDimensions(int32_t index, Dims const* inputs, int32_t nbInputDims) noexcept
|
||||
{
|
||||
try
|
||||
{
|
||||
checkValidInputs(inputs, nbInputDims);
|
||||
PLUGIN_VALIDATE(index == 0);
|
||||
// [N, anchors, (y1, x1, y2, x2, class_id, score)]
|
||||
return {2, {mKeepTopK, 6}};
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
caughtError(e);
|
||||
}
|
||||
return Dims{};
|
||||
}
|
||||
|
||||
int32_t DetectionLayer::enqueue(
|
||||
int32_t batchSize, void const* const* inputs, void* const* outputs, void* workspace, cudaStream_t stream) noexcept
|
||||
{
|
||||
try
|
||||
{
|
||||
PLUGIN_VALIDATE(inputs != nullptr);
|
||||
PLUGIN_VALIDATE(outputs != nullptr);
|
||||
void* detections = outputs[0];
|
||||
|
||||
// refine detection
|
||||
RefineDetectionWorkSpace refDetcWorkspace(batchSize, mAnchorsCnt, mParam, mType);
|
||||
cudaError_t status = RefineBatchClassNMS(stream, batchSize, mAnchorsCnt,
|
||||
DataType::kFLOAT, // mType,
|
||||
mParam, refDetcWorkspace, workspace,
|
||||
inputs[1], // inputs[InScore]
|
||||
inputs[0], // inputs[InDelta],
|
||||
mValidCnt->mPtr, // inputs[InCountValid],
|
||||
inputs[2], // inputs[ROI]
|
||||
detections);
|
||||
|
||||
return status;
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
caughtError(e);
|
||||
}
|
||||
return STATUS_FAILURE;
|
||||
}
|
||||
|
||||
DataType DetectionLayer::getOutputDataType(
|
||||
int32_t index, nvinfer1::DataType const* inputTypes, int32_t nbInputs) const noexcept
|
||||
{
|
||||
// Only DataType::kFLOAT is acceptable by the plugin layer.
|
||||
return DataType::kFLOAT;
|
||||
}
|
||||
|
||||
// Configure the layer with input and output data types.
|
||||
void DetectionLayer::configurePlugin(Dims const* inputDims, int32_t nbInputs, Dims const* outputDims, int32_t nbOutputs,
|
||||
DataType const* inputTypes, DataType const* outputTypes, bool const* inputIsBroadcast,
|
||||
bool const* outputIsBroadcast, PluginFormat floatFormat, int32_t maxBatchSize) noexcept
|
||||
{
|
||||
try
|
||||
{
|
||||
checkValidInputs(inputDims, nbInputs);
|
||||
PLUGIN_VALIDATE(inputDims[0].d[0] == inputDims[1].d[0] && inputDims[1].d[0] == inputDims[2].d[0]);
|
||||
|
||||
mAnchorsCnt = inputDims[2].d[0];
|
||||
mType = inputTypes[0];
|
||||
mMaxBatchSize = maxBatchSize;
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
caughtError(e);
|
||||
}
|
||||
}
|
||||
|
||||
// Attach the plugin object to an execution context and grant the plugin the access to some context resource.
|
||||
void DetectionLayer::attachToContext(
|
||||
cudnnContext* cudnnContext, cublasContext* cublasContext, IGpuAllocator* gpuAllocator) noexcept
|
||||
{
|
||||
}
|
||||
|
||||
// Detach the plugin object from its execution context.
|
||||
void DetectionLayer::detachFromContext() noexcept {}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 1993-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef TRT_DETECTION_LAYER_PLUGIN_H
|
||||
#define TRT_DETECTION_LAYER_PLUGIN_H
|
||||
#include <cuda_runtime_api.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "NvInfer.h"
|
||||
#include "NvInferPlugin.h"
|
||||
#include "common/kernels/maskRCNNKernels.h"
|
||||
|
||||
namespace nvinfer1
|
||||
{
|
||||
namespace plugin
|
||||
{
|
||||
|
||||
class DetectionLayer : public IPluginV2Ext
|
||||
{
|
||||
public:
|
||||
DetectionLayer(int32_t numClasses, int32_t keepTopk, float scoreThreshold, float iouThreshold);
|
||||
|
||||
DetectionLayer(void const* data, size_t length);
|
||||
|
||||
~DetectionLayer() override = default;
|
||||
|
||||
int32_t getNbOutputs() const noexcept override;
|
||||
|
||||
Dims getOutputDimensions(int32_t index, Dims const* inputs, int32_t nbInputDims) noexcept override;
|
||||
|
||||
int32_t initialize() noexcept override;
|
||||
|
||||
void terminate() noexcept override;
|
||||
|
||||
void destroy() noexcept override;
|
||||
|
||||
size_t getWorkspaceSize(int32_t maxBatchSize) const noexcept override;
|
||||
|
||||
int32_t enqueue(int32_t batchSize, void const* const* inputs, void* const* outputs, void* workspace,
|
||||
cudaStream_t stream) noexcept override;
|
||||
|
||||
size_t getSerializationSize() const noexcept override;
|
||||
|
||||
void serialize(void* buffer) const noexcept override;
|
||||
|
||||
bool supportsFormat(DataType type, PluginFormat format) const noexcept override;
|
||||
|
||||
char const* getPluginType() const noexcept override;
|
||||
|
||||
char const* getPluginVersion() const noexcept override;
|
||||
|
||||
IPluginV2Ext* clone() const noexcept override;
|
||||
|
||||
void setPluginNamespace(char const* libNamespace) noexcept override;
|
||||
|
||||
char const* getPluginNamespace() const noexcept override;
|
||||
|
||||
DataType getOutputDataType(
|
||||
int32_t index, nvinfer1::DataType const* inputTypes, int32_t nbInputs) const noexcept override;
|
||||
|
||||
void attachToContext(
|
||||
cudnnContext* cudnnContext, cublasContext* cublasContext, IGpuAllocator* gpuAllocator) noexcept override;
|
||||
|
||||
void configurePlugin(Dims const* inputDims, int32_t nbInputs, Dims const* outputDims, int32_t nbOutputs,
|
||||
DataType const* inputTypes, DataType const* outputTypes, bool const* inputIsBroadcast,
|
||||
bool const* outputIsBroadcast, PluginFormat floatFormat, int32_t maxBatchSize) noexcept override;
|
||||
|
||||
void detachFromContext() noexcept override;
|
||||
|
||||
private:
|
||||
void checkValidInputs(nvinfer1::Dims const* inputs, int32_t nbInputDims);
|
||||
|
||||
int32_t mBackgroundLabel;
|
||||
int32_t mNbClasses;
|
||||
int32_t mKeepTopK;
|
||||
float mScoreThreshold;
|
||||
float mIOUThreshold;
|
||||
|
||||
int32_t mMaxBatchSize;
|
||||
int32_t mAnchorsCnt;
|
||||
std::shared_ptr<CudaBind<int32_t>> mValidCnt; // valid cnt = number of input rois for every image.
|
||||
nvinfer1::DataType mType;
|
||||
RefineNMSParameters mParam;
|
||||
|
||||
std::string mNameSpace;
|
||||
};
|
||||
|
||||
class DetectionLayerPluginCreator : public nvinfer1::pluginInternal::BaseCreator
|
||||
{
|
||||
public:
|
||||
DetectionLayerPluginCreator();
|
||||
|
||||
~DetectionLayerPluginCreator() override {}
|
||||
|
||||
char const* getPluginName() const noexcept override;
|
||||
|
||||
char const* getPluginVersion() const noexcept override;
|
||||
|
||||
PluginFieldCollection const* getFieldNames() noexcept override;
|
||||
|
||||
IPluginV2Ext* createPlugin(char const* name, PluginFieldCollection const* fc) noexcept override;
|
||||
|
||||
IPluginV2Ext* deserializePlugin(char const* name, void const* data, size_t length) noexcept override;
|
||||
|
||||
private:
|
||||
PluginFieldCollection mFC;
|
||||
int32_t mNbClasses;
|
||||
int32_t mKeepTopK;
|
||||
float mScoreThreshold;
|
||||
float mIOUThreshold;
|
||||
std::vector<PluginField> mPluginAttributes;
|
||||
};
|
||||
} // namespace plugin
|
||||
} // namespace nvinfer1
|
||||
#endif // TRT_DETECTION_LAYER_PLUGIN_H
|
||||
Reference in New Issue
Block a user