tanhLayer
Hyperbolic tangent (tanh) layer
Description
A hyperbolic tangent (tanh) activation layer applies the tanh function on the layer inputs.
Creation
Properties
Name
— Layer name
""
(default) | character vector | string scalar
NumInputs
— Number of inputs
1
(default)
This property is read-only.
Number of inputs to the layer, returned as 1
. This layer accepts a
single input only.
Data Types: double
InputNames
— Input names
{'in'}
(default)
This property is read-only.
Input names, returned as {'in'}
. This layer accepts a single input
only.
Data Types: cell
NumOutputs
— Number of outputs
1
(default)
This property is read-only.
Number of outputs from the layer, returned as 1
. This layer has a
single output only.
Data Types: double
OutputNames
— Output names
{'out'}
(default)
This property is read-only.
Output names, returned as {'out'}
. This layer has a single output
only.
Data Types: cell
Examples
Create Hyperbolic Tangent Layer
Create a hyperbolic tangent (tanh) layer with the name 'tanh1'
.
layer = tanhLayer('Name','tanh1')
layer = TanhLayer with properties: Name: 'tanh1' Learnable Parameters No properties. State Parameters No properties. Use properties method to see a list of all properties.
Include a tanh layer in a Layer
array.
layers = [
imageInputLayer([28 28 1])
convolution2dLayer(3,16)
batchNormalizationLayer
tanhLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,32)
batchNormalizationLayer
tanhLayer
fullyConnectedLayer(10)
softmaxLayer]
layers = 10x1 Layer array with layers: 1 '' Image Input 28x28x1 images with 'zerocenter' normalization 2 '' 2-D Convolution 16 3x3 convolutions with stride [1 1] and padding [0 0 0 0] 3 '' Batch Normalization Batch normalization 4 '' Tanh Hyperbolic tangent 5 '' 2-D Max Pooling 2x2 max pooling with stride [2 2] and padding [0 0 0 0] 6 '' 2-D Convolution 32 3x3 convolutions with stride [1 1] and padding [0 0 0 0] 7 '' Batch Normalization Batch normalization 8 '' Tanh Hyperbolic tangent 9 '' Fully Connected 10 fully connected layer 10 '' Softmax softmax
Algorithms
Layer Input and Output Formats
Layers in a layer array or layer graph pass data to subsequent layers as formatted dlarray
objects.
The format of a dlarray
object is a string of characters, in which each
character describes the corresponding dimension of the data. The formats consist of one or
more of these characters:
"S"
— Spatial"C"
— Channel"B"
— Batch"T"
— Time"U"
— Unspecified
For example, 2-D image data that is represented as a 4-D array, where the first two dimensions
correspond to the spatial dimensions of the images, the third dimension corresponds to the
channels of the images, and the fourth dimension corresponds to the batch dimension, can be
described as having the format "SSCB"
(spatial, spatial, channel,
batch).
TanhLayer
objects apply an element-wise operation and supports input
data of any format. The layer and does not add or remove any dimensions, so it outputs data
with the same format as its inputs.
Complex Numbers
TanhLayer
objects support complex-valued input
and outputs. (since R2024a) The layer applies the same underlying operation to complex-valued
input as it does to real-valued input and outputs complex-valued data where
applicable.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Version History
Introduced in R2019aR2024a: Support for complex-valued inputs and outputs
TanhLayer
objects support complex-valued input and outputs. The layer applies the same underlying operation to complex-valued input as it does to real-valued input and outputs complex-valued data where applicable.
See Also
trainnet
| trainingOptions
| dlnetwork
| batchNormalizationLayer
| leakyReluLayer
| clippedReluLayer
| reluLayer
| swishLayer
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)