PlaceholderLayer
Layer replacing an unsupported Keras or ONNX layer
PlaceholderLayer is not recommended. Use importNetworkFromTensorFlow or importNetworkFromONNX to import a Keras or ONNX™ network as a dlnetwork object with custom
layers.
Description
PlaceholderLayer is a layer that importKerasLayers and importONNXLayers insert into a layer array or layer graph in place of an
unsupported Keras or ONNX layer.
Creation
Importing layers from a Keras or ONNX network that has layers that are not supported by Deep Learning Toolbox™ creates PlaceholderLayer objects.
Properties
Layer name, specified as a character vector or a string scalar.
Data Types: char | string
Layer description, specified as a character vector or a string scalar.
Data Types: char | string
Layer type, specified as a character vector or a string scalar.
Data Types: char | string
Keras configuration of a layer, specified as a structure. The fields of the structure depend on the layer type.
Note
This property only exists if the layer was created when importing a Keras network.
Data Types: struct
ONNX configuration of a layer, specified as a structure. The fields of the structure depend on the layer type.
Note
This property only exists if the layer was created when importing an ONNX network.
Data Types: struct
Imported weights, specified as a structure.
Data Types: struct
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.
lgraph.Layers
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 Fully connected layer with output size 10
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}}
Version History
Introduced in R2017bPlaceholderLayer is not recommended. Use importNetworkFromTensorFlow or importNetworkFromONNX to import a Keras or ONNX network as a dlnetwork object with custom
layers.
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.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- 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)