quora上的一个回答很简明
Suppose you’re using a Convolutional Neural Network whose initial layers are Convolution and Pooling layers. They layers have multidimensional tensors as their outputs. If you wanted to use a Dense(a fully connected layer) after your convolution layers, you would need to ‘unstack’ all this multidimensional tensor into a very long 1D tensor. You can achieve this using Flatten.
For instance if the output of the previous layer is of shape
(15, 3, 3, 4)
flatten unstacks all the tensor values into a 1-D tensor of shape
(15x3x3x4,)
so that it can be used as input for a Dense layer.
In short whenever you need to convert a multidimensional tensor into a single 1-D tensor, use can use Flatten.
网友评论