chore: import upstream snapshot with attribution
Docker Image CI / build-ubuntu2004 (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:36:55 +08:00
commit c8a779b1bb
1887 changed files with 3245738 additions and 0 deletions
@@ -0,0 +1,21 @@
#
# 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(
pyramidROIAlignPlugin.cpp
pyramidROIAlignPlugin.h
)
+138
View File
@@ -0,0 +1,138 @@
# PyramidROIAlign [DEPRECATED]
**This plugin is deprecated since TensorRT 11.0 and will be removed in a future release. No alternatives are planned to be provided.**
**Table Of Contents**
- [Changelog](#changelog)
- [Description](#description)
- [Structure](#structure)
- [Parameters](#parameters)
- [Compatibility Modes](#compatibility-modes)
- [Additional Resources](#additional-resources)
- [License](#license)
- [Known issues](#known-issues)
## Changelog
Mar 2026
Deprecated this plugin. No alternatives are planned to be provided.
February 2022
Major refactoring of the plugin to add new features and compatibility modes.
June 2019
This is the first release of this `README.md` file.
## Description
The `PyramidROIAlign` plugin performs the ROIAlign operations on the output feature maps of an FPN (Feature Pyramid Network). This is used in many implementations of FasterRCNN and MaskRCNN. This operation is also known as ROIPooling.
## Structure
#### Inputs
This plugin works in NCHW format. It takes five input tensors:
`rois` is the proposal ROI coordinates, these usually come from a Proposals layer or an NMS operation. Its shape is `[N, R, 4]` where `N` is the batch_size, `R` is the number of ROI candidates and `4` is the number of coordinates.
`feature_map_[0-3]` are the four feature map outputs of an FPN. It is expected these to form a multi-scale pyramid, with the 0th feature map being the highest resolution map. For example:
- `feature_map_0` with shape `[N, C, 256, 256]`, usually corresponds to `P2`.
- `feature_map_1` with shape `[N, C, 128, 128]`, usually corresponds to `P3`.
- `feature_map_2` with shape `[N, C, 64, 64]`, usually corresponds to `P4`.
- `feature_map_3` with shape `[N, C, 32, 32]`, usually corresponds to `P5`.
#### Outputs
This plugin generates one output tensor of shape `[N, R, C, pooled_size, pooled_size]` where `C` is the same number of channels as the feature maps, and `pooled_size` is the configured height (and width) of the feature area after ROIAlign.
## Parameters
This plugin has the plugin creator class `PyramidROIAlignPluginCreator` and the plugin class `PyramidROIAlign`.
The following parameters are used to create a `PyramidROIAlign` instance:
| Type | Parameter | Default | Description
|---------|------------------------|------------|--------------------------------------------------------
| `int` | `pooled_size` | 7 | The spatial size of a feature area after ROIAlgin will be `[pooled_size, pooled_size]`
| `int[]` | `image_size` | 1024,1024 | An 2-element array with the input image size of the entire network, in `[image_height, image_width]` layout
| `int` | `fpn_scale` | 224 | The canonical ImageNet size with which the FPN scale map selection is calculated.
| `int` | `sampling_ratio` | 0 | If set to 1 or larger, the number of samples to take for each output element. If set to 0, this will be calculated adaptively by the size of the ROI.
| `int` | `roi_coords_absolute` | 1 | If set to 0, the ROIs are normalized in [0-1] range. If set to 1, the ROIs are in full image space.
| `int` | `roi_coords_swap` | 0 | If set to 0, the ROIs are in `[x1,y1,x2,y2]` format (PyTorch standard). If set to 1, they are in `[y1,x1,y2,x2]` format (TensorFlow standard).
| `int` | `roi_coords_plusone` | 0 | If set to 1, the ROI area will be calculated with a +1 offset on each dimension to enforce a minimum size for malformed ROIs.
| `int` | `roi_coords_transform` | 2 | The coordinate transformation method to use for the ROI Align operation. If set to 2, `half_pixel` sampling will be performed. If set to 1, `output_half_pixel` will be performed. If set to 0, no pixel offset will be applied. More details on compatibility modes below.
## Compatibility Modes
There exist many implementations of FasterRCNN and MaskRCNN, and unfortunately, there is no consensus on a canonical way to execute the ROI Pooling of an FPN. This plugin attempts to support multiple common implementations, configurable via the various parameters that have been exposed.
#### Detectron 2
To replicate the standard ROI Pooling behavior of [Detectron 2](https://github.com/facebookresearch/detectron2), set the parameters as follows:
- `roi_coords_transform`: 2. This implementation uses half_pixel coordinate offsets.
- `roi_coords_plusone`: 0. This implementation does not offset the ROI area calculation.
- `roi_coords_swap`: 0. This implementation follows the PyTorch standard for coordinate layout.
- `roi_coords_absolute`: 1. This implementation works will full-size ROI coordinates.
- `sampling_ratio`: 0. This implementation uses an adaptive sampling ratio determined from each ROI area.
- `fpn_scale`: 224. This implementation uses the standard 224 value to determine the scale selection thresholds.
#### MaskRCNN Benchmark
To replicate the standard ROI Pooling behavior of [maskrcnn-benchmark](https://github.com/facebookresearch/maskrcnn-benchmark), set the parameters as follows:
- `roi_coords_transform`: 1. This implementation uses output_half_pixel coordinate offsets.
- `roi_coords_plusone`: 1. This implementation offsets the ROI area calculation by adding 1 to each ROI dimension.
- `roi_coords_swap`: 0. This implementation follows the PyTorch standard for coordinate layout.
- `roi_coords_absolute`: 1. This implementation works will full-size ROI coordinates.
- `sampling_ratio`: 2. This implementation performs two samples per output element.
- `fpn_scale`: 224. This implementation uses the standard 224 value to determine the scale selection thresholds.
#### Backward-Compatibility
This plugin underwent a major refactoring since its initial version. In order to replicate the original plugin behavior, use the following parameters or set the `legacy` parameter to 1.
- `roi_coords_transform`: -1. This is a special mode exclusively to allow back-compatibility with the original PyramidROIAlign plugin.
- `roi_coords_plusone`: 0. The original implementation had no such logic.
- `roi_coords_swap`: 1. The original implementation expected TensorFlow-like coordinate layout.
- `roi_coords_absolute`: 0. The original implementation expected normalized ROI coordinates.
- `sampling_ratio`: 1. The original implementation performed a single sample per output element.
- `fpn_scale`: 158. The original implementation used a non-standard FPN scale threshold which works out to canonical value of 158, use this value to replicate the old behavior.
#### Other Implementations
Other FPN ROI Pooling implementations may be adapted by having a better understanding of how the various parameters work internally.
**FPN Scale**: This values helps to determine the threshold used to select one feature map or another, according to the size of each ROI. The value defined here comes from the canonical ImageNet size as defined in Equation 1 of the original [FPN paper](https://arxiv.org/pdf/1612.03144.pdf). This size defines the minimum `sqrt(height * width)` that will be sampled from the `P4` feature map. Therefore, by setting the default value of 224, the following feature map selection schedule is used:
- `sqrt(height * width)` between [0 - 111]: Sample from `P2`
- `sqrt(height * width)` between [112 - 223]: Sample from `P3`
- `sqrt(height * width)` between [224 - 447]: Sample from `P4`
- `sqrt(height * width)` between [448 - max]: Sample from `P5`
If your FPN implementation uses a different mapping, set the `fpn_scale` parameter such that its value thresholds the `P4` feature map, `fpn_scale/2` thresholds `P3`, and `fpn_scale*2` thresholds `P5`.
**Coordinate Transformation**: This flag primarily defines various offsets applied to coordinates when performing the bilinear interpolation sampling for ROI Align. The three supported values work as follows:
- `roi_coords_transform` = -1: This is a back-compatibility that calculates the scale by subtracting one to both the input and output dimensions. This is similar to the `align_corners` resize method.
- `roi_coords_transform` = 0: This is a naive implementation where no pixel offset is applied anywhere. It is similar to the `asymmetric` resize method.
- `roi_coords_transform` = 1: This performs half pixel offset by applying a 0.5 offset only in the output element sampling. This is similar to the `output_half_pixel` ROI Align method.
- `roi_coords_transform` = 2: This performs half pixel offset by applying a 0.5 offset in the output element sampling, but also to the input map coordinate. This is similar to the `half_pixel` ROI Align method, and is the favored method of performing ROI Align.
**Force Malformed Boxes by +1**: Some legacy implementations of ROI Pooling, especially those that do not deal properly with pixel sampling, enforce a minimum ROI area size. This is performed by adding a value of 1, in absolute image space, to each dimension of the ROI box. This method is not very common, but some [older implementations](https://github.com/facebookresearch/maskrcnn-benchmark/blob/main/maskrcnn_benchmark/csrc/cuda/ROIPool_cuda.cu#L35-L37) use it, so this attribute has been exposed to replicate this behavior.
## Additional Resources
The following resources provide a deeper understanding of the `PyramidROIAlign` plugin:
- [MaskRCNN](https://github.com/matterport/Mask_RCNN)
- [FPN](https://arxiv.org/abs/1612.03144)
## 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.
## Known issues
There are no known issues in this plugin.
@@ -0,0 +1,434 @@
/*
* 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 "pyramidROIAlignPlugin.h"
#include "common/plugin.h"
#include <cuda_runtime_api.h>
#include <math.h>
#include <memory>
#include <string_view>
using namespace nvinfer1;
using namespace plugin;
using nvinfer1::plugin::PyramidROIAlign;
using nvinfer1::plugin::PyramidROIAlignPluginCreator;
namespace
{
char const* const kPYRAMIDROIALGIN_PLUGIN_VERSION{"1"};
char const* const kPYRAMIDROIALGIN_PLUGIN_NAME{"PyramidROIAlign_TRT"};
} // namespace
PyramidROIAlignPluginCreator::PyramidROIAlignPluginCreator()
{
mPluginAttributes.clear();
mPluginAttributes.emplace_back(PluginField("fpn_scale", nullptr, PluginFieldType::kINT32, 1));
mPluginAttributes.emplace_back(PluginField("pooled_size", nullptr, PluginFieldType::kINT32, 1));
mPluginAttributes.emplace_back(PluginField("image_size", nullptr, PluginFieldType::kINT32, 2));
mPluginAttributes.emplace_back(PluginField("roi_coords_absolute", nullptr, PluginFieldType::kINT32, 1));
mPluginAttributes.emplace_back(PluginField("roi_coords_swap", nullptr, PluginFieldType::kINT32, 1));
mPluginAttributes.emplace_back(PluginField("roi_coords_plusone", nullptr, PluginFieldType::kINT32, 1));
mPluginAttributes.emplace_back(PluginField("roi_coords_transform", nullptr, PluginFieldType::kINT32, 1));
mPluginAttributes.emplace_back(PluginField("sampling_ratio", nullptr, PluginFieldType::kINT32, 1));
mPluginAttributes.emplace_back(PluginField("legacy", nullptr, PluginFieldType::kINT32, 1));
mFC.nbFields = mPluginAttributes.size();
mFC.fields = mPluginAttributes.data();
}
char const* PyramidROIAlignPluginCreator::getPluginName() const noexcept
{
return kPYRAMIDROIALGIN_PLUGIN_NAME;
}
char const* PyramidROIAlignPluginCreator::getPluginVersion() const noexcept
{
return kPYRAMIDROIALGIN_PLUGIN_VERSION;
}
PluginFieldCollection const* PyramidROIAlignPluginCreator::getFieldNames() noexcept
{
return &mFC;
}
IPluginV2Ext* PyramidROIAlignPluginCreator::createPlugin(char const* name, PluginFieldCollection const* fc) noexcept
{
try
{
// Default values for the plugin creator, these will be used when the corresponding
// plugin field is not passed, allowing to have defaults for "optional" ONNX attributes.
int32_t pooledSize = 7;
int32_t transformCoords = 2;
bool absCoords = true;
bool swapCoords = false;
bool plusOneCoords = false;
bool legacy = false;
int32_t samplingRatio = 0;
xy_t imageSize = {dimToInt32(MaskRCNNConfig::IMAGE_SHAPE.d[1]), dimToInt32(MaskRCNNConfig::IMAGE_SHAPE.d[2])};
int32_t fpnScale = 224;
using namespace std::string_view_literals;
PluginField const* fields = fc->fields;
for (int32_t i = 0; i < fc->nbFields; ++i)
{
std::string_view const attrName = fields[i].name;
if (attrName == "fpn_scale"sv)
{
PLUGIN_VALIDATE(fields[i].type == PluginFieldType::kINT32);
fpnScale = *(static_cast<int32_t const*>(fields[i].data));
PLUGIN_VALIDATE(fpnScale >= 1);
}
if (attrName == "pooled_size"sv)
{
PLUGIN_VALIDATE(fields[i].type == PluginFieldType::kINT32);
pooledSize = *(static_cast<int32_t const*>(fields[i].data));
PLUGIN_VALIDATE(pooledSize >= 1);
}
if (attrName == "image_size"sv)
{
PLUGIN_VALIDATE(fields[i].type == PluginFieldType::kINT32);
PLUGIN_VALIDATE(fields[i].length == 2);
auto const dims = static_cast<int32_t const*>(fields[i].data);
imageSize.y = dims[0];
imageSize.x = dims[1];
PLUGIN_VALIDATE(imageSize.y >= 1);
PLUGIN_VALIDATE(imageSize.x >= 1);
}
if (attrName == "roi_coords_absolute"sv)
{
PLUGIN_VALIDATE(fields[i].type == PluginFieldType::kINT32);
absCoords = *(static_cast<int32_t const*>(fields[i].data));
}
if (attrName == "roi_coords_swap"sv)
{
PLUGIN_VALIDATE(fields[i].type == PluginFieldType::kINT32);
swapCoords = *(static_cast<int32_t const*>(fields[i].data));
}
if (attrName == "roi_coords_plusone"sv)
{
PLUGIN_VALIDATE(fields[i].type == PluginFieldType::kINT32);
plusOneCoords = *(static_cast<int32_t const*>(fields[i].data));
}
if (attrName == "roi_coords_transform"sv)
{
PLUGIN_VALIDATE(fields[i].type == PluginFieldType::kINT32);
transformCoords = *(static_cast<int32_t const*>(fields[i].data));
}
if (attrName == "sampling_ratio"sv)
{
PLUGIN_VALIDATE(fields[i].type == PluginFieldType::kINT32);
samplingRatio = *(static_cast<int32_t const*>(fields[i].data));
PLUGIN_VALIDATE(samplingRatio >= 0);
}
if (attrName == "legacy"sv)
{
PLUGIN_ASSERT(fields[i].type == PluginFieldType::kINT32);
legacy = *(static_cast<int32_t const*>(fields[i].data));
}
}
return new PyramidROIAlign(pooledSize, transformCoords, absCoords, swapCoords, plusOneCoords, samplingRatio,
legacy, imageSize, fpnScale);
}
catch (std::exception const& e)
{
caughtError(e);
}
return nullptr;
}
IPluginV2Ext* PyramidROIAlignPluginCreator::deserializePlugin(
char const* name, void const* data, size_t length) noexcept
{
try
{
return new PyramidROIAlign(data, length);
}
catch (std::exception const& e)
{
caughtError(e);
}
return nullptr;
}
PyramidROIAlign::PyramidROIAlign(int32_t pooledSize, int32_t transformCoords, bool absCoords, bool swapCoords,
bool plusOneCoords, int32_t samplingRatio, bool legacy, xy_t imageSize, int32_t fpnScale)
: mPooledSize({pooledSize, pooledSize})
, mImageSize(imageSize)
, mFPNScale(fpnScale)
, mTransformCoords(transformCoords)
, mAbsCoords(absCoords)
, mSwapCoords(swapCoords)
, mPlusOneCoords(plusOneCoords)
, mSamplingRatio(samplingRatio)
, mIsLegacy(legacy)
{
PLUGIN_VALIDATE(pooledSize >= 1);
PLUGIN_VALIDATE(samplingRatio >= 0);
PLUGIN_VALIDATE(fpnScale >= 1);
}
int32_t PyramidROIAlign::getNbOutputs() const noexcept
{
return 1;
}
int32_t PyramidROIAlign::initialize() noexcept
{
return 0;
}
void PyramidROIAlign::terminate() noexcept {}
void PyramidROIAlign::destroy() noexcept
{
delete this;
}
size_t PyramidROIAlign::getWorkspaceSize(int32_t) const noexcept
{
return 0;
}
bool PyramidROIAlign::supportsFormat(DataType type, PluginFormat format) const noexcept
{
return (type == DataType::kFLOAT && format == PluginFormat::kLINEAR);
}
char const* PyramidROIAlign::getPluginType() const noexcept
{
return kPYRAMIDROIALGIN_PLUGIN_NAME;
}
char const* PyramidROIAlign::getPluginVersion() const noexcept
{
return kPYRAMIDROIALGIN_PLUGIN_VERSION;
}
IPluginV2Ext* PyramidROIAlign::clone() const noexcept
{
try
{
auto plugin = std::make_unique<PyramidROIAlign>(*this);
plugin->setPluginNamespace(mNameSpace.c_str());
return plugin.release();
}
catch (std::exception const& e)
{
caughtError(e);
}
return nullptr;
}
void PyramidROIAlign::setPluginNamespace(char const* libNamespace) noexcept
{
mNameSpace = libNamespace;
}
char const* PyramidROIAlign::getPluginNamespace() const noexcept
{
return mNameSpace.c_str();
}
void PyramidROIAlign::check_valid_inputs(nvinfer1::Dims const* inputs, int32_t nbInputDims)
{
// to be compatible with tensorflow node's input:
// roi: [N, anchors, 4],
// feature_map list(4 maps): p2, p3, p4, p5
PLUGIN_ASSERT(nbInputDims == 1 + mFeatureMapCount);
nvinfer1::Dims rois = inputs[0];
PLUGIN_ASSERT(rois.nbDims == 2);
PLUGIN_ASSERT(rois.d[1] == 4);
for (int32_t i = 1; i < nbInputDims; ++i)
{
nvinfer1::Dims dims = inputs[i];
// CHW with the same #C
PLUGIN_ASSERT(dims.nbDims == 3 && dims.d[0] == inputs[i].d[0]);
}
}
Dims PyramidROIAlign::getOutputDimensions(int32_t index, Dims const* inputs, int32_t nbInputDims) noexcept
{
check_valid_inputs(inputs, nbInputDims);
PLUGIN_ASSERT(index == 0);
nvinfer1::Dims result{};
result.nbDims = 4;
// mROICount
result.d[0] = inputs[0].d[0];
// mFeatureLength
result.d[1] = inputs[1].d[0];
// height
result.d[2] = mPooledSize.y;
// width
result.d[3] = mPooledSize.x;
return result;
}
int32_t PyramidROIAlign::enqueue(
int32_t batch_size, void const* const* inputs, void* const* outputs, void* workspace, cudaStream_t stream) noexcept
{
void* const pooled = outputs[0];
cudaError_t status;
// Support legacy UFF mode
if (mIsLegacy)
{
// Legacy values
mTransformCoords = -1;
mPlusOneCoords = 0;
mSwapCoords = true;
mAbsCoords = false;
mSamplingRatio = 1;
float const firstThreshold
= (224 * 224 * 2.F / (MaskRCNNConfig::IMAGE_SHAPE.d[1] * MaskRCNNConfig::IMAGE_SHAPE.d[2])) / (4.F * 4.F);
status = roiAlign(stream, batch_size, mImageSize, mFeatureLength, mROICount, firstThreshold, mTransformCoords,
mAbsCoords, mSwapCoords, mPlusOneCoords, mSamplingRatio, inputs[0], &inputs[1], mFeatureSpatialSize, pooled,
mPooledSize);
}
else
{
// As per FPN paper equation 1 (https://arxiv.org/pdf/1612.03144.pdf)
// the default 224 FPN scale corresponds to the canonical ImageNet size
// used to define the ROI scale threshold that samples from P4. Because the
// plugin works with normalized ROI coordinates, the FPN scale must be normalized
// by the input image size.
float const scale = static_cast<float>(mFPNScale);
float const normScale = sqrtf(scale * scale / (mImageSize.y * mImageSize.x));
// Furthermore, the roiAlign kernel expects a first threshold instead. This is
// the *area* of an ROI but for one level down, i.e. at the P2->P3 transition.
float const firstThreshold = normScale * normScale / 4.F;
status = roiAlign(stream, batch_size, mImageSize, mFeatureLength, mROICount, firstThreshold, mTransformCoords,
mAbsCoords, mSwapCoords, mPlusOneCoords, mSamplingRatio, inputs[0], &inputs[1], mFeatureSpatialSize, pooled,
mPooledSize);
}
return status;
}
size_t PyramidROIAlign::getSerializationSize() const noexcept
{
return sizeof(int32_t) * 2 // mPooledSize
+ sizeof(int32_t) * 2 // mImageSize
+ sizeof(int32_t) // mFeatureLength
+ sizeof(int32_t) // mROICount
+ sizeof(int32_t) // mFPNScale
+ sizeof(int32_t) // mTransformCoords
+ sizeof(bool) // mAbsCoords
+ sizeof(bool) // mSwapCoords
+ sizeof(bool) // mPlusOneCoords
+ sizeof(int32_t) // mSamplingRatio
+ sizeof(bool) // mIsLegacy
+ sizeof(int32_t) * 8; // mFeatureSpatialSize
}
void PyramidROIAlign::serialize(void* buffer) const noexcept
{
char *d = reinterpret_cast<char*>(buffer), *a = d;
write(d, mPooledSize.y);
write(d, mPooledSize.x);
write(d, mImageSize.y);
write(d, mImageSize.x);
write(d, mFeatureLength);
write(d, mROICount);
write(d, mFPNScale);
write(d, mTransformCoords);
write(d, mAbsCoords);
write(d, mSwapCoords);
write(d, mPlusOneCoords);
write(d, mSamplingRatio);
write(d, mIsLegacy);
write(d, mFeatureSpatialSize[0].y);
write(d, mFeatureSpatialSize[0].x);
write(d, mFeatureSpatialSize[1].y);
write(d, mFeatureSpatialSize[1].x);
write(d, mFeatureSpatialSize[2].y);
write(d, mFeatureSpatialSize[2].x);
write(d, mFeatureSpatialSize[3].y);
write(d, mFeatureSpatialSize[3].x);
PLUGIN_ASSERT(d == a + getSerializationSize());
}
PyramidROIAlign::PyramidROIAlign(void const* data, size_t length)
{
deserialize(static_cast<int8_t const*>(data), length);
}
void PyramidROIAlign::deserialize(int8_t const* data, size_t length)
{
auto const* d{data};
mPooledSize = {read<int32_t>(d), read<int32_t>(d)};
mImageSize = {read<int32_t>(d), read<int32_t>(d)};
mFeatureLength = read<int32_t>(d);
mROICount = read<int32_t>(d);
mFPNScale = read<int32_t>(d);
mTransformCoords = read<int32_t>(d);
mAbsCoords = read<bool>(d);
mSwapCoords = read<bool>(d);
mPlusOneCoords = read<bool>(d);
mSamplingRatio = read<int32_t>(d);
mIsLegacy = read<bool>(d);
mFeatureSpatialSize[0].y = read<int32_t>(d);
mFeatureSpatialSize[0].x = read<int32_t>(d);
mFeatureSpatialSize[1].y = read<int32_t>(d);
mFeatureSpatialSize[1].x = read<int32_t>(d);
mFeatureSpatialSize[2].y = read<int32_t>(d);
mFeatureSpatialSize[2].x = read<int32_t>(d);
mFeatureSpatialSize[3].y = read<int32_t>(d);
mFeatureSpatialSize[3].x = read<int32_t>(d);
PLUGIN_VALIDATE(d == data + length);
}
// Return the DataType of the plugin output at the requested index
DataType PyramidROIAlign::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 PyramidROIAlign::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
{
PLUGIN_ASSERT(supportsFormat(inputTypes[0], floatFormat));
check_valid_inputs(inputDims, nbInputs);
PLUGIN_ASSERT(nbOutputs == 1);
PLUGIN_ASSERT(nbInputs == 1 + mFeatureMapCount);
mROICount = inputDims[0].d[0];
mFeatureLength = inputDims[1].d[0];
for (size_t layer = 0; layer < mFeatureMapCount; ++layer)
{
mFeatureSpatialSize[layer] = {dimToInt32(inputDims[layer + 1].d[1]), dimToInt32(inputDims[layer + 1].d[2])};
}
}
// Attach the plugin object to an execution context and grant the plugin the access to some context resource.
void PyramidROIAlign::attachToContext(
cudnnContext* cudnnContext, cublasContext* cublasContext, IGpuAllocator* gpuAllocator) noexcept
{
}
// Detach the plugin object from its execution context.
void PyramidROIAlign::detachFromContext() noexcept {}
@@ -0,0 +1,133 @@
/*
* 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_PYRAMID_ROIALIGN_PLUGIN_H
#define TRT_PYRAMID_ROIALIGN_PLUGIN_H
#include <cuda_runtime_api.h>
#include <string.h>
#include <string>
#include <vector>
#include "NvInfer.h"
#include "NvInferPlugin.h"
#include "common/kernels/maskRCNNKernels.h"
#include "common/mrcnn_config.h"
namespace nvinfer1
{
namespace plugin
{
class TRT_DEPRECATED_BECAUSE("Outdated use case. No alternatives planned.") PyramidROIAlign : public IPluginV2Ext
{
public:
PyramidROIAlign(int32_t pooledSize, int32_t transformCoords, bool absCoords, bool swapCoords, bool plusOneCoords,
int32_t samplingRatio, bool legacy, xy_t roiRange, int32_t fpnScale);
PyramidROIAlign(void const* data, size_t length);
~PyramidROIAlign() 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) const noexcept override;
int32_t enqueue(int32_t batch_size, 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 deserialize(int8_t const* data, size_t length);
void check_valid_inputs(nvinfer1::Dims const* inputs, int32_t nbInputDims);
static int32_t const mFeatureMapCount = 4;
xy_t mPooledSize{};
xy_t mImageSize{};
int32_t mFeatureLength{};
int32_t mROICount{};
int32_t mFPNScale{};
int32_t mTransformCoords{};
bool mAbsCoords{};
bool mSwapCoords{};
bool mPlusOneCoords{};
int32_t mSamplingRatio{};
bool mIsLegacy{false};
xy_t mFeatureSpatialSize[mFeatureMapCount]{};
std::string mNameSpace{};
};
class TRT_DEPRECATED_BECAUSE("Outdated use case. No alternatives planned.") PyramidROIAlignPluginCreator
: public nvinfer1::pluginInternal::BaseCreator
{
public:
PyramidROIAlignPluginCreator();
~PyramidROIAlignPluginCreator() 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;
std::vector<PluginField> mPluginAttributes;
};
} // namespace plugin
} // namespace nvinfer1
#endif // TRT_PYRAMID_ROIALIGN_PLUGIN_H