Safemotion Lib
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
fastreid.layers.pooling.GeneralizedMeanPooling Class Reference
Inheritance diagram for fastreid.layers.pooling.GeneralizedMeanPooling:
fastreid.layers.pooling.GeneralizedMeanPoolingP

Public Member Functions

 __init__ (self, norm=3, output_size=1, eps=1e-6)
 
 forward (self, x)
 
 __repr__ (self)
 

Public Attributes

 p
 
 output_size
 
 eps
 

Detailed Description

Applies a 2D power-average adaptive pooling over an input signal composed of several input planes.
The function computed is: :math:`f(X) = pow(sum(pow(X, p)), 1/p)`
    - At p = infinity, one gets Max Pooling
    - At p = 1, one gets Average Pooling
The output is of size H x W, for any input size.
The number of output features is equal to the number of input planes.
Args:
    output_size: the target output size of the image of the form H x W.
                 Can be a tuple (H, W) or a single H for a square image H x H
                 H and W can be either a ``int``, or ``None`` which means the size will
                 be the same as that of the input.

Definition at line 25 of file pooling.py.

Constructor & Destructor Documentation

◆ __init__()

fastreid.layers.pooling.GeneralizedMeanPooling.__init__ ( self,
norm = 3,
output_size = 1,
eps = 1e-6 )

Reimplemented in fastreid.layers.pooling.GeneralizedMeanPoolingP.

Definition at line 39 of file pooling.py.

39 def __init__(self, norm=3, output_size=1, eps=1e-6):
40 super(GeneralizedMeanPooling, self).__init__()
41 assert norm > 0
42 self.p = float(norm)
43 self.output_size = output_size
44 self.eps = eps
45

Member Function Documentation

◆ __repr__()

fastreid.layers.pooling.GeneralizedMeanPooling.__repr__ ( self)

Definition at line 50 of file pooling.py.

50 def __repr__(self):
51 return self.__class__.__name__ + '(' \
52 + str(self.p) + ', ' \
53 + 'output_size=' + str(self.output_size) + ')'
54
55

◆ forward()

fastreid.layers.pooling.GeneralizedMeanPooling.forward ( self,
x )

Definition at line 46 of file pooling.py.

46 def forward(self, x):
47 x = x.clamp(min=self.eps).pow(self.p)
48 return torch.nn.functional.adaptive_avg_pool2d(x, self.output_size).pow(1. / self.p)
49

Member Data Documentation

◆ eps

fastreid.layers.pooling.GeneralizedMeanPooling.eps

Definition at line 44 of file pooling.py.

◆ output_size

fastreid.layers.pooling.GeneralizedMeanPooling.output_size

Definition at line 43 of file pooling.py.

◆ p

fastreid.layers.pooling.GeneralizedMeanPooling.p

Definition at line 42 of file pooling.py.


The documentation for this class was generated from the following file: