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 .prototxt file protofile and with network weights specified by the .caffemodel file datafile.

This function requires Deep Learning Toolbox™ Importer for Caffe Models support 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 more Name,Value pair arguments using any of the previous syntaxes.

Examples

collapse all

Download and install Deep Learning Toolbox Importer for Caffe Models support package.

To download the required support package, type importCaffeNetwork at the command line.

importCaffeNetwork

If Deep Learning Toolbox Importer for Caffe Models support 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 click Install.

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 .prototxt file containing the network architecture, specified as a character vector or a string scalar. protofile must 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 .prototxt file 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 .caffemodel file containing the network weights, specified as a character vector or a string scalar. datafile must 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, use importCaffeLayers.

Example: 'digits_iter_10000.caffemodel'

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: importCaffeNetwork(protofile,datafile,'AverageImage',I) imports a pretrained network using the average image I for 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 .prototxt file 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 .prototxt file, if present. Otherwise, the function sets the Normalization property 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 vectors str, then the software sets the classes of the output layer to categorical(str,str). If Classes is 'auto', then the function sets the classes to categorical(1:N), where N is the number of classes.

Data Types: char | categorical | string | cell

Output Arguments

collapse all

Imported pretrained Caffe network, returned as a SeriesNetwork object or DAGNetwork object. Caffe networks that take color images as input expect the images to be in BGR format. During import, importCaffeNetwork modifies the network so that the imported MATLAB network takes RGB images as input.

Tips

Compatibility Considerations

expand all

Not recommended starting in R2018b

Extended Capabilities

Introduced in R2017a