Main Content

findPlaceholderLayers

Find placeholder layers in network architecture imported from Keras or ONNX

findPlaceholderLayers is not recommended. Use importNetworkFromTensorFlow or importNetworkFromONNX to import a Keras or ONNX™ network as a dlnetwork object with custom layers.

Description

example

placeholderLayers = findPlaceholderLayers(importedLayers) returns all placeholder layers that exist in the network architecture importedLayers 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,indices] = findPlaceholderLayers(importedLayers) also returns the indices of the placeholder layers.

Examples

collapse all

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: [15x1 nnet.cnn.layer.Layer]
    Connections: [15x2 table]

Display the imported layers of the network. Two placeholder layers replace the Gaussian noise layers in the Keras network.

lgraph.Layers
ans = 
  15x1 Layer array with layers:

     1   'input_1'                            Image Input             28x28x1 images
     2   'conv2d_1'                           2-D Convolution         20 7x7 convolutions with stride [1  1] and padding 'same'
     3   'conv2d_1_relu'                      ReLU                    ReLU
     4   'conv2d_2'                           2-D Convolution         20 3x3 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         2x2 max pooling with stride [2  2] and padding 'same'
     9   'max_pooling2d_2'                    2-D Max Pooling         2x2 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 = 
  2x1 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: {{1x1 cell}}

gaussian2.KerasConfiguration
ans = struct with fields:
        trainable: 1
             name: 'gaussian_noise_2'
           stddev: 0.7000
    inbound_nodes: {{1x1 cell}}

Input Arguments

collapse all

Network architecture imported from Keras or ONNX, specified as a Layer array or LayerGraph object.

Output Arguments

collapse all

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 in importedLayers.

  • If importedLayers is a LayerGraph object, then indices are the indices of the placeholder layers in importedLayers.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 use findPlaceholderLayers 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

expand all