importNetworkFromTensorFlow
Syntax
Description
imports a pretrained TensorFlow™ network from the folder net
= importNetworkFromTensorFlow(modelFolder
)modelFolder
, which contains the
network in the SavedModel format. The network comprises the layers defined in the
saved_model
file with the .pb
extension and the
learned weights in the variables
subfolder. The function returns the
network net
as an initialized dlnetwork
object.
importNetworkFromTensorFlow
requires the Deep Learning Toolbox™ Converter for TensorFlow Models support package. If this support package is not installed, then
importNetworkFromTensorFlow
provides a download link.
Note
The importNetworkFromTensorFlow
function can generate a custom layer when
importing a TensorFlow layer. For more information, see Algorithms. The function saves
the generated custom layers in the +
modelFolder
namespace.
specifies additional options using one or more name-value arguments. For example, you can
specify a namespace in which to save the generated custom layers and associated
functions.net
= importNetworkFromTensorFlow(modelFolder
,Name=Value
)
Examples
Input Arguments
Output Arguments
More About
Tips
To use a pretrained network for prediction or transfer learning on new images, you must preprocess your images in the same way as the images that you use to train the imported model. The most common preprocessing steps are resizing images, subtracting image average values, and converting the images from BGR format to RGB format.
For more information about preprocessing images for training and prediction, see Preprocess Images for Deep Learning.
The members of the
+
namespace (custom layers and TensorFlow operators) are not accessible if the namespace parent folder is not on the MATLAB path. For more information, see Namespaces and the MATLAB Path.CustomLayersNamespace
MATLAB uses one-based indexing, whereas Python® uses zero-based indexing. In other words, the first element in an array has an index of 1 and 0 in MATLAB and Python, respectively. For more information about MATLAB indexing, see Array Indexing. In MATLAB, to use an array of indices (
ind
) created in Python, convert the array toind+1
.For more tips, see Tips on Importing Models from TensorFlow, PyTorch, and ONNX.
Algorithms
The importNetworkFromTensorFlow
function imports a TensorFlow layer into MATLAB by trying these steps in order:
The function tries to import the TensorFlow layer as a built-in MATLAB layer. For more information, see TensorFlow-Keras Layers Supported for Conversion into Built-In MATLAB Layers.
The function tries to import the TensorFlow layer as a built-in MATLAB function. For more information, see Supported TensorFlow Operators.
The function tries to import the TensorFlow layer as a custom layer.
importNetworkFromTensorFlow
saves the generated custom layers and the associated functions in the+
namespace. For an example, see Import TensorFlow Network with Automatically Generated Custom Layers.CustomLayersNamespace
The function imports the TensorFlow layer as a custom layer with a placeholder function.
importNetworkFromTensorFlow
saves the placeholder function in the+ops
inner namespace of the+
namespace. You must complete the placeholder function before you can use the network.CustomLayersNamespace
In some cases, the software will indicates that you need to initialize the imported network. For an example, see Import and Initialize TensorFlow Network.
Alternative Functionality
App
You can also import models from external platforms using the Deep Network Designer
app. The app uses the importNetworkFromTensorFlow
function to import the network. On
import, the app shows an import report with details about any issues that require
attention.
References
[1] TensorFlow. “TensorFlow.” Accessed July 3, 2023. https://www.tensorflow.org/.
[2] TensorFlow. “Using the SavedModel Format | TensorFlow Core.” Accessed July 3, 2023. https://www.tensorflow.org/guide/saved_model.
Version History
Introduced in R2023bSee Also
importNetworkFromONNX
| importNetworkFromPyTorch
| exportONNXNetwork
| exportNetworkToTensorFlow
| trainnet
| dlnetwork
| dlarray
Topics
- Interoperability Between Deep Learning Toolbox, TensorFlow, PyTorch, and ONNX
- Tips on Importing Models from TensorFlow, PyTorch, and ONNX
- Inference Comparison Between TensorFlow and Imported Networks for Image Classification
- Pretrained Deep Neural Networks
- Deploy Imported TensorFlow Model with MATLAB Compiler