SubtractMean

Description

Info

Parent class: Module

Derived classes: -

This module subtracts the filter average from the tensor elements. The module only works with two-dimensional maps.

Initializing

def __init__(self, size=5, includePad=True, name=None):

Parameters

Parameter Allowed types Description Default
size int Filter size 5
includePad bool Inclusion flag for edge filling values when calculating the average value True
name str Layer name None

Explanations

size - size of the filter should be odd; the filter is always square;


includePad - pad attribute is set to non-zero by default and new elements are added to the original tensor along the edges, it is possible to take into account the module’s runtime when the includePad flag is set.

Examples

Necessary imports.

import numpy as np
from PuzzleLib.Backend import gpuarray
from PuzzleLib.Modules import SubtractMean

Info

gpuarray is required to properly place the tensor in the GPU

``python batchsize, maps, h, w = 1, 1, 3, 3 data = gpuarray.to_gpu(np.arange(batchsize * maps * h * w).reshape((batchsize, maps, h, w)).astype(np.float32)) print(data)

<div class="output">
[[[[0. 1. 2.] [3. 4. 5.] [6. 7. 8.]]]]
</div>
Инициализируем модуль без учёта паддинга при расчётах:

```python
submean = SubtractMean(size=3, includePad=False)
print(submean(data))
[[[[-2.  -1.5 -1. ]
   [-0.5  0.   0.5]
   [ 1.   1.5  2. ]]]]

As well as while taking padding into account:

submean = SubtractNorm(size=3, includePad=True)
print(submean(data))
[[[[-0.8888889  -0.6666666   0.6666666 ]
   [ 0.66666675  0.          2.        ]
   [ 3.7777777   3.3333333   5.333333  ]]]]