0
$\begingroup$

I have a net with a nested sub-net like

net1 = NetGraph[
  {
   "Layer" -> ElementwiseLayer[2 # &]
   },
  {
   "Layer" -> NetPort["A"],
   "Layer" -> NetPort["B"]
   }]
NET = NetGraph[
  {
   "net1" ->  net1
   },
  {
   }]

Out[1]=

I'd like to replace net1 with a net with less outputs. However, if I try to do

net2 = NetGraph[
  {
   "Layer" -> ElementwiseLayer[2 # &]
   },
  {
   "Layer" -> NetPort["A"]
   }]
NetReplacePart[NET, {"net1" -> net2}]

I get

NetGraph::invnetrep: Replacement of net failed: replacement net was missing output port named "B".

This is in agreement with NetReplacePart's documentation that states clearly:

"When a specific layer is replaced, the shapes of the inputs and outputs of the original layer must match those of the layer it is replaced with."

How can replace net1 with net2, removing output B?

$\endgroup$

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.