importCaffeLayers

Import convolutional neural network layers from Caffe

Description

example

layers = importCaffeLayers(protofile) imports the layers of a Caffe [1] network. The function returns the layers defined in the .prototxt file protofile.

This function requires Deep Learning Toolbox™ Importer for Caffe Models support package. If this support package is not installed, then the function provides a download link.

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

layers = importCaffeLayers(protofile,'InputSize',sz) specifies the size of the input data. If the .prototxt file does not specify the size of the input data, then you must specify the input size.

Examples

collapse all

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

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

importCaffeLayers

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 the example file 'digitsnet.prototxt' to import.

protofile = 'digitsnet.prototxt';

Import the network layers.

layers = importCaffeLayers(protofile)
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 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 sz input argument.

Example: 'digitsnet.prototxt'

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]

Output Arguments

collapse all

Network architecture, returned as a Layer array or a LayerGraph object. Caffe networks that take color images as input expect the images to be in BGR format. During import, importCaffeLayers modifies the network so that the imported MATLAB network takes RGB images as input.

Tips

Introduced in R2017a