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.
Here are the specifics steps that need to be implemented:
- Perform one forward pass on model A with a batch size of 64, and 13155 rows.
- 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).
- Perform one forward pass on model B by feeding it with #2 above.
- 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.