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

Public Member Functions

def __init__ (self, output_size, input_size, which_linear, eps=1e-5, momentum=0.1, cross_replica=False, mybn=False, norm_style="bn")
 Constructor.
 
def forward (self, x, y)
 forward
 
def extra_repr (self)
 extra_repr
 

Public Attributes

 input_size
 output size
 
 gain
 Prepare gain and bias layers.
 
 bias
 bias
 
 eps
 epsilon to avoid dividing by 0
 
 momentum
 Momentum.
 
 cross_replica
 Use cross-replica batchnorm?
 
 mybn
 Use my batchnorm?
 
 norm_style
 Norm style?
 
 bn
 bn
 

Detailed Description

Class-conditional bn
output size is the number of channels, input size is for the linear layers
Andy's Note: this class feels messy but I'm not really sure how to clean it up  # noqa
Suggestions welcome! (By which I mean, refactor this and make a merge request
if you want to make this more readable/usable).

Definition at line 516 of file ieagan.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  output_size,
  input_size,
  which_linear,
  eps = 1e-5,
  momentum = 0.1,
  cross_replica = False,
  mybn = False,
  norm_style = "bn" 
)

Constructor.

Definition at line 526 of file ieagan.py.

536 ):
537 super(ccbn, self).__init__()
538
539 self.output_size, self.input_size = output_size, input_size
540
541 self.gain = which_linear(input_size, output_size)
542
543 self.bias = which_linear(input_size, output_size)
544
545 self.eps = eps
546
547 self.momentum = momentum
548
549 self.cross_replica = cross_replica
550
551 self.mybn = mybn
552
553 self.norm_style = norm_style
554
555 if self.mybn:
556
557 self.bn = myBN(output_size, self.eps, self.momentum)
558 elif self.norm_style in ["bn", "in"]:
559 self.register_buffer("stored_mean", torch.zeros(output_size))
560 self.register_buffer("stored_var", torch.ones(output_size))
561

Member Function Documentation

◆ extra_repr()

def extra_repr (   self)

extra_repr

Definition at line 601 of file ieagan.py.

601 def extra_repr(self):
602 s = "out: {output_size}, in: {input_size},"
603 s += " cross_replica={cross_replica}"
604 return s.format(**self.__dict__)
605
606

◆ forward()

def forward (   self,
  x,
  y 
)

forward

Definition at line 563 of file ieagan.py.

563 def forward(self, x, y):
564 # Calculate class-conditional gains and biases
565 gain = (1 + self.gain(y)).view(y.size(0), -1, 1, 1)
566 bias = self.bias(y).view(y.size(0), -1, 1, 1)
567 # If using my batchnorm
568 if self.mybn:
569 return self.bn(x, gain=gain, bias=bias)
570 # else:
571 else:
572 if self.norm_style == "bn":
573 out = F.batch_norm(
574 x,
575 self.stored_mean,
576 self.stored_var,
577 None,
578 None,
579 self.training,
580 0.1,
581 self.eps,
582 )
583 elif self.norm_style == "in":
584 out = F.instance_norm(
585 x,
586 self.stored_mean,
587 self.stored_var,
588 None,
589 None,
590 self.training,
591 0.1,
592 self.eps,
593 )
594 elif self.norm_style == "gn":
595 out = groupnorm(x, self.normstyle)
596 elif self.norm_style == "nonorm":
597 out = x
598 return out * gain + bias
599

Member Data Documentation

◆ bias

bias

bias

Definition at line 543 of file ieagan.py.

◆ bn

bn

bn

Definition at line 557 of file ieagan.py.

◆ cross_replica

cross_replica

Use cross-replica batchnorm?

Definition at line 549 of file ieagan.py.

◆ eps

eps

epsilon to avoid dividing by 0

Definition at line 545 of file ieagan.py.

◆ gain

gain

Prepare gain and bias layers.

Definition at line 541 of file ieagan.py.

◆ input_size

input_size

output size

Definition at line 539 of file ieagan.py.

◆ momentum

momentum

Momentum.

Definition at line 547 of file ieagan.py.

◆ mybn

mybn

Use my batchnorm?

Definition at line 551 of file ieagan.py.

◆ norm_style

norm_style

Norm style?

Definition at line 553 of file ieagan.py.


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