scalingLayer
Scaling layer
Description
A scaling layer linearly scales and offsets the input data.
Creation
Description
creates a scaling
layer.layer
= scalingLayer
specifies options using one or more name-value arguments. For example,
layer
= scalingLayer(Name=Value
)Scale=0.5
specifies to scale the input by
0.5
.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: scalingLayer(Scale=0.1,Offset=0.4)
creates a scaling layer
that scales and offsets the input using values of 0.1
and
0.4
, respectively.
Scaling factor, specified as one of these values:
Numeric scalar — Scale all input values using the specified value.
Numeric array — Scale each element of the input using the specified array with implicit expansion.
Scale
and
Offset
must have sizes such that the size of Scale.*X +
Offset
matches the size of X
, where X
is
the layer input. (since R2025a)
Before R2025a: If Scale
and
Offset
are both numeric arrays, then they must be the same
size.
This argument sets the Scale
property.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Since R2025a
Offset, specified as one of these values:
Numeric scalar — Offset all scaled input values using the specified value.
Numeric array — Offset each element of the scaled input using the specified array with implicit expansion.
Scale
and
Offset
must have sizes such that the size of Scale.*X +
Offset
matches the size of X
, where X
is
the layer input. (since R2025a)
Before R2025a: If Scale
and
Offset
are both numeric arrays, then they must be the same
size.
Before R2025a: Use Bias
instead.
This argument sets the Offset
property.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Properties
Scaling
Scaling factor, specified as one of these values:
Numeric scalar — Scale all input values using the specified value.
Numeric array — Scale each element of the input using the specified array with implicit expansion.
Scale
and
Offset
must have sizes such that the size of Scale.*X +
Offset
matches the size of X
, where X
is
the layer input. (since R2025a)
Before R2025a: If Scale
and
Offset
are both numeric arrays, then they must be the same
size.
The ScalingLayer
object stores this property as double type.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Since R2025a
Offset, specified as one of these values:
Numeric scalar — Offset all scaled input values using the specified value.
Numeric array — Offset each element of the scaled input using the specified array with implicit expansion.
Scale
and
Offset
must have sizes such that the size of Scale.*X +
Offset
matches the size of X
, where X
is
the layer input. (since R2025a)
Before R2025a: If Scale
and
Offset
are both numeric arrays, then they must be the same
size.
Before R2025a: Use Bias
instead.
The ScalingLayer
object stores this property as double type.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Layer
This property is read-only.
One-line description of the layer, stored as 'Scaling'
. This
description appears when you display a Layer
array and when you use
the analyzeNetwork
function.
This property is read-only.
Type of the layer, stored as 'Scaling'
. The type appears when
you display a Layer
array and when you use the analyzeNetwork
function.
Data Types: char
This property is read-only.
Number of inputs to the layer, stored as 1
. This layer accepts a
single input only.
Data Types: double
This property is read-only.
Input names, stored as {'in'}
. This layer accepts a single input
only.
Data Types: cell
This property is read-only.
Number of outputs from the layer, stored as 1
. This layer has a
single output only.
Data Types: double
This property is read-only.
Output names, stored as {'out'}
. This layer has a single output
only.
Data Types: cell
Examples
Create a scaling layer that scales the input with a factor of 0.1
and adds an offset of 0.4
.
layer = scalingLayer(Scale=0.1,Offset=0.4);
Include a scaling layer in a layer array.
layers = [ featureInputLayer(1) fullyConnectedLayer(400) reluLayer fullyConnectedLayer(300) reluLayer fullyConnectedLayer(1) tanhLayer scalingLayer(Scale=0.1,Offset=0.4)];
To scale and offset each element of the input using different values, specify the scale and offset using numeric arrays.
Create a scaling layer that scales and offsets the input using the scaling and offset values [1 2 3]'
and [0.1 0.2 0.3]'
, respectively.
layer = scalingLayer(Scale=[1 2 3]',Bias=[0.1 0.2 0.3]');
Include a scaling layer with the same scale and offset in a layer array. In this layer array, the output size of the fully connected layer is 3
(and in turn, the subsequent tanh layer), so the scaling layer receives a 3-by- array, where is the batch size. The scaling layer transforms each 3-by-1 vector in its input using implicit expansion.
layers = [ featureInputLayer(1) fullyConnectedLayer(400) reluLayer fullyConnectedLayer(300) reluLayer fullyConnectedLayer(3) tanhLayer scalingLayer(Scale=[1 2 3]',Bias=[0.1 0.2 0.3]')];
Algorithms
A scaling layer linearly scales and offsets the input data.
The scaling and offset operation is given by Y = Scale.*X + Offset
,
where X
is the layer input. The scaling operation supports implicit
expansion. That is, the layer automatically adjusts the dimensions
Scale
and Offset
so that it has the same size as
the input during the layer operation.
This means you can simplify your code by using arrays of smaller sizes for
Scale
and Offset
, or create a layer that
processes data independently over different dimensions.
Scale
and
Offset
must have sizes such that the size of Scale.*X +
Offset
matches the size of X
, where X
is
the layer input. (since R2025a)
Before R2025a: If Scale
and
Offset
are both numeric arrays, then they must be the same
size.
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 format consists of one or
more of these characters:
"S"
— Spatial"C"
— Channel"B"
— Batch"T"
— Time"U"
— Unspecified
For example, you can describe 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, as having the format "SSCB"
(spatial, spatial, channel, batch).
ScalingLayer
objects apply an element-wise operation and support input
data of any format. The layer does not add or remove any dimensions, so it outputs data with
the same format as its input data.
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 R2019aThis layer now requires Deep Learning Toolbox™ only. In previous releases, this layer also required Reinforcement Learning Toolbox™.
There are some changes to the layer:
The
Bias
property is not recommended. Use theOffset
property instead. Code that uses theBias
property continues to work.The default value of the
Description
property is'Scaling'
. In previous releases, the default value is'Scaling layer'
.Setting the
Description
using a name-value argument is not recommended. Use the default value instead. Code that sets theDescription
argument continues to work.The default value of the
Type
property is'Scaling'
. In previous releases, the default value is"ScalingLayer"
.scalingLayer
objects have different class names. If you have code that refers to the previous class names of these objects, then replace the references with the new class names. In most cases, your code will continue to run.This table shows the change of outputs of the
class
function for this layers.layer
class(layer)
(Before R2025a)class(layer)
(Starting in R2025a)scalingLayer
object'rl.layer.ScalingLayer'
'nnet.cnn.layer.ScalingLayer'
The
isa
function returns the same value as for previous releases. For example, in R2025a, bothisa(layer,"nnet.cnn.layer.ScalingLayer")
andisa(layer,"rl.layer.ScalingLayer")
return1
(true
) forscalingLayer
objects.If you have code that uses the value returned by the
class
function, then you must update your code to use the new class name. For example, replace instances ofwithif class(layer) == "rl.layer.ScalingLayer" ... end
if isa(layer,"nnet.cnn.layer.ScalingLayer") ... end
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
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: United States.
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)