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

Public Member Functions

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

Public Attributes

 output_size
 output size
 
 input_size = output_size, input_size
 output size
 
 gain = which_linear(input_size, output_size)
 Prepare gain and bias layers.
 
 bias = which_linear(input_size, output_size)
 bias
 
 eps = eps
 epsilon to avoid dividing by 0
 
 momentum = momentum
 Momentum.
 
 cross_replica = cross_replica
 Use cross-replica batchnorm?
 
 mybn = mybn
 Use my batchnorm?
 
str norm_style = norm_style
 Norm style?
 
 bn = myBN(output_size, self.eps, self.momentum)
 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 542 of file ieagan.py.

Constructor & Destructor Documentation

◆ __init__()

__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 552 of file ieagan.py.

562 ):
563 super(ccbn, self).__init__()
564
565 self.output_size, self.input_size = output_size, input_size
566
567 self.gain = which_linear(input_size, output_size)
568
569 self.bias = which_linear(input_size, output_size)
570
571 self.eps = eps
572
573 self.momentum = momentum
574
575 self.cross_replica = cross_replica
576
577 self.mybn = mybn
578
579 self.norm_style = norm_style
580
581 if self.mybn:
582
583 self.bn = myBN(output_size, self.eps, self.momentum)
584 elif self.norm_style in ["bn", "in"]:
585 self.register_buffer("stored_mean", torch.zeros(output_size))
586 self.register_buffer("stored_var", torch.ones(output_size))
587

Member Function Documentation

◆ extra_repr()

extra_repr ( self)

extra_repr

Definition at line 627 of file ieagan.py.

627 def extra_repr(self):
628 s = "out: {output_size}, in: {input_size},"
629 s += " cross_replica={cross_replica}"
630 # \cond false positive doxygen warning
631 return s.format(**self.__dict__)
632 # \endcond
633
634

◆ forward()

forward ( self,
x,
y )

forward

Definition at line 589 of file ieagan.py.

589 def forward(self, x, y):
590 # Calculate class-conditional gains and biases
591 gain = (1 + self.gain(y)).view(y.size(0), -1, 1, 1)
592 bias = self.bias(y).view(y.size(0), -1, 1, 1)
593 # If using my batchnorm
594 if self.mybn:
595 return self.bn(x, gain=gain, bias=bias)
596 # else:
597 else:
598 if self.norm_style == "bn":
599 out = F.batch_norm(
600 x,
601 self.stored_mean,
602 self.stored_var,
603 None,
604 None,
605 self.training,
606 0.1,
607 self.eps,
608 )
609 elif self.norm_style == "in":
610 out = F.instance_norm(
611 x,
612 self.stored_mean,
613 self.stored_var,
614 None,
615 None,
616 self.training,
617 0.1,
618 self.eps,
619 )
620 elif self.norm_style == "gn":
621 out = groupnorm(x, self.normstyle)
622 elif self.norm_style == "nonorm":
623 out = x
624 return out * gain + bias
625

Member Data Documentation

◆ bias

bias = which_linear(input_size, output_size)

bias

Definition at line 569 of file ieagan.py.

◆ bn

bn = myBN(output_size, self.eps, self.momentum)

bn

Definition at line 583 of file ieagan.py.

◆ cross_replica

cross_replica = cross_replica

Use cross-replica batchnorm?

Definition at line 575 of file ieagan.py.

◆ eps

eps = eps

epsilon to avoid dividing by 0

Definition at line 571 of file ieagan.py.

◆ gain

gain = which_linear(input_size, output_size)

Prepare gain and bias layers.

Definition at line 567 of file ieagan.py.

◆ input_size

input_size = output_size, input_size

output size

Definition at line 565 of file ieagan.py.

◆ momentum

momentum = momentum

Momentum.

Definition at line 573 of file ieagan.py.

◆ mybn

mybn = mybn

Use my batchnorm?

Definition at line 577 of file ieagan.py.

◆ norm_style

str norm_style = norm_style

Norm style?

Definition at line 579 of file ieagan.py.

◆ output_size

output_size

output size

Definition at line 565 of file ieagan.py.


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