assembleNetwork
(Not recommended) Assemble deep learning network from pretrained layers
The assembleNetwork
function is not recommended. Use dlnetwork
objects instead. For more information, see Version History.
To train a network from scratch, use the trainnet
function.
Description
assembles the layer array or layer graph assembledNet
= assembleNetwork(layers
)layers
into a deep learning
network ready to use for prediction.
Examples
Assemble Network from Layers
Assemble a neural network from pretrained layers without training.
Define a simple LSTM network.
numChannels = 3;
numHiddenUnits = 100;
numClasses = 10;
layers = [
sequenceInputLayer(numChannels)
lstmLayer(numHiddenUnits,OutputMode="last")
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
For the learnable layers in the network, manually set the properties that correspond to the learnable parameters. You can import or load the parameters from external sources such as MAT files. For illustrative purposes, this example sets the learnable parameters to random values.
layers(2).InputWeights = rand(4*numHiddenUnits,numChannels); layers(2).RecurrentWeights = rand(4*numHiddenUnits,numHiddenUnits); layers(2).Bias = rand(4*numHiddenUnits,1); layers(3).Weights = rand(numClasses,numHiddenUnits); layers(3).Bias = rand(numClasses,1);
Set the Classes
property of the classification output
layer.
classNames = string(1:10); layers(5).Classes = classNames;
Assemble the network using the assembleNetwork
function. The
output network is a SeriesNetwork
object that is ready to use for
prediction.
net = assembleNetwork(layers)
net = SeriesNetwork with properties: Layers: [5×1 nnet.cnn.layer.Layer] InputNames: {'sequenceinput'} OutputNames: {'classoutput'}
Input Arguments
layers
— Neural network layers
Layer
array | LayerGraph
object
Neural network layers, specified as a Layer
array
or a LayerGraph
object.
To create a neural network with all layers connected sequentially, you can use a
Layer
array as the input argument. In this case, the returned
neural network is a SeriesNetwork
object.
A directed acyclic graph (DAG) neural network has a complex structure in which layers
can have multiple inputs and outputs. To create a DAG neural network, specify the neural
network architecture as a LayerGraph
object and then use that layer graph as the input argument to
assembleNetwork
.
The assembleNetwork
function supports neural networks with at most one
sequence input layer.
For a list of built-in layers, see List of Deep Learning Layers.
Output Arguments
assembledNet
— Assembled network
SeriesNetwork
object | DAGNetwork
object
Assembled network ready for prediction, returned as a SeriesNetwork
object or a DAGNetwork
object. The returned network depends on the layers
input argument:
If
layers
is aLayer
array, thenassembledNet
is aSeriesNetwork
object.If
layers
is aLayerGraph
object, thenassembledNet
is aDAGNetwork
object.
Version History
Introduced in R2018bR2024a: Not recommended
assembleNetwork
is not recommended. Use dlnetwork
objects instead.
The assembleNetwork
function returns SeriesNetwork
and DAGNetwork
objects, which are not recommended. There are no plans to
remove support for the assembleNetwork
function. However,
dlnetwork
objects are recommended instead and have these
advantages:
dlnetwork
objects are a unified data type that supports network building, prediction, built-in training, visualization, compression, verification, and custom training loops.dlnetwork
objects support a wider range of network architectures that you can create or import from external platforms.The
trainnet
function supportsdlnetwork
objects, which enables you to easily specify loss functions. You can select from built-in loss functions or specify a custom loss function.Training and prediction with
dlnetwork
objects is typically faster thanLayerGraph
andtrainNetwork
workflows.
To update your code to use dlnetwork
objects, use one of these
options:
Not Recommended | Recommended |
---|---|
Assemble SeriesNetwork or DAGNetwork object
using a layer array or layer graph. | Build dlnetwork object directly and do
not include any output layers. Most functions that support
LayerGraph objects also support dlnetwork
objects. To initialize the network, use the initialize function. |
Assemble imported network returned by the
importKerasLayers ,
importTensorFlowLayers , or
importONNXLayers functions. | Import the network using the importNetworkFromTensorFlow or importNetworkFromONNX functions. |
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi 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)