findPlaceholderLayers - Find placeholder layers in network architecture imported from Keras or
ONNX - MATLAB ([original](https://in.mathworks.com/help/deeplearning/ref/findplaceholderlayers.html)) ([raw](?raw))
Main Content
Find placeholder layers in network architecture imported from Keras orONNX
Syntax
Description
[placeholderLayers](#d126e95769) = findPlaceholderLayers([importedLayers](#d126e95726))
returns all placeholder layers that exist in the network architectureimportedLayers
imported by the importKerasLayers or importONNXLayers functions. Placeholder layers are the layers that these functions insert in place of layers that are not supported by Deep Learning Toolbox™.
To use with an imported network, this function requires either the Deep Learning Toolbox Converter for TensorFlow™ Models support package or the Deep Learning Toolbox Converter for ONNX Model Format support package.
[[placeholderLayers](#d126e95769),[indices](#d126e95793)] = findPlaceholderLayers([importedLayers](#d126e95726))
also returns the indices of the placeholder layers.
Examples
Specify the Keras network file to import layers from.
modelfile = 'digitsDAGnetwithnoise.h5';
Import the network architecture. The network includes some layer types that are not supported by Deep Learning Toolbox. The importKerasLayers function replaces each unsupported layer with a placeholder layer and returns a warning message.
lgraph = importKerasLayers(modelfile)
Warning: "importKerasLayers" is not recommended and will be removed in a future release. To import TensorFlow-Keras models, save using the SavedModel format and use importNetworkFromTensorFlow function.
Warning: Unable to import some Keras layers, because they are not supported by the Deep Learning Toolbox. They have been replaced by placeholder layers. To find these layers, call the function findPlaceholderLayers on the returned object.
lgraph = LayerGraph with properties:
InputNames: {'input_1'}
OutputNames: {'ClassificationLayer_activation_1'}
Layers: [15×1 nnet.cnn.layer.Layer]
Connections: [15×2 table]
Display the imported layers of the network. Two placeholder layers replace the Gaussian noise layers in the Keras network.
ans = 15×1 Layer array with layers:
1 'input_1' Image Input 28×28×1 images
2 'conv2d_1' 2-D Convolution 20 7×7 convolutions with stride [1 1] and padding 'same'
3 'conv2d_1_relu' ReLU ReLU
4 'conv2d_2' 2-D Convolution 20 3×3 convolutions with stride [1 1] and padding 'same'
5 'conv2d_2_relu' ReLU ReLU
6 'gaussian_noise_1' GaussianNoise Placeholder for "GaussianNoise" Keras layer
7 'gaussian_noise_2' GaussianNoise Placeholder for "GaussianNoise" Keras layer
8 'max_pooling2d_1' 2-D Max Pooling 2×2 max pooling with stride [2 2] and padding 'same'
9 'max_pooling2d_2' 2-D Max Pooling 2×2 max pooling with stride [2 2] and padding 'same'
10 'flatten_1' Keras Flatten Flatten activations into 1-D assuming C-style (row-major) order
11 'flatten_2' Keras Flatten Flatten activations into 1-D assuming C-style (row-major) order
12 'concatenate_1' Depth concatenation Depth concatenation of 2 inputs
13 'dense_1' Fully Connected 10 fully connected layer
14 'activation_1' Softmax softmax
15 'ClassificationLayer_activation_1' Classification Output crossentropyex
Find the placeholder layers using findPlaceholderLayers
. The output argument contains the two placeholder layers that importKerasLayers
inserted in place of the Gaussian noise layers of the Keras network.
placeholders = findPlaceholderLayers(lgraph)
placeholders = 2×1 PlaceholderLayer array with layers:
1 'gaussian_noise_1' GaussianNoise Placeholder for "GaussianNoise" Keras layer
2 'gaussian_noise_2' GaussianNoise Placeholder for "GaussianNoise" Keras layer
Specify a name for each placeholder layer.
gaussian1 = placeholders(1); gaussian2 = placeholders(2);
Display the configuration of each placeholder layer.
gaussian1.KerasConfiguration
ans = struct with fields: trainable: 1 name: 'gaussian_noise_1' stddev: 1.5000 inbound_nodes: {{1×1 cell}}
gaussian2.KerasConfiguration
ans = struct with fields: trainable: 1 name: 'gaussian_noise_2' stddev: 0.7000 inbound_nodes: {{1×1 cell}}
Input Arguments
Network architecture imported from Keras or ONNX, specified as a dlnetwork
,Layer
array, or LayerGraph
object.
Output Arguments
All placeholder layers in the network architecture, returned as an array of PlaceholderLayer objects.
Indices of placeholder layers, returned as a vector.
- If importedLayers is a layer array, then
indices
are the indices of the placeholder layers inimportedLayers
. - If
importedLayers
is aLayerGraph
object, thenindices
are the indices of the placeholder layers inimportedLayers.Layers
.
If you remove a layer from or add a layer to a Layer
array or LayerGraph
object, then the indices of the other layers in the object can change. You must usefindPlaceholderLayers
again to find the updated indices of the rest of the placeholder layers.
Tips
- If you have installed Deep Learning Toolbox Converter for TensorFlow Models and
findPlaceholderLayers
is unable to find placeholder layers created when the ONNX network is imported, then try updating the Deep Learning Toolbox Converter for TensorFlow Models support package in the Add-On Explorer.
Version History
Introduced in R2017b