Sobes.tech
Middle

Milleks on mõeldud pooling kiht?

sobes.tech AI

Vastus AI-lt

Pooling layer in neural networks is used to reduce the dimensionality of input data, which helps to decrease computational load and reduce the number of model parameters. It also promotes the extraction of the most important features, increasing the model's robustness to shifts and distortions in the input data.

The most common types of pooling:

  • Max pooling — selects the maximum value from a region.
  • Average pooling — calculates the average value.

Example of max pooling with a window size of 2x2 and stride 2:

import torch
import torch.nn as nn

input_tensor = torch.tensor([[[[1, 2, 3, 4],
                               [5, 6, 7, 8],
                               [9, 10, 11, 12],
                               [13, 14, 15, 16]]]], dtype=torch.float32)

pool = nn.MaxPool2d(kernel_size=2, stride=2)
output = pool(input_tensor)
print(output)

The result will contain the maximums from each 2x2 block, reducing the size from 4x4 to 2x2.