Using Keras, I am trying to reproduce a few basic results from a published paper.

In this task, there are two neural networks - A & B, that are connected in a cascade formation, i.e. the output of model A feeds the input of model B. Please see the figure below.

graphical description of cascaded neural network

Here are the specifics steps that need to be implemented:

  1. Perform one forward pass on model A with a batch size of 64, and 13155 rows.
  2. Clone the output to create a batch of 128 rows i.e. use each training sample twice. (There are auxiliary inputs which distinguish the duplicate rows, but I have omitted that info for the sake of brevity).
  3. Perform one forward pass on model B by feeding it with #2 above.
  4. Now backward the two networks, calculate a loss for each one, sum the loss & send it to the optimizer with the gradients of both networks.

As I am quite new to the world of neural networks & Keras, I'd really appreciate any help from the community to implement the above steps in Keras. In particular, I am quite confused about implementing step 2 (please see the attached figure).

As a starting point, I had found this answer to be somewhat aligned to my question, but the details of customization to my specific problem is fuzzy, for example how to implement the forward & backward logic separately etc.

  • $\begingroup$ I am also interested in a solution to this question. Can someone from the community please point in a suitable direction? $\endgroup$ Dec 10 '20 at 12:21
  • $\begingroup$ Did you try to use Keras functional API? See here keras.io/guides/functional_api/… $\endgroup$ Dec 11 '20 at 11:24
  • $\begingroup$ @VladislavGladkikh : Yes I did. But I am not sure how to clone prediction made by first network and by doing that double the batch size for training the second network? $\endgroup$
    – KKCS
    Dec 14 '20 at 7:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.