glasses.nn.pool package

Submodules

glasses.nn.pool.SpatialPyramidPool module

class glasses.nn.pool.SpatialPyramidPool.SpatialPyramidPool(num_pools: List[int] = [1, 4, 16], pool: torch.nn.modules.module.Module = <class 'torch.nn.modules.pooling.AdaptiveMaxPool2d'>)[source]

Bases: torch.nn.modules.module.Module

Implementation of Spatial Pyramid Pooling in Deep Convolutional Networks for Visual Recognition

https://github.com/FrancescoSaverioZuppichini/glasses/blob/develop/docs/_static/images/SPP.png?raw=true

It generate fixed length representation regardless of image dimensions.

Examples

>>> x = torch.randn((4, 256, 14, 14))
>>> SpatialPyramidPool()(x).shape
>>> # torch.Size([4, 256, 21])
Parameters
  • num_pools (List[int], optional) – The number of pooling output size. Defaults to [1, 4, 16].

  • pool (nn.Module, optional) – The pooling layer. Defaults to nn.AdaptiveMaxPool2d.

Initializes internal Module state, shared by both nn.Module and ScriptModule.

forward(x: torch.Tensor) torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool

Module contents

class glasses.nn.pool.SpatialPyramidPool(num_pools: List[int] = [1, 4, 16], pool: torch.nn.modules.module.Module = <class 'torch.nn.modules.pooling.AdaptiveMaxPool2d'>)[source]

Bases: torch.nn.modules.module.Module

Implementation of Spatial Pyramid Pooling in Deep Convolutional Networks for Visual Recognition

https://github.com/FrancescoSaverioZuppichini/glasses/blob/develop/docs/_static/images/SPP.png?raw=true

It generate fixed length representation regardless of image dimensions.

Examples

>>> x = torch.randn((4, 256, 14, 14))
>>> SpatialPyramidPool()(x).shape
>>> # torch.Size([4, 256, 21])
Parameters
  • num_pools (List[int], optional) – The number of pooling output size. Defaults to [1, 4, 16].

  • pool (nn.Module, optional) – The pooling layer. Defaults to nn.AdaptiveMaxPool2d.

Initializes internal Module state, shared by both nn.Module and ScriptModule.

forward(x: torch.Tensor) torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool