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...
Public Member Functions | |
virtual void | setNbOutputChannels (int32_t nbOutputs)=0 |
Set the number of output channels K from the fully connected layer. More... | |
virtual int32_t | 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 (int32_t index, ITensor &tensor)=0 |
Append or replace an input of this layer with a specific tensor. More... | |
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 int32_t | getNbInputs () const =0 |
Get the number of inputs of a layer. More... | |
virtual ITensor * | getInput (int32_t index) const =0 |
Get the layer input corresponding to the given index. More... | |
virtual int32_t | getNbOutputs () const =0 |
Get the number of outputs of a layer. More... | |
virtual ITensor * | getOutput (int32_t 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 (int32_t index, DataType dataType)=0 |
Set the output type of this layer. More... | |
virtual DataType | getOutputType (int32_t index) const =0 |
get the output type of this layer More... | |
virtual bool | outputTypeIsSet (int32_t index) const =0 |
whether the output type has been set for this layer More... | |
virtual void | resetOutputType (int32_t index)=0 |
reset the output type for this layer More... | |
Protected Member Functions | |
virtual | ~IFullyConnectedLayer () |
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:
{C, H, W}
, then the tensor is reshaped into {1, C*H*W}
.{P, C, H, W}
, then the tensor is reshaped into {P, C*H*W}
.The layer then performs the following operation:
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:
{C, H, W}
, then the output tensor will have shape {K, 1, 1}
.{P, C, H, W}
, then the output tensor will have shape {P, K, 1, 1}
.
|
inlineprotectedvirtual |
|
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].
|
pure virtual |
Get the number of output channels K
from the fully connected layer.
|
pure virtual |
Set the kernel weights, given as a KxC
matrix in row-major order.
|
pure virtual |
Get the kernel weights.
|
pure virtual |
Set the bias weights.
Bias is optional. To omit bias, set the count value in the weights structure to zero.
|
pure virtual |
Get the bias weights.
|
pure virtual |
Append or replace an input of this layer with a specific tensor.
index | the index of the input to modify. |
tensor | the new input tensor |
For a IFullyConnectedLayer, only index 0 is valid unless explicit precision mode is enabled. With explicit precision mode, values 0-1 are valid where value 1 overrides kernel weights. Kernel weights tensor (computed at build-time) must be an output of dequantize scale layer (i.e. a scale layer with int8 input and float output) in explicit precision network. Conversely, this input tensor can be overridden via appropriate set call. The indices are as follows:
If this function is called with a value greater than 0, then the function getNbInputs() changes
Implements nvinfer1::ILayer.
|
pure virtualinherited |
Return the type of a layer.
|
pure virtualinherited |
Set the name of a layer.
This method copies the name string.
|
pure virtualinherited |
|
pure virtualinherited |
Get the number of inputs of a layer.
|
pure virtualinherited |
Get the layer input corresponding to the given index.
index | The index of the input tensor. |
|
pure virtualinherited |
Get the number of outputs of a layer.
|
pure virtualinherited |
Get the layer output corresponding to the given index.
|
pure virtualinherited |
Set the computational precision of this layer.
Setting the precision allows TensorRT to choose implementation which run at this computational precision. Layer input type would also get inferred from layer computational precision. TensorRT could still choose a non-conforming fastest implementation ignoring set layer precision. Use BuilderFlag::kSTRICT_TYPES to force choose implementations with requested precision. In case no implementation is found with requested precision, TensorRT would choose available fastest implementation. If precision is not set, TensorRT will select the layer computational precision and layer input type based on performance considerations and the flags specified to the builder.
precision | the computational precision. |
|
pure virtualinherited |
get the computational precision of this layer
|
pure virtualinherited |
whether the computational precision has been set for this layer
|
pure virtualinherited |
reset the computational precision for this layer
|
pure virtualinherited |
Set the output type of this layer.
Setting the output type constrains TensorRT to choose implementations which generate output data with the given type. If it is not set, TensorRT will select output type based on layer computational precision. TensorRT could still choose non-conforming output type based on fastest implementation. Use BuilderFlag::kSTRICT_TYPES to force choose requested output type. In case layer precision is not specified, output type would depend on chosen implementation based on performance considerations and the flags specified to the builder.
This method cannot be used to set the data type of the second output tensor of the TopK layer. The data type of the second output tensor of the topK layer is always Int32. Also the output type of all layers that are shape operations must be DataType::kINT32, and all attempts to set the output type to some other data type will be ignored except for issuing an error message.
Note that the layer output type is generally not identical to the data type of the output tensor, as TensorRT may insert implicit reformatting operations to convert the former to the latter. Calling layer->setOutputType(i, type) has no effect on the data type of the i-th output tensor of layer, and users need to call layer->getOutput(i)->setType(type) to change the tensor data type. This is particularly relevant if the tensor is marked as a network output, since only setType() [but not setOutputType()] will affect the data representation in the corresponding output binding.
index | the index of the output to set |
dataType | the type of the output |
|
pure virtualinherited |
get the output type of this layer
index | the index of the output |
|
pure virtualinherited |
whether the output type has been set for this layer
index | the index of the output |
|
pure virtualinherited |
reset the output type for this layer
index | the index of the output |