Belle II Software development
Model Class Reference
Inheritance diagram for Model:
Generator

Public Member Functions

 __init__ (self)
 Constructor.
 
 init_weights (self)
 Initialize.
 
 forward (self, z, y)
 forward
 

Public Attributes

 ch = G_ch
 Channel width multiplier.
 
 G_depth = G_depth
 Number of resblocks per stage.
 
 dim_z = dim_z
 Dimensionality of the latent space.
 
 bottom_width = bottom_width
 The initial spatial dimensions.
 
 H_base = H_base
 The initial harizontal dimension.
 
 resolution = resolution
 Resolution of the output.
 
 kernel_size = G_kernel_size
 Kernel size?
 
 attention = G_attn
 Attention?
 
 n_classes = n_classes
 number of classes, for use in categorical conditional generation
 
 G_shared = G_shared
 Use shared embeddings?
 
int shared_dim = shared_dim if shared_dim > 0 else dim_z
 Dimensionality of the shared embedding?
 
# y and z are[bs, 128] dimensional hier = hier
 Hierarchical latent space?
 
 cross_replica = cross_replica
 Cross replica batchnorm?
 
 mybn = mybn
 Use my batchnorm?
 
 activation = torch.nn.ReLU(inplace=True)
 activation
 
str init = G_init
 Initialization style.
 
str G_param = G_param
 Parameterization style.
 
 norm_style = norm_style
 Normalization style.
 
 BN_eps = BN_eps
 Epsilon for BatchNorm?
 
 SN_eps = SN_eps
 Epsilon for Spectral Norm?
 
 fp16 = G_fp16
 fp16?
 
 arch = G_arch(self.ch, self.attention)[resolution]
 Architecture dict.
 
 RRM_prx_G = RRM_prx_G
 RRM_prx_G.
 
 n_head_G = n_head_G
 n_head_G
 
 which_conv
 which conv
 
 which_linear
 which linear
 
 which_embedding = nn.Embedding
 which embedding
 
 which_bn
 which bn
 
tuple shared
 shared
 
 RR_G
 RRM on proxy embeddings.
 
 linear
 First linear layer.
 
list blocks = []
 blocks
 
 output_layer
 output layer
 
 lr = G_lr
 lr
 
 B1 = G_B1
 B1.
 
 B2 = G_B2
 B2.
 
 adam_eps = adam_eps
 adam_eps
 
 optim
 optim
 
 lr_sched = None
 lr sched
 
int param_count = 0
 parameter count
 

Detailed Description

Generator subclass default initializing with CONFIG dict

Definition at line 1459 of file ieagan.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self)

Constructor.

Definition at line 1466 of file ieagan.py.

1466 def __init__(self):
1467 super().__init__(**CONFIG)
1468
1469

Member Function Documentation

◆ forward()

forward ( self,
z,
y )
inherited

forward

Definition at line 1435 of file ieagan.py.

1435 def forward(self, z, y):
1436 y = self.shared(y)
1437 # If relational embedding
1438 if self.RRM_prx_G:
1439 y = self.RR_G(y.unsqueeze(0)).squeeze(0)
1440 # y = F.normalize(y, dim=1)
1441 # If hierarchical, concatenate zs and ys
1442 if self.hier: # y and z are [bs,128] dimensional
1443 z = torch.cat([y, z], 1)
1444 y = z
1445 # First linear layer
1446 h = self.linear(z) # ([bs,256]-->[bs,24576])
1447 # Reshape
1448 h = h.view(h.size(0), -1, self.bottom_width, self.bottom_width * self.H_base)
1449 # Loop over blocks
1450 for _, blocklist in enumerate(self.blocks):
1451 # Second inner loop in case block has multiple layers
1452 for block in blocklist:
1453 h = block(h, y)
1454
1455 # Apply batchnorm-relu-conv-tanh at output
1456 return torch.tanh(self.output_layer(h))
1457
1458

◆ init_weights()

init_weights ( self)
inherited

Initialize.

Definition at line 1412 of file ieagan.py.

1412 def init_weights(self):
1413
1414 self.param_count = 0
1415 for module in self.modules():
1416 if (
1417 isinstance(module, nn.Conv2d)
1418 or isinstance(module, nn.Linear)
1419 or isinstance(module, nn.Embedding)
1420 ):
1421 if self.init == "ortho":
1422 init.orthogonal_(module.weight)
1423 elif self.init == "N02":
1424 init.normal_(module.weight, 0, 0.02)
1425 elif self.init in ["glorot", "xavier"]:
1426 init.xavier_uniform_(module.weight)
1427 else:
1428 print("Init style not recognized...")
1429 self.param_count += sum(
1430 [p.data.nelement() for p in module.parameters()]
1431 )
1432 print(f"Param count for G's initialized parameters: {self.param_count}")
1433

Member Data Documentation

◆ activation

activation = torch.nn.ReLU(inplace=True)
inherited

activation

Definition at line 1201 of file ieagan.py.

◆ adam_eps

adam_eps = adam_eps
inherited

adam_eps

Definition at line 1372 of file ieagan.py.

◆ arch

arch = G_arch(self.ch, self.attention)[resolution]
inherited

Architecture dict.

Definition at line 1221 of file ieagan.py.

◆ attention

attention = G_attn
inherited

Attention?

Definition at line 1185 of file ieagan.py.

◆ B1

B1 = G_B1
inherited

B1.

Definition at line 1368 of file ieagan.py.

◆ B2

B2 = G_B2
inherited

B2.

Definition at line 1370 of file ieagan.py.

◆ blocks

blocks = []
inherited

blocks

Definition at line 1299 of file ieagan.py.

◆ BN_eps

