Main Content

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。prototxtfileprotofile

This function requiresDeep Learning Toolbox™ Importer for Caffe Modelssupport 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。prototxtfile does not specify the size of the input data, then you must specify the input size.

Examples

collapse all

Download and installDeep Learning Toolbox Importer for Caffe Modelssupport package.

Download the required support package by typingimportCaffeLayersat the command line.

importCaffeLayers

IfDeep Learning Toolbox Importer for Caffe Modelssupport 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 clickInstall

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

输入参数

collapse all

文件名称of the。prototxtfile containing the network architecture, specified as a character vector or a string scalar.protofilemust 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。prototxtfile does not specify the size of the input data, you must specify the size using theszinput 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 aLayerarray or aLayerGraphobject. Caffe networks that take color images as input expect the images to be in BGR format. During import,importCaffeLayersmodifies the network so that the imported MATLAB network takes RGB images as input.

More About

collapse all

Generate Code for Imported Network Architecture

You can useMATLAB Coder™or GPU Coder™ together with Deep Learning Toolbox to generate MEX, standalone CPU, CUDA®MEX, or standalone CUDA code for an imported network. For more information, seeDeep Learning Code Generation

  • UseMATLAB Coderwith Deep Learning Toolbox to generate MEX or standalone CPU code that runs on desktop or embedded targets. You can deploy generated standalone code that uses the Intel®MKL-DNN library or the ARM®Compute library. Alternatively, you can generate generic C or C++ code that does not call third-party library functions. For more information, seeDeep Learning with MATLAB Coder(MATLAB Coder)

  • Use GPU Coder with Deep Learning Toolbox to generate CUDA MEX or standalone CUDA code that runs on desktop or embedded targets. You can deploy generated standalone CUDA code that uses the CUDA deep neural network library (cuDNN), the TensorRT™ high performance inference library, or the ARM Compute library for Mali GPU. For more information, seeDeep Learning with GPU Coder(GPU Coder)

importCaffeLayersreturns the network architecturelayersas aLayerorLayerGraphobject. For code generation, you must first convert the importedLayerorLayerGraphobject to a network. Convert aLayerorLayerGraphobject to aDAGNetworkorSeriesNetworkobject by using汇编工作。Convert aLayerorLayerGraphobject to adlnetworkobject by usingdlnetwork。For more information onMATLAB Coderand GPU Coder support for Deep Learning Toolbox objects, seeSupported Classes(MATLAB Coder)andSupported Classes(GPU Coder), respectively.

You can generate code for any imported network whose layers support code generation. For lists of the layers that support code generation withMATLAB Coderand GPU Coder, seeSupported Layers(MATLAB Coder)andSupported Layers(GPU Coder), respectively. For more information on the code generation capabilities and limitations of each built-in MATLAB layer, see the Extended Capabilities section of the layer. For example, seeCode GenerationandGPU Code GenerationofimageInputLayer

Use Imported Network Layers on GPU

importCaffeLayersdoes not execute on a GPU. However,importCaffeLayersimports the layers of a pretrained neural network for deep learning as aLayerarray orLayerGraphobject, which you can use on a GPU.

  • Convert the imported layers to aDAGNetworkobject by using汇编工作。On theDAGNetworkobject, you can then predict class labels on either a CPU or GPU by usingclassify。使用名称值参数指定硬件要求ExecutionEnvironment。For networks with multiple outputs, use thepredictfunction and specify the name-value argumentReturnCategoricalastrue

  • Convert the imported layers to adlnetworkobject by usingdlnetwork。On thedlnetworkobject, you can then predict class labels on either a CPU or GPU by usingpredict。The functionpredictexecutes on the GPU if either the input data or network parameters are stored on the GPU.

    • If you useMinibatchqueueto process and manage the mini-batches of input data, theMinibatchqueueobject converts the output to a GPU array by default if a GPU is available.

    • Usedlupdateto convert the learnable parameters of adlnetworkobject to GPU arrays.

      net = dlupdate(@gpuArray,net)

  • You can train the imported layers on either a CPU or GPU by usingtrainNetwork。To specify training options, including options for the execution environment, use thetrainingOptionsfunction. Specify the hardware requirements using the name-value argumentExecutionEnvironment。For more information on how to accelerate training, seeScale Up Deep Learning in Parallel, on GPUs, and in the Cloud

Using a GPU requires Parallel Computing Toolbox™ and a supported GPU device. For information on supported devices, seeGPU Support by Release(Parallel Computing Toolbox)

Tips

Version History

Introduced in R2017a