Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

cntk

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.

like image 1000
Arko Chakraborti Avatar asked Feb 28 '18 21:02

Arko Chakraborti


1 Answers

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.

like image 89
Arko Chakraborti Avatar answered Oct 04 '22 05:10

Arko Chakraborti