Main Content

importCaffeNetwork

Import pretrained convolutional neural network models from Caffe

Description

example

net= importCaffeNetwork(protofile,datafile)imports a pretrained network from Caffe[1]. The function returns the pretrained network with the architecture specified by the.prototxtfileprotofileand with network weights specified by the.caffemodelfiledatafile.

This function requiresDeep Learning Toolbox™ Importer for Caffe Modelssupport package. If this support package is not installed, the function provides a download link.

You can download pretrained networks from Caffe Model Zoo[2].

net= importCaffeNetwork(___,Name,Value)returns a network with additional options specified by one or moreName,Valuepair arguments using any of the previous syntaxes.

Examples

collapse all

Download and installDeep Learning Toolbox Importer for Caffe Modelssupport package.

To download the required support package, typeimportCaffeNetworkat the command line.

importCaffeNetwork

IfDeep Learning Toolbox Importer for Caffe Modelssupport 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.

Specify files to import.

protofile ='digitsnet.prototxt'; datafile ='digits_iter_10000.caffemodel';

Import network.

net = importCaffeNetwork(protofile,datafile)
net = SeriesNetwork with properties: Layers: [7×1 nnet.cnn.layer.Layer] InputNames: {'testdata'} OutputNames: {'ClassificationOutput'}

Input Arguments

collapse all

File name of the.prototxtfile containing the network architecture, specified as a character vector or a string scalar.protofilemust be in the current folder, in a folder on the MATLAB®path, or you must include a full or relative path to the file. If the.prototxtfile does not specify the size of the input data, you must specify the size using the'InputSize'name-value pair argument.

Example:'digitsnet.prototxt'

File name of the.caffemodelfile containing the network weights, specified as a character vector or a string scalar.datafilemust be in the current folder, in a folder on the MATLAB path, or you must include a full or relative path to the file. To import network layers without weights, useimportCaffeLayers.

Example:'digits_iter_10000.caffemodel'

Name-Value Arguments

Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, whereNameis the argument name andValueis the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and encloseNamein quotes.

Example:importCaffeNetwork(protofile,datafile,'AverageImage',I)imports a pretrained network using the average imageIfor zero-center normalization.

Size of input data, specified as a row vector. Specify a vector of two or three integer values[h,w], or[h,w,c]corresponding to the height, width, and the number of channels of the input data. If the.prototxtfile does not specify the size of the input data, then you must specify the input size.

Example:[28 28 1]

Average image for zero-center normalization, specified as a matrix. If you specify an image, then you must specify an image of the same size as the input data. If you do not specify an image, the software uses the data specified in the.prototxtfile, if present. Otherwise, the function sets theNormalizationproperty of the image input layer of the network to'none'.

Classes of the output layer, specified as a categorical vector, string array, cell array of character vectors, or'auto'. If you specify a string array or cell array of character vectorsstr, then the software sets the classes of the output layer tocategorical(str,str). IfClassesis'auto', then the function sets the classes tocategorical(1:N), whereN的数量是classes.

Data Types:char|categorical|string|cell

Output Arguments

collapse all

Imported pretrained Caffe network, returned as aSeriesNetworkobject orDAGNetworkobject. Caffe networks that take color images as input expect the images to be in BGR format. During import,importCaffeNetworkmodifies the network so that the imported MATLAB network takes RGB images as input.

More About

collapse all

Generate Code for Imported Network

You can useMATLAB Coder™or GPU Coder™ together with Deep Learning Toolbox to generate MEX, standalone CPU, CUDA®MEX, or standalone CUDA code for an imported network. For more information, seeCode Generation.

  • UseMATLAB Coderwith Deep Learning Toolbox to generate MEX or standalone CPU code that runs on desktop or embedded targets. You can deploy generated standalone code that uses the Intel®MKL-DNN library or the ARM®Compute library. Alternatively, you can generate generic C or C++ code that does not call third-party library functions. For more information, seeDeep Learning with MATLAB Coder(MATLAB Coder).

  • Use GPU Coder with Deep Learning Toolbox to generate CUDA MEX or standalone CUDA code that runs on desktop or embedded targets. You can deploy generated standalone CUDA code that uses the CUDA deep neural network library (cuDNN), the TensorRT™ high performance inference library, or the ARM Compute library for Mali GPU. For more information, seeDeep Learning with GPU Coder(GPU Coder).

importCaffeNetworkreturns the networknetas aDAGNetworkorSeriesNetworkobject. Both these objects support code generation. For more information onMATLAB Coderand GPU Coder support for Deep Learning Toolbox objects, seeSupported Classes(MATLAB Coder)andSupported Classes(GPU Coder), respectively.

You can generate code for any imported network whose layers support code generation. For lists of the layers that support code generation withMATLAB Coderand GPU Coder, seeSupported Layers(MATLAB Coder)andSupported Layers(GPU Coder), respectively. For more information on the code generation capabilities and limitations of each built-in MATLAB layer, see the Extended Capabilities section of the layer. For example, seeCode GenerationandGPU Code GenerationofimageInputLayer.

Use Imported Network on GPU

importCaffeNetworkdoes not execute on a GPU. However,importCaffeNetworkimports a pretrained neural network for deep learning as aDAGNetworkorSeriesNetworkobject, which you can use on a GPU.

  • You can make predictions with the imported network on either a CPU or GPU by usingclassify. Specify the hardware requirements using the name-value argumentExecutionEnvironment. For networks with multiple outputs, use thepredictfunction.

  • You can make predictions with the imported network on either a CPU or GPU by usingpredict. Specify the hardware requirements using the name-value argumentExecutionEnvironment. If the network has multiple outputs, specify the name-value argumentReturnCategoricalastrue.

  • You can train the imported network on either a CPU or GPU by usingtrainNetwork. To specify training options, including options for the execution environment, use thetrainingOptionsfunction. 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 a Parallel Computing Toolbox™ license and a supported GPU device. For information about supported devices, seeGPU Computing Requirements(Parallel Computing Toolbox).

Tips

Extended Capabilities

版本历史

Introduced in R2017a

expand all