By the looks of it, the output of your pooling layer is 1 x 20 x 20 while the output of your network is 20 x 20, so you'll first have to decide how to match these dimensions. You can use ReshapeLayer
to match the dimensions of one to the other or you can use AppendLayer
instead.
Now as for getting the output of node 30 directly towards the output: this isn't possible if you use NetChain
as far as I know. NetChain
only constructs linear nets. Instead, you should use NetGraph
. As a simple example of how to catenate information from deeper inside of the net directly to the output, consider the simple example below where the output of the first linear layer is appended directly to the output of the last linear layer:
NetGraph[
{
LinearLayer[10],
Ramp,
LinearLayer[5],
CatenateLayer[]
},
{
NetPort["Input"] -> 1 -> 2 -> 3,
{1, 3} -> 4 -> NetPort["Output"]
}
]
I noticed that your code is based on the idea of gradually adding layers to the network rather than constructing it in one go and I think you may want to reconsider that strategy here. It's probably easier to rewrite convolutionModule
to a function that simply returns a discrete block (e.g., a NetChain
) rather than having it append the results to an existing net. Several of these blocks can then be put together in one single NetGraph
.