How to chain Multiple Networks (backpropagate through networks sequentially)?

34 views
Skip to first unread message

nukeb...@gmail.com

unread,
Jul 6, 2016, 6:27:28 AM7/6/16
to Caffe Users

Background : I want to chain multiple networks. Suppose that I have 5 neural networks. One of them feeds into the rest 4. The purpose is to feedforward into the chosen subnetwork (and backpropagate) depending on the input example.

For example, if I have an input A which is mapped to the 1st subnetwork, then it is feedforwarded through the common network, the output of which is fed into the 1st subnetwork (note that I have 4 subnetworks in total and 1 shared network). At the end of the 1st subnetwork, I compute the loss w.r.t. the ground truth for input A. Then, I backpropagate the error, updating the parameters as I go back through the layers of the 1st subnetwork and subsequently the shared network.

Problem :

So far, I've tried to do this using two simple networks N and M. The output of N feeds into M. During backpropagation, I assign thediff of the first layer of M to the diff of the last layer of N. The last layer in N is identical to the first layer of M. After the above assignment, when I execute N.backward it does not seem to result in the correct gradients for the layers in N. I don't know how to get around this.


I have uploaded an ipython notebook which gives details about my attempt at solving the problem. Visit the following link to a shared folder in my dropbox to use this ipython notebook.
http://preview.tinyurl.com/gqal6qa

nukeb...@gmail.com

unread,
Jul 6, 2016, 7:44:09 AM7/6/16
to Caffe Users
Well. Seems like a simple problem. I have resolved the issue.

All that needs to be done is to set:

N.backward(output_layer=diff);
where
diff = M.blobs['first_layer'].diff;
Reply all
Reply to author
Forward
0 new messages