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
package.
imports a pretrained network from TensorFlow and saves the generated custom layers and associated functions in the
net
= importNetworkFromTensorFlow(modelFolder
,PackageName=CustomLayersPackage
)+
CustomLayersPackage
package.
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 as same way 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
+
package (custom layers and TensorFlow operators) are not accessible if the package parent folder is not on the MATLAB path. For more information, see Packages and the MATLAB Path.CustomLayersPackage
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+
package. For an example, see Import TensorFlow Network with Automatically Generated Custom Layers.CustomLayersPackage
The function imports the TensorFlow layer as a custom layer with a placeholder function.
importNetworkFromTensorFlow
saves the placeholder function in the+ops
subpackage of the+
package. You must complete the placeholder function before you can use the network.CustomLayersPackage
In some cases, the software will indicates that you need to initialize the imported network. For an example, see Import and Initialize TensorFlow Network.
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 R2023b
See 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
- Make Predictions Using dlnetwork Object
- Deploy Imported TensorFlow Model with MATLAB Compiler