How to slice 4d tensor in tensorflow.js?

47 views Asked by At

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].

2

There are 2 answers

3
TP95 On BEST ANSWER

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

1
Daniel Guedes On

[1,28,28,1] the last 1 referring to 1 of the 32 feature maps.