2
$\begingroup$

I have two NetGraphs, each with 3 different input ports ("Input","Random1","Random2"), the first with 2 outputs ("Output" and "Loss") and the second with one output "Final_Out". All I want to do is "chain" these networks together at the "Output" port such that the "Output" of the first becomes the "Input" of the second. Everything else should be left untouched - i.e. Loss stays an output port and so does Final_Out.

It doesn't matter to me whether the Random1 and Random2 ports for each get merged or stay separate. I've tried a lot and for the life of me cannot figure out how to accomplish this - especially considering I don't have access to the definitions of these neural networks, just the imported NetGraphs.

Is there any way to accomplish this?

$\endgroup$
2
$\begingroup$
net1 = NetGraph[
  {
   CatenateLayer[],
   LinearLayer[1],
   LinearLayer[1]
   },
  {
   {NetPort["Input"], NetPort["Random1"], NetPort["Random2"]} -> 
    1 -> 2 -> NetPort["Output"],
   2 -> 3 -> NetPort["Loss"]
   }
  ]

enter image description here

net2 = NetGraph[
  {
   CatenateLayer[],
   LinearLayer[1]
   },
  {
   {NetPort["Input"], NetPort["Random1"], NetPort["Random2"]} -> 
    1 -> 2 -> NetPort["Final_Out"]
   }
  ]

enter image description here

net = NetGraph[
  {
   net1,
   net2
   },
  {
   NetPort[1, "Output"] -> NetPort[2, "Input"]
   }
  ]

enter image description here

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.