pretrainedEncoderNetwork
Syntax
Description
creates an encoder network, net
= pretrainedEncoderNetwork(networkName
,depth
)net
, from a pretrained network,
networkName
. The encoder network performs depth
downsampling operations.
This function requires Deep Learning Toolbox™.
[
also returns the names, net
,outputNames
] = pretrainedEncoderNetwork(networkName
,depth
)outputNames
, of activation layers that occur
directly before downsampling operations. These activations correspond to features of
interest at particular spatial resolutions or scales.
Examples
Create Encoder Network from Pretrained SqueezeNet Network
Create an encoder with three downsampling operations based on the SqueezeNet pretrained network.
encoderNet = pretrainedEncoderNetwork('squeezenet',3)
encoderNet = dlnetwork with properties: Layers: [33x1 nnet.cnn.layer.Layer] Connections: [36x2 table] Learnables: [26x3 table] State: [0x3 table] InputNames: {'data'} OutputNames: {'fire5-concat'} Initialized: 1 View summary with summary.
Display the encoder network.
analyzeNetwork(encoderNet)
Create U-Net from Pretrained GoogLeNet
Create a GAN encoder network with four downsampling operations from a pretrained GoogLeNet network.
depth = 4;
[encoder,outputNames] = pretrainedEncoderNetwork('googlenet',depth);
Determine the input size of the encoder network.
inputSize = encoder.Layers(1).InputSize;
Determine the output size of the activation layers in the encoder network by creating a sample data input and then calling forward
, which returns the activations.
exampleInput = dlarray(zeros(inputSize),'SSC'); exampleOutput = cell(1,length(outputNames)); [exampleOutput{:}] = forward(encoder,exampleInput,'Outputs',outputNames);
Determine the number of channels in the decoder blocks as the length of the third channel in each activation.
numChannels = cellfun(@(x) size(extractdata(x),3),exampleOutput); numChannels = fliplr(numChannels(1:end-1));
Define a function that creates an array of layers for one decoder block.
decoderBlock = @(block) [ transposedConv2dLayer(2,numChannels(block),'Stride',2) convolution2dLayer(3,numChannels(block),'Padding','same') reluLayer convolution2dLayer(3,numChannels(block),'Padding','same') reluLayer];
Create the decoder module with the same number of upsampling blocks as there are downsampling blocks in the encoder module.
decoder = blockedNetwork(decoderBlock,depth);
Create the U-Net network by connecting the encoder module and decoder module and adding skip connections.
net = encoderDecoderNetwork([224 224 3],encoder,decoder, ... 'OutputChannels',3,'SkipConnections','concatenate')
net = dlnetwork with properties: Layers: [139x1 nnet.cnn.layer.Layer] Connections: [167x2 table] Learnables: [116x3 table] State: [0x3 table] InputNames: {'data'} OutputNames: {'encoderDecoderFinalConvLayer'} Initialized: 1 View summary with summary.
Display the network.
analyzeNetwork(net)
Input Arguments
networkName
— Pretrained network name
"googlenet"
| "inceptionv3"
| "resnet101"
| "vgg19"
| ...
Pretrained network name, specified as one of these string values. You must install the associated Add-On for the selected pretrained network.
"alexnet"
— Seealexnet
(Deep Learning Toolbox) for more information."googlenet"
— Seegooglenet
(Deep Learning Toolbox) for more information."inceptionresnetv2"
— Seeinceptionresnetv2
(Deep Learning Toolbox) for more information."inceptionv3"
— Seeinceptionv3
(Deep Learning Toolbox) for more information."mobilenetv2"
— Seemobilenetv2
(Deep Learning Toolbox) for more information."resnet18"
— Seeresnet18
(Deep Learning Toolbox) for more information."resnet50"
— Seeresnet50
(Deep Learning Toolbox) for more information."resnet101"
— Seeresnet101
(Deep Learning Toolbox) for more information."squeezenet"
— Seesqueezenet
(Deep Learning Toolbox) for more information."vgg16"
— Seevgg16
(Deep Learning Toolbox) for more information."vgg19"
— Seevgg19
(Deep Learning Toolbox) for more information.
Data Types: char
| string
depth
— Number of downsampling operations
2
(default) | positive integer
Number of downsampling operations in the encoder, specified as a positive integer.
The encoder downsamples the input by a factor of 2^depth
. You
cannot specify a depth greater than the depth of the pretrained network.
Output Arguments
net
— Encoder network
dlnetwork
object
outputNames
— Layer names
string vector
Layer names in the network net
that come directly before
downsampling operations, returned as a string vector.
Version History
Introduced in R2021a
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: .
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)