importKerasLayers
Import layers from Keras network
Description
imports the layers of a TensorFlow™-Keras network from a model file. The function returns the layers defined in the HDF5 (layers
= importKerasLayers(modelfile
).h5
) or JSON (.json
) file given by the file namemodelfile
.
This function requires theDeep Learning Toolbox™ Converter for TensorFlow Modelssupport package. If this support package is not installed, then the function provides a download link.
imports the layers from a TensorFlow-Keras network with additional options specified by one or more name-value pair arguments.layers
= importKerasLayers(modelfile
,Name,Value
)
For example,importKerasLayers(modelfile,'ImportWeights',true)
imports the network layers and the weights from the model filemodelfile
.
Examples
Download and Install Deep Learning Toolbox Converter for TensorFlow Models
Download and install the Deep Learning Toolbox Converter for TensorFlow Models support package.
TypeimportKerasLayers
at the command line.
importKerasLayers
If the Deep Learning Toolbox Converter for TensorFlow Models support package is not installed, then the function provides a link to the required support package in the Add-On Explorer. To install the support package, click the link, and then clickInstall. Check that the installation is successful by importing the layers from the model file'digitsDAGnet.h5'
at the command line. If the required support package is installed, then the function returns aLayerGraph
object.
modelfile ='digitsDAGnet.h5'; net = importKerasLayers(modelfile)
net = LayerGraph with properties: Layers: [13x1 nnet.cnn.layer.Layer] Connections: [13x2 table] InputNames: {'input_1'} OutputNames: {'ClassificationLayer_activation_1'}
Import Layers from Keras Network and Plot Architecture
Import the network layers from the model filedigitsDAGnet.h5
.
modelfile ='digitsDAGnet.h5'; layers = importKerasLayers(modelfile)
layers = LayerGraph with properties: Layers: [13x1 nnet.cnn.layer.Layer] Connections: [13x2 table] InputNames: {'input_1'} OutputNames: {'ClassificationLayer_activation_1'}
Plot the network architecture.
plot(layers)
Import Keras Network Layers and Train Network
Specify the network file to import.
modelfile ='digitsDAGnet.h5';
Import network layers.
layers = importKerasLayers(modelfile)
layers = LayerGraph with properties: Layers: [13x1 nnet.cnn.layer.Layer] Connections: [13x2 table] InputNames: {'input_1'} OutputNames: {'ClassificationLayer_activation_1'}
Load a data set for training a classifier to recognize new digits.
folder = fullfile(toolboxdir('nnet'),'nndemos','nndatasets','DigitDataset'); imds = imageDatastore(folder,...'IncludeSubfolders',true,...'LabelSource','foldernames');
Partition the dataset into training and test sets.
numTrainFiles = 750; [imdsTrain,imdsTest] = splitEachLabel(imds,numTrainFiles,'randomize');
Set the training options.
options = trainingOptions('sgdm',...'MaxEpochs',10,...'InitialLearnRate',0.001);
Train network using training data.
net = trainNetwork(imdsTrain,layers,options);
Training on single CPU. |========================================================================================| | Epoch | Iteration | Time Elapsed | Mini-batch | Mini-batch | Base Learning | | | | (hh:mm:ss) | Accuracy | Loss | Rate | |========================================================================================| | 1 | 1 | 00:00:01 | 15.62% | 12.6982 | 0.0010 | | 1 | 50 | 00:00:17 | 63.28% | 1.2109 | 0.0010 | | 2 | 100 | 00:00:34 | 85.16% | 0.4193 | 0.0010 | | 3 | 150 | 00:00:51 | 96.88% | 0.1749 | 0.0010 | | 4 | 200 | 00:01:06 | 99.22% | 0.0457 | 0.0010 | | 5 | 250 | 00:01:19 | 100.00% | 0.0374 | 0.0010 | | 6 | 300 | 00:01:34 | 96.88% | 0.1223 | 0.0010 | | 7 | 350 | 00:01:50 | 100.00% | 0.0087 | 0.0010 | | 7 | 400 | 00:02:04 | 100.00% | 0.0166 | 0.0010 | | 8 | 450 | 00:02:20 | 100.00% | 0.0098 | 0.0010 | | 9 | 500 | 00:02:38 | 100.00% | 0.0047 | 0.0010 | | 10 | 550 | 00:03:03 | 100.00% | 0.0031 | 0.0010 | | 10 | 580 | 00:03:13 | 100.00% | 0.0059 | 0.0010 | |========================================================================================| Training finished: Max epochs completed.
Run the trained network on the test set that was not used to train the network and predict the image labels (digits).
YPred = classify(net,imdsTest); YTest = imdsTest.Labels;
Calculate the accuracy.
accuracy = sum(YPred == YTest)/numel(YTest)
accuracy = 0.9856
Import Keras Network Architecture and Weights from Same File
Specify the network file to import layers and weights from.
modelfile ='digitsDAGnet.h5';
Import the network architecture and weights from the files you specified. To import the layer weights, specify'ImportWeights'
to betrue
. The function also imports the layers with their weights from the same HDF5 file.
layers = importKerasLayers(modelfile,'ImportWeights',true)
layers = LayerGraph with properties: Layers: [13x1 nnet.cnn.layer.Layer] Connections: [13x2 table] InputNames: {'input_1'} OutputNames: {'ClassificationLayer_activation_1'}
View the size of the weights in the second layer.
weights = layers.Layers(2).Weights; size(weights)
ans =1×47 7 1 20
The function has imported the weights so the layer weights are non-empty.
Import Keras Network Architecture and Weights from Separate Files
Specify the network file to import layers from and the file containing weights.
modelfile ='digitsDAGnet.json'; weights ='digitsDAGnet.weights.h5';
Import the network architecture and weights from the files you specified. The .json file does not include an output layer. Specify the output layer, so that importKerasLayers adds an output layer at the end of the networks architecture.
layers = importKerasLayers(modelfile,...'ImportWeights',true,...'WeightFile',weights,...'OutputLayerType','classification')
layers = LayerGraph with properties: Layers: [13x1 nnet.cnn.layer.Layer] Connections: [13x2 table] InputNames: {'input_1'} OutputNames: {'ClassificationLayer_activation_1'}
Assemble Network from Pretrained Keras Layers
This example shows how to import the layers from a pretrained Keras network, replace the unsupported layers with custom layers, and assemble the layers into a network ready for prediction.
Import Keras Network
Import the layers from a Keras network model. The network in'digitsDAGnetwithnoise.h5'
classifies images of digits.
filename ='digitsDAGnetwithnoise.h5'; lgraph = importKerasLayers(filename,'ImportWeights',true);
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.
The Keras network contains some layers that are not supported by Deep Learning Toolbox. TheimportKerasLayers
function displays a warning and replaces the unsupported layers with placeholder layers.
Plot the layer graph usingplot
.
figure plot(lgraph) title("Imported Network")
Replace Placeholder Layers
To replace the placeholder layers, first identify the names of the layers to replace. Find the placeholder layers usingfindPlaceholderLayers
.
placeholderLayers = findPlaceholderLayers(lgraph)
placeholderLayers = 2x1 PlaceholderLayer array with layers: 1 'gaussian_noise_1' PLACEHOLDER LAYER Placeholder for 'GaussianNoise' Keras layer 2 'gaussian_noise_2' PLACEHOLDER LAYER Placeholder for 'GaussianNoise' Keras layer
Display the Keras configurations of these layers.
placeholderLayers.KerasConfiguration
ans =struct with fields:trainable: 1 name: 'gaussian_noise_1' stddev: 1.5000
ans =struct with fields:trainable: 1 name: 'gaussian_noise_2' stddev: 0.7000
Define a custom Gaussian noise layer. To create this layer, save the filegaussianNoiseLayer.m
in the current folder. Then, create two Gaussian noise layers with the same configurations as the imported Keras layers.
gnLayer1 = gaussianNoiseLayer(1.5,'new_gaussian_noise_1'); gnLayer2 = gaussianNoiseLayer(0.7,'new_gaussian_noise_2');
Replace the placeholder layers with the custom layers usingreplaceLayer
.
lgraph = replaceLayer(lgraph,'gaussian_noise_1',gnLayer1); lgraph = replaceLayer(lgraph,'gaussian_noise_2',gnLayer2);
Plot the updated layer graph usingplot
.
figure plot(lgraph) title("Network with Replaced Layers")
Specify Class Names
If the imported classification layer does not contain the classes, then you must specify these before prediction. If you do not specify the classes, then the software automatically sets the classes to1
,2
, ...,N
, whereN
is the number of classes.
Find the index of the classification layer by viewing theLayers
property of the layer graph.
lgraph.Layers
ans = 15x1 Layer array with layers: 1 'input_1' Image Input 28x28x1 images 2 'conv2d_1' Convolution 20 7x7x1 convolutions with stride [1 1] and padding 'same' 3 'conv2d_1_relu' ReLU ReLU 4 'conv2d_2' Convolution 20 3x3x1 convolutions with stride [1 1] and padding 'same' 5 'conv2d_2_relu' ReLU ReLU 6 'new_gaussian_noise_1' Gaussian Noise Gaussian noise with standard deviation 1.5 7 'new_gaussian_noise_2' Gaussian Noise Gaussian noise with standard deviation 0.7 8 'max_pooling2d_1' Max Pooling 2x2 max pooling with stride [2 2] and padding 'same' 9 'max_pooling2d_2' 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
The classification layer has the name'ClassificationLayer_activation_1'
. View the classification layer and check theClasses
property.
cLayer = lgraph.Layers(end)
cLayer = ClassificationOutputLayer with properties: Name: 'ClassificationLayer_activation_1' Classes: 'auto' ClassWeights: 'none' OutputSize: 'auto' Hyperparameters LossFunction: 'crossentropyex'
Because theClasses
property of the layer is'auto'
, you must specify the classes manually. Set the classes to0
,1
, ...,9
, and then replace the imported classification layer with the new one.
cLayer.Classes = string(0:9)
cLayer = ClassificationOutputLayer with properties: Name: 'ClassificationLayer_activation_1' Classes: [0 1 2 3 4 5 6 7 8 9] ClassWeights: 'none' OutputSize: 10 Hyperparameters LossFunction: 'crossentropyex'
lgraph = replaceLayer(lgraph,'ClassificationLayer_activation_1',cLayer);
Assemble Network
Assemble the layer graph usingassembleNetwork
. The function returns aDAGNetwork
object that is ready to use for prediction.
net = assembleNetwork(lgraph)
net = DAGNetwork with properties: Layers: [15x1 nnet.cnn.layer.Layer] Connections: [15x2 table] InputNames: {'input_1'} OutputNames: {'ClassificationLayer_activation_1'}
Import Keras PReLU Layer
Import layers from a Keras network that has parametric rectified linear unit (PReLU) layers.
A PReLU layer performs a threshold operation, where for each channel, any input value less than zero is multiplied by a scalar. The PReLU operation is given by
where is the input of the nonlinear activation on channel , and is the scaling parameter controlling the slope of the negative part. The subscript in indicates that the parameter can be a vector and the nonlinear activation can vary on different channels.
importKerasNetwork
andimportKerasLayers
can import a network that includes PReLU layers. These functions support both scalar-valued and vector-valued scaling parameters. If a scaling parameter is a vector, then the functions replace the vector with the average of the vector elements. You can modify a PReLU layer to have a vector-valued scaling parameter after import.
Specify the network file to import.
modelfile =“digitsDAGnetwithPReLU.h5';
digitsDAGnetwithPReLU
includes two PReLU layers. One has a scalar-valued scaling parameter, and the other has a vector-valued scaling parameter.
Import the network architecture and weights frommodelfile
.
layers = importKerasLayers(modelfile,'ImportWeights',true);
Warning: Layer 'p_re_lu_1' is a PReLU layer with a vector-valued parameter. The function replaces the parameter with the average of the vector elements. You can change the parameter back to a vector after import.
TheimportKerasLayers
function displays a warning for the PReLu layerp_re_lu_1
. The function replaces the vector-valued scaling parameter ofp_re_lu_1
with the average of the vector elements. You can change the parameter back to a vector. First, find the index of the PReLU layer by viewing theLayers
property.
layers.Layers
ans = 13x1 Layer array with layers: 1 'input_1' Image Input 28x28x1 images 2 'conv2d_1' Convolution 20 7x7x1 convolutions with stride [1 1] and padding 'same' 3 'conv2d_2' Convolution 20 3x3x1 convolutions with stride [1 1] and padding 'same' 4 'p_re_lu_1' PReLU PReLU layer 5 'p_re_lu_2' PReLU PReLU layer 6 'max_pooling2d_1' Max Pooling 2x2 max pooling with stride [2 2] and padding 'same' 7 'max_pooling2d_2' Max Pooling 2x2 max pooling with stride [2 2] and padding 'same' 8 'flatten_1' Keras Flatten Flatten activations into 1-D assuming C-style (row-major) order 9 'flatten_2' Keras Flatten Flatten activations into 1-D assuming C-style (row-major) order 10 'concatenate_1' Depth concatenation Depth concatenation of 2 inputs 11 'dense_1' Fully Connected 10 fully connected layer 12 'dense_1_softmax' Softmax softmax 13 'ClassificationLayer_dense_1' Classification Output crossentropyex
layers
has two PReLU layers. Extract the fourth layerp_re_lu_1
,最初向量值扩展标准ameter for a channel dimension.
tempLayer = layers.Layers(4)
tempLayer = PreluLayer with properties: Name: 'p_re_lu_1' RawAlpha: [20x1 single] Learnable Parameters Alpha: 0.0044 State Parameters No properties. Show all properties
TheRawAlpha
property contains the vector-valued scaling parameter, and theAlpha
property contains a scalar that is an element average of the vector values. ReshapeRawAlpha
to place the vector values in the third dimension, which corresponds to the channel dimension. Then, replaceAlpha
with the reshapedRawAlpha
values.
tempLayer.Alpha = reshape(tempLayer.RawAlpha,[1,1,numel(tempLayer.RawAlpha)])
tempLayer = PreluLayer with properties: Name: 'p_re_lu_1' RawAlpha: [20x1 single] Learnable Parameters Alpha: [1x1x20 single] State Parameters No properties. Show all properties
Replace thep_re_lu_1
layer inlayers
withtempLayer
.
layers = replaceLayer(layers,'p_re_lu_1', tempLayer); layers.Layers(4)
ans = PreluLayer with properties: Name: 'p_re_lu_1' RawAlpha: [20x1 single] Learnable Parameters Alpha: [1x1x20 single] State Parameters No properties. Show all properties
Now thep_re_lu_1
layer has a vector-valued scaling parameter.
Input Arguments
modelfile
—Name of Keras model file
character vector|string scalar
包含网络拱模型文件的名称itecture, and possibly the weights, specified as a character vector or a string scalar. The file must be in the current folder, in a folder on the MATLAB®path, or you must include a full or relative path to the file.
Ifmodelfile
includes
The network architecture and weights, then it must be in HDF5 (
.h5
) format.Only the network architecture, then it can be in HDF5 or JSON (
.json
) format.
Ifmodelfile
includes only the network architecture, then you can optionally supply the weights using the'ImportWeights'
and'WeightFile'
name-value pair arguments. If you supply the weights, then the weights file must be in HDF5 format.
Example:'digitsnet.h5'
Data Types:char
|string
Name-Value Arguments
Specify optional comma-separated pairs ofName,Value
arguments.Name
is the argument name andValue
is the corresponding value.Name
must appear inside quotes. You can specify several name and value pair arguments in any order asName1,Value1,...,NameN,ValueN
.
importKerasLayers(modelfile,'OutputLayerType','classification')
imports the network layers from the model filemodelfile
and adds an output layer for a classification problem at the end of the Keras layers.
OutputLayerType
—Type of output layer
'classification'
|'regression'
|'pixelclassification'
Type of output layer that the function appends to the end of the imported network architecture whenmodelfile
does not specify a loss function, specified as'classification'
,'regression'
, or'pixelclassification'
. Appending apixelClassificationLayer
(Computer Vision Toolbox)object requires Computer Vision Toolbox™.
If a network inmodelfile
has multiple outputs, then you cannot specify the output layer types using this argument.importKerasLayers
inserts placeholder layers for the outputs. After importing, you can find and replace the placeholder layers by usingfindPlaceholderLayers
andreplaceLayer
, respectively.
Example:'OutputLayerType','regression'
ImageInputSize
—Size of input images
vector of two or three numerical values
Size of the input images for the network, specified as a vector of two or three numerical values corresponding to[height,width]
for grayscale images and[height,width,channels]
for color images, respectively. The network uses this information when themodelfile
does not specify the input size.
If a network inmodelfile
has multiple inputs, then you cannot specify the input sizes using this argument.importKerasLayers
inserts placeholder layers for the inputs. After importing, you can find and replace the placeholder layers by usingfindPlaceholderLayers
andreplaceLayer
, respectively.
Example:'ImageInputSize',[28 28]
ImportWeights
—Indicator to import weights
false
(default) |true
Indicator to import weights as well as the network architecture, specified as eitherfalse
ortrue
.
If
'ImportWeights'
istrue
andmodelfile
includes the weights, thenimportKerasLayers
imports the weights frommodelfile
, which must have HDF5 (.h5
) format.If
'ImportWeights'
istrue
andmodelfile
does not include the weights, then you must specify a separate file that includes weights, using the'WeightFile'
name-value pair argument.
Example:'ImportWeights',true
Data Types:logical
WeightFile
—Weight file name
character vector|string scalar
Weight file name, from which to import weights whenmodelfile
does not include weights, specified as a character vector or a string scalar. To use this name-value pair argument, you also must set'ImportWeights'
totrue
.
Weight file must be in the current folder, in a folder on the MATLAB path, or you must include a full or relative path to the file.
Example:'WeightFile','weights.h5'
Data Types:char
|string
Output Arguments
layers
— Network architecture
Layer
array object |LayerGraph
object
Network architecture, returned as aLayer
array object when the Keras network is of typeSequential
, or returned as aLayerGraph
object when the Keras network is of typeModel
.
Limitations
importKerasLayers
supports TensorFlow-Keras versions as follows:The function fully supports TensorFlow-Keras versions up to 2.2.4.
The function offers limited support for TensorFlow-Keras versions 2.2.5 to 2.4.0.
More About
Supported Keras Layers
importKerasLayers
supports the following TensorFlow-Keras layer types for conversion into built-in MATLAB layers, with some limitations.
TensorFlow-Keras Layer | Corresponding Deep Learning Toolbox Layer |
---|---|
Add |
additionLayer |
|
Layers: |
Advanced activations:
|
Layers:
|
AveragePooling1D |
averagePooling1dLayer withPaddingValue specified as'mean' |
AveragePooling2D |
averagePooling2dLayer withPaddingValue specified as'mean' |
BatchNormalization |
batchNormalizationLayer |
Bidirectional(LSTM(__)) |
bilstmLayer |
Concatenate |
depthConcatenationLayer |
Conv1D |
convolution1dLayer |
Conv2D |
convolution2dLayer |
Conv2DTranspose |
transposedConv2dLayer |
CuDNNGRU |
gruLayer |
CuDNNLSTM |
lstmLayer |
Dense |
fullyConnectedLayer |
DepthwiseConv2D |
groupedConvolution2dLayer |
Dropout |
dropoutLayer |
Embedding |
wordEmbeddingLayer (Text Analytics Toolbox) |
Flatten |
nnet.keras.layer.FlattenCStyleLayer |
GlobalAveragePooling1D |
globalAveragePooling1dLayer |
GlobalAveragePooling2D |
globalAveragePooling2dLayer |
GlobalMaxPool1D |
globalMaxPooling1dLayer |
GlobalMaxPool2D |
globalMaxPooling2dLayer |
GRU |
gruLayer |
Input |
imageInputLayer ,sequenceInputLayer , orfeatureInputLayer |
LSTM |
lstmLayer |
MaxPool1D |
maxPooling1dLayer |
MaxPool2D |
maxPooling2dLayer |
Multiply |
multiplicationLayer |
SeparableConv2D |
groupedConvolution2dLayer orconvolution2dLayer |
TimeDistributed |
sequenceFoldingLayer before the wrapped layer, andsequenceUnfoldingLayer after the wrapped layer |
UpSampling2D |
resize2dLayer (Image Processing Toolbox) |
UpSampling3D |
resize3dLayer (Image Processing Toolbox) |
ZeroPadding1D |
nnet.keras.layer.ZeroPadding1DLayer |
ZeroPadding2D |
nnet.keras.layer.ZeroPadding2DLayer |
* For a PReLU layer,importKerasLayers
replaces a vector-valued scaling parameter with the average of the vector elements. You can change the parameter back to a vector after import. For an example, seeImport Keras PReLU Layer.
Supported Keras Loss Functions
importKerasLayers
supports the following Keras loss functions:
mean_squared_error
categorical_crossentropy
sparse_categorical_crossentropy
binary_crossentropy
Use Imported Network Layers on GPU
importKerasLayers
does not execute on a GPU. However,importKerasLayers
进口pretrained层的神经网络for deep learning as aLayer
array orLayerGraph
对象,它可以use on a GPU.
Convert the imported layers to a
DAGNetwork
object by usingassembleNetwork
. On theDAGNetwork
object, you can then predict class labels on either a CPU or GPU by usingclassify
. Specify the hardware requirements using the name-value argumentExecutionEnvironment
. For networks with multiple outputs, use thepredict
function and specify the name-value argumentReturnCategorical
astrue
.Convert the imported
LayerGraph
object to adlnetwork
object by usingdlnetwork
. On thedlnetwork
object, you can then predict class labels on either a CPU or GPU by usingpredict
. The functionpredict
executes on the GPU if either the input data or network parameters are stored on the GPU.If you use
minibatchqueue
to process and manage the mini-batches of input data, theminibatchqueue
object converts the output to a GPU array by default if a GPU is available.Use
dlupdate
to convert the learnable parameters of adlnetwork
object to GPU arrays.dlnet = dlupdate(@gpuarray,dlnet)
You can train the imported layers on either a CPU or GPU by using
trainNetwork
. To specify training options, including options for the execution environment, use thetrainingOptions
function. Specify the hardware requirements using the name-value argumentExecutionEnvironment
. For more information on how to accelerate training, seeScale Up Deep Learning in Parallel, on GPUs, and in the Cloud.
Using a GPU requires Parallel Computing Toolbox™ and a supported GPU device. For information on supported devices, seeGPU Support by Release(Parallel Computing Toolbox).
Tips
If the network contains a layer thatDeep Learning Toolbox Converter for TensorFlow Modelsdoes not support (seeSupported Keras Layers), then
importKerasLayers
inserts a placeholder layer in place of the unsupported layer. To find the names and indices of the unsupported layers in the network, use thefindPlaceholderLayers
function. You then can replace a placeholder layer with a new layer that you define. To replace a layer, usereplaceLayer
.You can replace a placeholder layer with a new layer that you define.
If the network is a series network, then replace the layer in the array directly. For example,
layer(2) = newlayer;
.If the network is a DAG network, then replace the layer using
replaceLayer
. For an example, seeAssemble Network from Pretrained Keras Layers.
You can import a Keras network with multiple inputs and multiple outputs (MIMO). Use
importKerasNetwork
if the network includes input size information for the inputs and loss information for the outputs. Otherwise, useimportKerasLayers
. TheimportKerasLayers
function inserts placeholder layers for the inputs and outputs. After importing, you can find and replace the placeholder layers by usingfindPlaceholderLayers
andreplaceLayer
, respectively. The workflow for importing MIMO Keras networks is the same as the workflow for importing MIMO ONNX™ networks. For an example, seeImport and Assemble ONNX Network with Multiple Outputs. To learn about a deep learning network with multiple inputs and multiple outputs, seeMultiple-Input and Multiple-Output Networks.To use a pretrained network for prediction or transfer learning on new images, you must preprocess your images in the same way the images that were used to train the imported model were preprocessed. The most common preprocessing steps are resizing images, subtracting image average values, and converting the images from BGR images to RGB.
For more information on preprocessing images for training and prediction, seePreprocess Images for Deep Learning.
Alternative Functionality
Use
importKerasNetwork
orimportKerasLayers
to import a TensorFlow-Keras network in HDF5 or JSON format. If the TensorFlow network is in the saved model format, useimportTensorFlowNetwork
orimportTensorFlowLayers
.If you import a custom TensorFlow-Keras layer or if the software cannot convert a TensorFlow-Keras layer into an equivalent built-in MATLAB layer, you can use
importTensorFlowNetwork
orimportTensorFlowLayers
, which try to generate a custom layer. For example,importTensorFlowNetwork
andimportTensorFlowLayers
generate a custom layer when you import a TensorFlow-KerasLambda
layer.
References
[1]Keras: Python深度学习库.https://keras.io.
See Also
importCaffeNetwork
|findPlaceholderLayers
|importKerasNetwork
|replaceLayer
|importCaffeLayers
|assembleNetwork
|exportONNXNetwork
|importONNXLayers
|importONNXNetwork
|importTensorFlowNetwork
|importTensorFlowLayers
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
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)