BN_eps = BN_eps
inherited

Epsilon for BatchNorm?

Definition at line 1215 of file ieagan.py.

◆ bottom_width

bottom_width = bottom_width
inherited

The initial spatial dimensions.

Definition at line 1177 of file ieagan.py.

◆ ch

ch = G_ch
inherited

Channel width multiplier.

Definition at line 1171 of file ieagan.py.

◆ cross_replica

cross_replica = cross_replica
inherited

Cross replica batchnorm?

Definition at line 1195 of file ieagan.py.

◆ dim_z

dim_z = dim_z
inherited

Dimensionality of the latent space.

Definition at line 1175 of file ieagan.py.

◆ fp16

fp16 = G_fp16
inherited

fp16?

Definition at line 1219 of file ieagan.py.

◆ G_depth

G_depth = G_depth
inherited

Number of resblocks per stage.

Definition at line 1173 of file ieagan.py.

◆ G_param

str G_param = G_param
inherited

Parameterization style.

Definition at line 1211 of file ieagan.py.

◆ G_shared

G_shared = G_shared
inherited

Use shared embeddings?

Definition at line 1189 of file ieagan.py.

◆ H_base

H_base = H_base
inherited

The initial harizontal dimension.

Definition at line 1179 of file ieagan.py.

◆ hier

# y and z are [bs,128] dimensional hier = hier
inherited

Hierarchical latent space?

Definition at line 1193 of file ieagan.py.

◆ init

str init = G_init
inherited

Initialization style.

Definition at line 1209 of file ieagan.py.

◆ kernel_size

kernel_size = G_kernel_size
inherited

Kernel size?

Definition at line 1183 of file ieagan.py.

◆ linear

linear
inherited
Initial value:
= self.which_linear(
self.dim_z + self.shared_dim,
self.arch["in_channels"][0] * ((self.bottom_width**2) * self.H_base),
)

First linear layer.

Definition at line 1290 of file ieagan.py.

◆ lr

lr = G_lr
inherited

lr

Definition at line 1366 of file ieagan.py.

◆ lr_sched

lr_sched = None
inherited

lr sched

Definition at line 1396 of file ieagan.py.

◆ mybn

mybn = mybn
inherited

Use my batchnorm?

Definition at line 1197 of file ieagan.py.

◆ n_classes

n_classes = n_classes
inherited

number of classes, for use in categorical conditional generation

Definition at line 1187 of file ieagan.py.

◆ n_head_G

n_head_G = n_head_G
inherited

n_head_G

Definition at line 1225 of file ieagan.py.

◆ norm_style

norm_style = norm_style
inherited

Normalization style.

Definition at line 1213 of file ieagan.py.

◆ optim

optim
inherited
Initial value:
= utils.Adam16(
params=self.parameters(),
lr=self.lr,
betas=(self.B1, self.B2),
weight_decay=0,
eps=self.adam_eps,
)

optim

Definition at line 1377 of file ieagan.py.

◆ output_layer

output_layer
inherited
Initial value:
= nn.Sequential(
bn(
self.arch["out_channels"][-1],
cross_replica=self.cross_replica,
mybn=self.mybn,
),
self.activation,
self.which_conv(self.arch["out_channels"][-1], 1),
)

output layer

Definition at line 1347 of file ieagan.py.

◆ param_count

int param_count = 0
inherited

parameter count

Definition at line 1414 of file ieagan.py.

◆ resolution

resolution = resolution
inherited

Resolution of the output.

Definition at line 1181 of file ieagan.py.

◆ RR_G

RR_G
inherited
Initial value:
= RelationalReasoning(
num_layers=1,
input_dim=128,
dim_feedforward=128,
which_linear=nn.Linear,
num_heads=self.n_head_G,
dropout=0.0,
hidden_dim=128,
)

RRM on proxy embeddings.

Definition at line 1279 of file ieagan.py.

◆ RRM_prx_G

RRM_prx_G = RRM_prx_G
inherited

RRM_prx_G.

Definition at line 1223 of file ieagan.py.

◆ shared

tuple shared
inherited
Initial value:
= (
self.which_embedding(n_classes, self.shared_dim)
if G_shared
else identity()
)

shared

Definition at line 1271 of file ieagan.py.

◆ shared_dim

int shared_dim = shared_dim if shared_dim > 0 else dim_z
inherited

Dimensionality of the shared embedding?

Unused if not using G_shared

Definition at line 1191 of file ieagan.py.

◆ SN_eps

SN_eps = SN_eps
inherited

Epsilon for Spectral Norm?

Definition at line 1217 of file ieagan.py.

◆ which_bn

which_bn
inherited
Initial value:
= functools.partial(
ccbn,
which_linear=bn_linear,
cross_replica=self.cross_replica,
mybn=self.mybn,
input_size=(
self.shared_dim + self.dim_z if self.G_shared else self.n_classes
),
norm_style=self.norm_style,
eps=self.BN_eps,
)

which bn

Definition at line 1259 of file ieagan.py.

◆ which_conv

which_conv
inherited
Initial value:
= functools.partial(
SNConv2d,
kernel_size=3,
padding=1,
num_svs=num_G_SVs,
num_itrs=num_G_SV_itrs,
eps=self.SN_eps,
)

which conv

Definition at line 1230 of file ieagan.py.

◆ which_embedding

which_embedding = nn.Embedding
inherited

which embedding

Definition at line 1252 of file ieagan.py.

◆ which_linear

which_linear
inherited
Initial value:
= functools.partial(
SNLinear,
num_svs=num_G_SVs,
num_itrs=num_G_SV_itrs,
eps=self.SN_eps,
)

which linear

Definition at line 1239 of file ieagan.py.


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