Why use Flatten layer?

After the Convolution convolutional layer, it is impossible to directly connect the Dense fully connected layer. You need to flatten the data of the Convolution layer (Flatten), and then you can directly add the Dense layer .

That is, the data of (height, width, channel) is compressed into a one-dimensional array with a length of height × width × channel, and then connected to the FC layer. After that, it is no different from an ordinary neural network.

 

As you can see from the figure, with the deepening of the network, our images (strictly speaking, those in the middle cannot be called images, but for convenience, let’s say that) are getting smaller and smaller, but the channels are getting bigger and bigger. . The representation in the figure is that the area of ​​the rectangular parallelepiped facing us is getting smaller and smaller, but the length is getting longer and longer.

The function of the Flatten layer : The Flatten layer turns an input size n * c * h * w into a simple vector whose size is n * (c h w). You can use reshape instead of ~, which is equivalent to the first dimension unchanged and the subsequent automatic calculation.

Guess you like

Origin blog.csdn.net/weixin_43135178/article/details/114602960