Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

importCaffeNetwork

Import pretrained convolutional neural network models from Caffe

Syntax

net = importCaffeNetwork(protofile,datafile)
net = importCaffeNetwork(protofile,datafile,'InputSize',sz)
net = importCaffeNetwork(___,Name,Value)

Description

example

net = importCaffeNetwork(protofile,datafile) imports a pretrained network from Caffe [1] as a SeriesNetwork object. 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 Neural Network 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(protofile,datafile,'InputSize',sz) returns a pretrained network and specifies the size of the input data. If the .prototxt file does not specify the size of the input data, you must specify the input size.

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 Neural Network Toolbox Importer for Caffe Models support package.

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

importCaffeNetwork

If Neural Network 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]

Input Arguments

collapse all

File name of the .prototxt file containing the network architecture, specified as a character vector. 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 sz input argument.

importCaffeNetwork can import only a series network with the following Caffe layer types:

  • Input

  • Data

  • Convolution

  • ReLU

  • Local Response Normalization (LRN)

  • Pooling

  • Inner Product

  • Dropout

  • Softmax With Loss

  • Euclidean Loss

If the network contains any other type of layer, then the software returns an error.

The function imports only the layers that protofile specifies with the include-phase TEST. The function ignores any layers that protofile specifies with the include-phase TRAIN.

The software cannot import a solver definition.

Example: 'digitsnet.prototxt'

Data Types: char

File name of the .caffemodel file containing the network weights, specified as a character vector. 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, see importCaffeLayers.

Example: 'digits_iter_10000.caffemodel'

Data Types: char

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.

Example: [28 28 1]

Data Types: double

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 single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: importCaffeNetwork(protofile,datafile,'AverageImage',I,'ClassNames',{'A','B','C'}) imports a pretrained network using the average image I for zero-center normalization and specifies the class names to be 'A', 'B', and 'C'.

collapse all

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

Data Types: single

Class names associated with the output layer of the network, specified by a cell array of character vectors.

Example: {'0','1','2','3','4','5','6','7','8','9'}

Data Types: cell

Output Arguments

collapse all

Imported pretrained Caffe network, returned as a SeriesNetwork object. Caffe networks that classify truecolor images expect a BGR image input. When imported into MATLAB, the image input layer expects an RGB image input.

References

[1] Caffe. http://caffe.berkeleyvision.org/

[2] Caffe Model Zoo. http://caffe.berkeleyvision.org/model_zoo.html

Introduced in R2017a


Was this topic helpful?