Belle II Software development
myBN Class Reference
Inheritance diagram for myBN:

Public Member Functions

def __init__ (self, num_channels, eps=1e-5, momentum=0.1)
 Constructor.
 
def reset_stats (self)
 reset standing stats
 
def forward (self, x, gain, bias)
 forward
 

Public Attributes

 momentum
 momentum for updating running stats
 
 eps
 epsilon to avoid dividing by 0
 
 accumulate_standing
 Accumulate running means and vars.
 

Detailed Description

My batchnorm, supports standing stats

Definition at line 400 of file ieagan.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  num_channels,
  eps = 1e-5,
  momentum = 0.1 
)

Constructor.

Definition at line 406 of file ieagan.py.

406 def __init__(self, num_channels, eps=1e-5, momentum=0.1):
407 super(myBN, self).__init__()
408
409 self.momentum = momentum
410
411 self.eps = eps
412 # Momentum
413 self.momentum = momentum
414 # Register buffers
415 self.register_buffer("stored_mean", torch.zeros(num_channels))
416 self.register_buffer("stored_var", torch.ones(num_channels))
417 self.register_buffer("accumulation_counter", torch.zeros(1))
418
419 self.accumulate_standing = False
420

Member Function Documentation

◆ forward()

def forward (   self,
  x,
  gain,
  bias 
)

forward

Definition at line 429 of file ieagan.py.

429 def forward(self, x, gain, bias):
430 # pylint: disable=no-member
431 if self.training:
432 out, mean, var = manual_bn(
433 x, gain, bias, return_mean_var=True, eps=self.eps
434 )
435 # If accumulating standing stats, increment them
436 if self.accumulate_standing:
437 self.stored_mean[:] = self.stored_mean + mean.data
438 self.stored_var[:] = self.stored_var + var.data
439 self.accumulation_counter += 1.0
440 # If not accumulating standing stats, take running averages
441 else:
442 self.stored_mean[:] = (
443 self.stored_mean * (1 - self.momentum) + mean * self.momentum
444 )
445 self.stored_var[:] = (
446 self.stored_var * (1 - self.momentum) + var * self.momentum
447 )
448 return out
449 # If not in training mode, use the stored statistics
450 else:
451 mean = self.stored_mean.view(1, -1, 1, 1)
452 var = self.stored_var.view(1, -1, 1, 1)
453 # If using standing stats, divide them by the accumulation counter
454 if self.accumulate_standing:
455 mean = mean / self.accumulation_counter
456 var = var / self.accumulation_counter
457 return fused_bn(x, mean, var, gain, bias, self.eps)
458
459

◆ reset_stats()

def reset_stats (   self)

reset standing stats

Definition at line 422 of file ieagan.py.

422 def reset_stats(self):
423 # pylint: disable=no-member
424 self.stored_mean[:] = 0
425 self.stored_var[:] = 0
426 self.accumulation_counter[:] = 0
427

Member Data Documentation

◆ accumulate_standing

accumulate_standing

Accumulate running means and vars.

Definition at line 419 of file ieagan.py.

◆ eps

eps

epsilon to avoid dividing by 0

Definition at line 411 of file ieagan.py.

◆ momentum

momentum

momentum for updating running stats

Definition at line 409 of file ieagan.py.


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