How to train a network with multiple output layers in CNTK?
Asked Answered
W

1

5

Objective: To train a neural network as shown in the image below, for an image classification task. (Input dimension can be seen in the image.)

I have been able to create the network, but am facing problems below:

  1. Specifying the loss and classification error functions.
  2. Specifying the output variable to be fed to train_minibatch dictionary.

I am using a generator to feed the data to the network, and thus using train_minibatch to feed the data. The output of this generator are the input images, and a list of 4 items containing the 1 hot encoded labels.

Wangle answered 28/2, 2018 at 21:16 Comment(0)
W
6

I was able to figure it out myself. For such a scenario, we have to define separate output variables for each of the branches and then feed the data to them separately.

Consider that y is a list of 4 elements that are supposed to be the output of the neural network. We would define our data dictionary as shown

trainer.train_minibatch( { input_placeholder: x, output_placeholder0: y[0], output_placeholder1: y[1], output_placeholder2: y[2], output_placeholder3: y[3] } )

Other variables like loss, classification error can be a simple sum over the individual losses (This will depend on the specific use case)

For more details have a look at this notebook where I have created the above network, fed the data and trained the model.

Wangle answered 2/3, 2018 at 19:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.