KMaxPool¶
Description¶
K-Max Pooling is a pooling operation, which is a generalization of max-pooling by the time parameter used in the Max-TDNN model, which differs from the local max-pooling used in convolutional networks for object recognition (LeCun et al., 1998).
K-Max Pooling selects a subsequence out of the k maximum values of the sequence. This module implements a special case when the relative positions of the selected elements are not saved: the sorted values are returned to the output.
Initializing¶
def __init__(self, topk, axis, name=None):
Parameters
Parameters | Allowed types | Description | Default |
---|---|---|---|
topk | int | Number of maximum values | - |
axis | int | Axis along which the operation is calculated | - |
name | str | Layer name | None |
Explanations
-
Examples¶
Necessary imports.
import numpy as np
from PuzzleLib.Backend import gpuarray
from PuzzleLib.Modules import KMaxPool
Info
gpuarray
is required to properly place the tensor in the GPU
np.random.seed(123)
data = gpuarray.to_gpu(np.random.randint(0, 9, (1, 1, 10)).astype(np.float32))
print(data)
[[[2. 2. 6. 1. 3. 6. 1. 0. 1. 0.]]]
topk, axis = 2, 2
kmaxpool = KMaxPool(topk=3, axis=2)
print(kmaxpool(data))
[[[3. 6. 6.]]]