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.


Import convolutional neural network layers from Caffe


layers = importCaffeLayers(protofile)
layers = importCaffeLayers(protofile,'InputSize',sz)



layers = importCaffeLayers(protofile) imports the layers of a network from Caffe [1] as a Layer array. The function returns the layers defined in the .prototxt given by the file name protofile.

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

layers = importCaffeLayers(protofile,'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.


collapse all

Download and install Neural Network Toolbox Importer for Caffe Models support package.

Download the required support package by typing importCaffeLayers at the command line.


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 file to import.

protofile = 'digitsnet.prototxt';

Import network layers.

layers = importCaffeLayers('digitsnet.prototxt')
layers = 

  1x7 Layer array with layers:

     1   'testdata'   Image Input             28x28x1 images
     2   'conv1'      Convolution             20 5x5x1 convolutions with stride [1  1] and padding [0  0]
     3   'relu1'      ReLU                    ReLU
     4   'pool1'      Max Pooling             2x2 max pooling with stride [2  2] and padding [0  0]
     5   'ip1'        Fully Connected         10 fully connected layer
     6   'loss'       Softmax                 softmax
     7   'output'     Classification Output   crossentropyex with 'class1', 'class2', and 8 other classes

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.

importCaffeLayers can import only the layers of 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.

Example: 'digitsnet.prototxt'

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

Output Arguments

collapse all

Network architecture, returned as a Layer array. Caffe networks that classify truecolor images expect a BGR image input. When imported into MATLAB, the image input layer expects an RGB image input


[1] Caffe.

[2] Caffe Model Zoo.

Introduced in R2017a

Was this topic helpful?