TensorRT 8.5.1
nvinfer1::IFullyConnectedLayer Class Reference

A fully connected layer in a network definition. This layer expects an input tensor of three or more non-batch dimensions. The input is automatically reshaped into an MxV tensor X, where V is a product of the last three dimensions and M is a product of the remaining dimensions (where the product over 0 dimensions is defined as 1). For example: More...

#include <NvInfer.h>

Inheritance diagram for nvinfer1::IFullyConnectedLayer:
nvinfer1::ILayer nvinfer1::INoCopy

Public Member Functions

void setNbOutputChannels (int32_t nbOutputs) noexcept
 Set the number of output channels K from the fully connected layer. More...
 
int32_t getNbOutputChannels () const noexcept
 Get the number of output channels K from the fully connected layer. More...
 
void setKernelWeights (Weights weights) noexcept
 Set the kernel weights, given as a KxC matrix in row-major order. More...
 
Weights getKernelWeights () const noexcept
 Get the kernel weights. More...
 
void setBiasWeights (Weights weights) noexcept
 Set the bias weights. More...
 
Weights getBiasWeights () const noexcept
 Get the bias weights. More...
 
void setInput (int32_t index, ITensor &tensor) noexcept
 Append or replace an input of this layer with a specific tensor. More...
 
- Public Member Functions inherited from nvinfer1::ILayer
LayerType getType () const noexcept
 Return the type of a layer. More...
 
void setName (char const *name) noexcept
 Set the name of a layer. More...
 
char const * getName () const noexcept
 Return the name of a layer. More...
 
int32_t getNbInputs () const noexcept
 Get the number of inputs of a layer. More...
 
ITensorgetInput (int32_t index) const noexcept
 Get the layer input corresponding to the given index. More...
 
int32_t getNbOutputs () const noexcept
 Get the number of outputs of a layer. More...
 
ITensorgetOutput (int32_t index) const noexcept
 Get the layer output corresponding to the given index. More...
 
void setInput (int32_t index, ITensor &tensor) noexcept
 Replace an input of this layer with a specific tensor. More...
 
void setPrecision (DataType dataType) noexcept
 Set the computational precision of this layer. More...
 
DataType getPrecision () const noexcept
 get the computational precision of this layer More...
 
bool precisionIsSet () const noexcept
 whether the computational precision has been set for this layer More...
 
void resetPrecision () noexcept
 reset the computational precision for this layer More...
 
void setOutputType (int32_t index, DataType dataType) noexcept
 Set the output type of this layer. More...
 
DataType getOutputType (int32_t index) const noexcept
 get the output type of this layer More...
 
bool outputTypeIsSet (int32_t index) const noexcept
 whether the output type has been set for this layer More...
 
void resetOutputType (int32_t index) noexcept
 reset the output type for this layer More...
 

Protected Member Functions

virtual ~IFullyConnectedLayer () noexcept=default
 
- Protected Member Functions inherited from nvinfer1::ILayer
virtual ~ILayer () noexcept=default
 
- Protected Member Functions inherited from nvinfer1::INoCopy
 INoCopy ()=default
 
virtual ~INoCopy ()=default
 
 INoCopy (INoCopy const &other)=delete
 
INoCopyoperator= (INoCopy const &other)=delete
 
 INoCopy (INoCopy &&other)=delete
 
INoCopyoperator= (INoCopy &&other)=delete
 

Protected Attributes

apiv::VFullyConnectedLayer * mImpl
 
- Protected Attributes inherited from nvinfer1::ILayer
apiv::VLayer * mLayer
 

Detailed Description

A fully connected layer in a network definition. This layer expects an input tensor of three or more non-batch dimensions. The input is automatically reshaped into an MxV tensor X, where V is a product of the last three dimensions and M is a product of the remaining dimensions (where the product over 0 dimensions is defined as 1). For example:

  • If the input tensor has shape {C, H, W}, then the tensor is reshaped into {1, C*H*W}.
  • If the input tensor has shape {P, C, H, W}, then the tensor is reshaped into {P, C*H*W}.

The layer then performs the following operation:

Y := matmul(X, W^T) + bias

Where X is the MxV tensor defined above, W is the KxV weight tensor of the layer, and bias is a row vector size K that is broadcasted to MxK. K is the number of output channels, and configurable via setNbOutputChannels(). If bias is not specified, it is implicitly 0.

The MxK result Y is then reshaped such that the last three dimensions are {K, 1, 1} and the remaining dimensions match the dimensions of the input tensor. For example:

  • If the input tensor has shape {C, H, W}, then the output tensor will have shape {K, 1, 1}.
  • If the input tensor has shape {P, C, H, W}, then the output tensor will have shape {P, K, 1, 1}.
Warning
Do not inherit from this class, as doing so will break forward-compatibility of the API and ABI.
Deprecated:
Deprecated in TensorRT 8.4. Superseded by IMatrixMultiplyLayer.

Constructor & Destructor Documentation

◆ ~IFullyConnectedLayer()

virtual nvinfer1::IFullyConnectedLayer::~IFullyConnectedLayer ( )
protectedvirtualdefaultnoexcept

Member Function Documentation

◆ getBiasWeights()

Weights nvinfer1::IFullyConnectedLayer::getBiasWeights ( ) const
inlinenoexcept

Get the bias weights.

See also
setBiasWeightsWeights()

◆ getKernelWeights()

Weights nvinfer1::IFullyConnectedLayer::getKernelWeights ( ) const
inlinenoexcept

Get the kernel weights.

See also
setKernelWeights()

◆ getNbOutputChannels()

int32_t nvinfer1::IFullyConnectedLayer::getNbOutputChannels ( ) const
inlinenoexcept

Get the number of output channels K from the fully connected layer.

See also
setNbOutputChannels()

◆ setBiasWeights()

void nvinfer1::IFullyConnectedLayer::setBiasWeights ( Weights  weights)
inlinenoexcept

Set the bias weights.

Bias is optional. To omit bias, set the count value in the weights structure to zero.

See also
getBiasWeightsWeights()

◆ setInput()

void nvinfer1::ILayer::setInput ( int32_t  index,
ITensor tensor 
)
inlinenoexcept

Append or replace an input of this layer with a specific tensor.

Parameters
indexthe index of the input to modify.
tensorthe new input tensor

Only index 0 (data input) is valid, unless explicit-quantization mode is enabled. In explicit-quantization mode, input with index 1 is the kernel-weights tensor, if present. The kernel-weights tensor must be a build-time constant (computable at build-time via constant-folding) and an output of a dequantize layer. If input index 1 is used then the kernel-weights parameter must be set to empty Weights.

See also
getKernelWeights(), setKernelWeights()

The indices are as follows:

  • 0: The input activation tensor.
  • 1: The kernel weights tensor (a constant tensor).

If this function is called with the value 1, then the function getNbInputs() changes from returning 1 to 2.

◆ setKernelWeights()

void nvinfer1::IFullyConnectedLayer::setKernelWeights ( Weights  weights)
inlinenoexcept

Set the kernel weights, given as a KxC matrix in row-major order.

See also
getKernelWeights()

◆ setNbOutputChannels()

void nvinfer1::IFullyConnectedLayer::setNbOutputChannels ( int32_t  nbOutputs)
inlinenoexcept

Set the number of output channels K from the fully connected layer.

If executing this layer on DLA, number of output channels must in the range [1,8192].

See also
getNbOutputChannels()

Member Data Documentation

◆ mImpl

apiv::VFullyConnectedLayer* nvinfer1::IFullyConnectedLayer::mImpl
protected

The documentation for this class was generated from the following file: