8
$\begingroup$
net = NetGraph[{3, 5, 8}, {1 -> 2 -> 3}, "Input" -> 2]

enter image description here

Take[net, {1, 2}]

enter image description here

But net[[1 ;; 2]] gives Missing["NotPresent", {1 ;; 2}].

I find net//Normal is:

enter image description here

But {a, b, c}[[1 ;; 2]] == Take[{a, b, c}, {1, 2}] returns True.

And There is a more complicated net:

net = NetGraph[{EmbeddingLayer[32, "Input" -> NetEncoder[{"Class", Range[0, 500]}]], 
          CatenateLayer[],64, Ramp, 43}, 
         {NetPort["EmbeddingLayerInput"] -> 1 -> 2, 
          NetPort["Input2"] -> 2, 2 -> 3 -> 4 -> 5}, 
         "Input2" -> 12]

enter image description here

I want to extract the sub-net like this:

NetGraph[{CatenateLayer[], 64, Ramp, 43}, 
         {NetPort["Input"] -> 1, 
         NetPort["Input2"] -> 1 -> 2 -> 3 -> 4}, 
         "Input2" -> 12, "Input" -> 32]

enter image description here

The way I can figure out is use this:

NetGraph[{CatenateLayer[], Take[net, {3, NetPort@"Output"}]}, 
         {NetPort["Input"] -> 1, NetPort["Input2"] -> 1 -> 2}, 
         "Input2" -> 12, "Input" -> 32]

enter image description here

So how to extract of sub-net of NetGraph correctly?

$\endgroup$

1 Answer 1

5
$\begingroup$

For now, part syntax [[]] is mostly synonymous with NetExtract. NetExtract does not support slice syntax. For what it is worth, we are going to make an actual NetTake function at some point that is nice and clearly documented, I don't like using Take to hide this 'surgery' functionality, which doesn't work exactly like ordinary Take.

The second thing should be possible easily, but seems not to be at the moment owing to a bug with CatenateLayer, which cannot be constructed purely from graph inputs. Here are two ways you would do it once the bug is fixed:

Take[net, {{2, NetPort[1, "Output"]}, 5}]
VertexDelete[net, 1]
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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