tensorflow.js

How to slice 4d tensor in tensorflow.js?


I have a tensor of shape [1,28,28,32] as output of a conv2d layer. Now I want to be able to access feature maps separately. The result should be of shape [1,28,28,1] or [28,28].


Solution

  • Use: tf.slice([0,0,0,ftr_map],[1,28,28,1])

    ftr_map controls which of the 32 feature maps you want to use.

    Here is the documentation for using tensor slice: LINK