Train Deep Learning Model inMATLAB
You can train and customize a deep learning model in various ways—for example, you can retrain a pretrained model with new data (transfer learning), train a network from scratch, or define a deep learning model as a function and use a custom training loop. Use this flow chart to choose the training method that is best suited for your task.
Tip
For information on computer vision workflows, including for object detection, seeComputer Vision Using Deep Learning. For information on importing networks and network architectures from TensorFlow™-Keras, Caffe, and the ONNX™ (Open Neural Network Exchange) model format, seeDeep Learning Import and Export.
Training Methods
This table provides information about the different training methods.
Method | More Information |
---|---|
Use network directly | If a pretrained network already performs the task you require, then you do not need to retrain the network. Instead, you can make predictions with the network directly by using the For an example, seeClassify Image Using GoogLeNet. |
Train network usingtrainingOptions andtrainNetwork |
If you have a network specified as a layer array or layer graph, and the For an example showing how to retrain a network (transfer learning), seeTrain Deep Learning Network to Classify New Images. For an example showing how to train a network from scratch, seeCreate Simple Deep Learning Network for Classification. |
Train network usingdlnetwork object and custom training loop |
For most tasks, you can control the training algorithm details using the For loss functions that cannot be specified using an output layer, you can specify the loss in a custom training loop. For an example showing how to train a network with a custom learning rate schedule, seeTrain Network Using Custom Training Loop. To learn, more seeDefine Custom Training Loops, Loss Functions, and Networks. |
Train network using model function and custom training loop | For networks that cannot be created using layer graphs, you can define a custom network as a function. For an example showing how to train a deep learning model defined as a function, seeTrain Network Using Model Function. If you can create parts of the network using a layer graph, then you can define those parts as layer graphs and the unsupported parts using model functions. |
Decisions
This table provides more information on each decision in the flow chart.
Decision | More Information |
---|---|
Does Deep Learning Toolbox™ provide a suitable pretrained network? | For most tasks, you can use or retrain a pretrained network such as For a list of pretrained deep learning networks in MATLAB®, seePretrained Deep Neural Networks. You can use pretrained networks directly with new data, or you can retrain them with new data for different tasks using transfer learning. |
Can you use the network without retraining? | If a pretrained network already performs the task you need, then you can use the network directly without retraining. For example, you can use the If you need to retrain the network—for example, to classify a different set of classes—then you can retrain the network using transfer learning. |
Can you define the model as a layer array or graph? | 您可以指定作为躺大多数深度学习模型er array or layer graph. In other words, you can define the model as a collection of layers with layer outputs connected to other layer inputs. Some network architectures cannot be defined as a layer graph. For example, Siamese networks require weight sharing and cannot be defined as a layer graph. For these networks, you must define the model as a function. For an example, seeTrain Network Using Model Function. |
网络只有一个输出吗? | For networks with multiple outputs, you must train the network using a custom training loop. For an example, seeTrain Network with Multiple Outputs. |
Does Deep Learning Toolbox provide the intermediate layers you need? | Deep Learning Toolbox provides many different layers for deep learning tasks. For a list of layers, seeList of Deep Learning Layers. If Deep Learning Toolbox provides the intermediate layers (layers in the middle of the network) that you need, then you can define the network as a layer array or layer graph using these layers. Otherwise, try defining any unsupported layers as custom layers. For more information, seeDefine Custom Deep Learning Layers. |
Can you define the unsupported intermediate layers as custom layers? | If Deep Learning Toolbox does not provide the layer you need, then you can try defining a custom deep learning layer. For more information, seeDefine Custom Deep Learning Layers. If you can define custom layers for any unsupported layers, then you can include these custom layers in a layer array or layer graph. Otherwise, specify the deep learning model using a function and train the model using a custom training loop. For an example, seeTrain Network Using Model Function. |
Does Deep Learning Toolbox provide the output layers you need? | Output layers specify the loss function used for training. Deep Learning Toolbox provides different output layers for deep learning tasks. For example, If Deep Learning Toolbox provides the output layers that you need, then you can define a layer graph using these layers. Otherwise, try defining any unsupported output layers as a custom layer. For more information, seeDefine Custom Deep Learning Layers. |
Can you define the unsupported output layers as custom layers? | If Deep Learning Toolbox does not provide the output layer you need, then you can try defining a custom output layer. For more information, seeDefine Custom Deep Learning Layers. If you can define a custom output layer for any unsupported output layers, then you can include these custom layers in a layer array or layer graph. Otherwise, train the model using a |
Does thetrainingOptions function provide the options you need? |
The If the |
See Also
Related Topics
- Pretrained Deep Neural Networks
- Classify Image Using GoogLeNet
- Train Deep Learning Network to Classify New Images
- Create Simple Deep Learning Network for Classification
- List of Deep Learning Layers
- Define Custom Deep Learning Layers
- Train Network Using Custom Training Loop
- Define Custom Training Loops, Loss Functions, and Networks
- Train Network Using Model Function