简体   繁体   中英

Multiple-input network training using Matlab's Deep Learning Toolbox

I want to train a convolutional neural network in Matlab with 5 input images using the trainNetwork function in their Deep Learning Toolbox. Currently, I have a combinedDatastore object ( ds ) for my training dataset with 5 inputs (images). I got the following error when using trainNetwork(ds, lgraph, options) :

Error using trainNetwork (line 165)
Invalid network.

Caused by:
    Network: Too many input layers. The network must have one input layer.
    Detected input layers:
        layer 'imageinput3'
        layer 'imageinput1'
        layer 'imageinput2'
        layer 'imageinput5'
        and 1 other layers.

How do I go about this? I am using Matlab 2019a. Thank you for your help!

A neural network has to have 1 input layer. Referring to MATLAB's documentation , an input layer is specified by the input image size, not the images you want the network to train on.

Check out this sample code on how to create your lgraph.

Create an array of layers. Suppose your images' size is 28x28x3.

layers = [
    imageInputLayer([28 28 3],'Name','input')  
    convolution2dLayer(3,16,'Padding','same','Name','conv_1')
    batchNormalizationLayer('Name','BN_1')
    reluLayer('Name','relu_1')];

Create a layer graph from the layer array. layerGraph connects all the layers in layers sequentially.

lgraph = layerGraph(layers);

Now, you can pass your training images to trainNetwork as follows:

net = trainNetwork(ds,lgraph,options);

Note: Please make sure your ds looks something like this, where each image has its own ground truth values. ds

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM