TensorRT  7.0.0.11
nvinfer1::IFullyConnectedLayer Class Referenceabstract

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

Public Member Functions

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

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.

Member Function Documentation

virtual Weights nvinfer1::IFullyConnectedLayer::getBiasWeights ( ) const
pure virtual

Get the bias weights.

See also
setBiasWeightsWeights()
virtual Weights nvinfer1::IFullyConnectedLayer::getKernelWeights ( ) const
pure virtual

Get the kernel weights.

See also
setKernelWeights()
virtual int nvinfer1::IFullyConnectedLayer::getNbOutputChannels ( ) const
pure virtual

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

See also
setNbOutputChannels()
virtual void nvinfer1::IFullyConnectedLayer::setBiasWeights ( Weights  weights)
pure virtual

Set the bias weights.

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

See also
getBiasWeightsWeights()
void nvinfer1::IFullyConnectedLayer::setInput ( int  index,
ITensor tensor 
)
pure virtual

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

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

For a fulyconnected layer, the values 0-2 are valid. The value 1 override kernel weights, and the value 2 override bias weights. Conversely, this input tensor can be overridden via appropriate set call. The indices are as follows:

Index | Description 0 | The input activation tensor. 1 | The kernel weights tensor. 2 | The bias weights tensor.

If this function is called with a value greater than 0, then the function getNbInputs() changes

Implements nvinfer1::ILayer.

virtual void nvinfer1::IFullyConnectedLayer::setKernelWeights ( Weights  weights)
pure virtual

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

See also
getKernelWeights()
virtual void nvinfer1::IFullyConnectedLayer::setNbOutputChannels ( int  nbOutputs)
pure virtual

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()

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