Main Content

importCaffeNetwork

Import pretrained convolutional neural network models from Caffe

Description

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].

example

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 Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is 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 enclose Name in quotes.

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.

More About

collapse all

Tips

Extended Capabilities

expand all

Version History

Introduced in R2017a

expand all