Import pretrained Keras network and weights
imports a pretrained TensorFlow-Keras network and its weights with additional options specified by one or more
name-value pair arguments.net
= importKerasNetwork(modelfile
,Name,Value
)
For example, importKerasNetwork(modelfile,'WeightFile',weights)
imports the network from the model file modelfile
and weights from the
weight file weights
. In this case, modelfile
can be in
HDF5 or JSON format, and the weight file must be in HDF5 format.
importKerasNetwork
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.
If the network contains a layer that Deep Learning Toolbox Converter for TensorFlow Models does not support (see Supported Keras Layers), then
importKerasNetwork
returns an error message. In this case, you can still
use importKerasLayers
to import the network architecture and weights.
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, use importKerasLayers
. The importKerasLayers
function
inserts placeholder layers for the inputs and outputs. After importing, you can find and
replace the placeholder layers by using findPlaceholderLayers
and replaceLayer
,
respectively. The workflow for importing MIMO Keras networks is the same as the workflow
for importing MIMO ONNX™ networks. For an example, see Import and Assemble ONNX Network with Multiple Outputs. To learn about a deep
learning network with multiple inputs and multiple outputs, see Multiple-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, see Preprocess Images for Deep Learning.
Use importKerasNetwork
or importKerasLayers
to
import a TensorFlow-Keras network in HDF5 or JSON format. If the TensorFlow network is in the saved model format, use
importTensorFlowNetwork
or
importTensorFlowLayers
.
[1] Keras: The Python Deep Learning library. https://keras.io.
exportONNXNetwork
| importCaffeLayers
| importCaffeNetwork
| importKerasLayers
| importONNXLayers
| importONNXNetwork
| importTensorFlowLayers
| importTensorFlowNetwork