models_genesis
ContBatchNorm3d
Bases: _BatchNorm
A class representing a 3D contextual batch normalization layer.
Attributes:
Name | Type | Description |
---|---|---|
running_mean |
Tensor
|
The running mean of the batch normalization. |
running_var |
Tensor
|
The running variance of the batch normalization. |
weight |
Tensor
|
The learnable weights of the batch normalization. |
bias |
Tensor
|
The learnable bias of the batch normalization. |
momentum |
float
|
The momentum for updating the running statistics. |
eps |
float
|
Small value added to the denominator for numerical stability. |
Source code in fmcib/models/models_genesis.py
_check_input_dim(input)
Check if the input tensor is 5-dimensional.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
Tensor
|
Input tensor to check the dimensionality. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the input tensor is not 5-dimensional. |
Source code in fmcib/models/models_genesis.py
forward(input)
Apply forward pass for the input through batch normalization layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
Tensor
|
Input tensor to be normalized. |
required |
Returns:
Name | Type | Description |
---|---|---|
Tensor |
Normalized output tensor. |
Raises:
Type | Description |
---|---|
ValueError
|
If the dimensions of the input tensor do not match the expected input dimensions. |
Source code in fmcib/models/models_genesis.py
DownTransition
Bases: Module
A class representing a down transition module in a neural network.
Attributes:
Name | Type | Description |
---|---|---|
in_channel |
int
|
The number of input channels. |
depth |
int
|
The depth of the down transition module. |
act |
Module
|
The activation function used in the module. |
Source code in fmcib/models/models_genesis.py
__init__(in_channel, depth, act)
Initialize a DownTransition object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_channel
|
int
|
The number of channels in the input. |
required |
depth
|
int
|
The depth of the DownTransition. |
required |
act
|
function
|
The activation function. |
required |
Returns:
Type | Description |
---|---|
None |
Source code in fmcib/models/models_genesis.py
forward(x)
Perform a forward pass through the neural network.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input tensor. |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple containing two tensors. The first tensor is the output of the forward pass. The second tensor is the output before applying the max pooling operation. |
Source code in fmcib/models/models_genesis.py
LUConv
Bases: Module
A class representing a LUConv module.
This module performs a convolution operation on the input data with a specified number of input channels and output channels. The convolution is followed by batch normalization and an activation function.
Attributes:
Name | Type | Description |
---|---|---|
in_chan |
int
|
The number of input channels. |
out_chan |
int
|
The number of output channels. |
act |
str
|
The activation function to be applied. Can be one of 'relu', 'prelu', or 'elu'. |
Source code in fmcib/models/models_genesis.py
__init__(in_chan, out_chan, act)
Initialize a LUConv layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_chan
|
int
|
Number of input channels. |
required |
out_chan
|
int
|
Number of output channels. |
required |
act
|
str
|
Activation function. Options: 'relu', 'prelu', 'elu'. |
required |
Returns:
Type | Description |
---|---|
None |
Raises:
Type | Description |
---|---|
TypeError
|
If the activation function is not one of the specified options. |
Source code in fmcib/models/models_genesis.py
forward(x)
Apply forward pass through the neural network.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
Input tensor to the network. |
required |
Returns:
Name | Type | Description |
---|---|---|
Tensor |
Output tensor after passing through the network. |
Source code in fmcib/models/models_genesis.py
OutputTransition
Bases: Module
A class representing the output transition in a neural network.
Attributes:
Name | Type | Description |
---|---|---|
inChans |
int
|
The number of input channels. |
n_labels |
int
|
The number of output labels. |
Source code in fmcib/models/models_genesis.py
__init__(inChans, n_labels)
Initialize the OutputTransition class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inChans
|
int
|
Number of input channels. |
required |
n_labels
|
int
|
Number of output labels. |
required |
Returns:
Type | Description |
---|---|
None |
Source code in fmcib/models/models_genesis.py
forward(x)
Forward pass through a neural network model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input tensor. |
required |
Returns:
Name | Type | Description |
---|---|---|
Tensor |
The output tensor after passing through the model. |
Source code in fmcib/models/models_genesis.py
UNet3D
Bases: Module
A class representing a 3D UNet model for segmentation.
Attributes:
Name | Type | Description |
---|---|---|
n_class |
int
|
The number of classes for segmentation. |
act |
str
|
The activation function type used in the model. |
decoder |
bool
|
Whether to include the decoder part in the model. |
Methods:
Name | Description |
---|---|
forward |
Forward pass of the model. |
Source code in fmcib/models/models_genesis.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
|
__init__(n_class=1, act='relu', decoder=True)
Initialize a 3D UNet neural network model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_class
|
int
|
The number of output classes. Defaults to 1. |
1
|
act
|
str
|
The activation function to use. Defaults to 'relu'. |
'relu'
|
decoder
|
bool
|
Whether to include the decoder layers. Defaults to True. |
True
|
Attributes:
Name | Type | Description |
---|---|---|
decoder |
bool
|
Whether the model includes decoder layers. |
down_tr64 |
DownTransition
|
The first down transition layer. |
down_tr128 |
DownTransition
|
The second down transition layer. |
down_tr256 |
DownTransition
|
The third down transition layer. |
down_tr512 |
DownTransition
|
The fourth down transition layer. |
up_tr256 |
UpTransition
|
The first up transition layer. (Only exists if |
up_tr128 |
UpTransition
|
The second up transition layer. (Only exists if |
up_tr64 |
UpTransition
|
The third up transition layer. (Only exists if |
out_tr |
OutputTransition
|
The output transition layer. (Only exists if |
avg_pool |
AvgPool3d
|
The average pooling layer. (Only exists if |
flatten |
Flatten
|
The flattening layer. (Only exists if |
Source code in fmcib/models/models_genesis.py
forward(x)
Perform forward pass through the neural network.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
Input tensor to the network. |
required |
Returns:
Name | Type | Description |
---|---|---|
Tensor |
Output tensor from the network. |
Note: This function performs a series of operations to downsample the input tensor, followed by upsampling if the 'decoder' flag is set. If the 'decoder' flag is not set, the output tensor goes through average pooling and flattening.
Source code in fmcib/models/models_genesis.py
UpTransition
Bases: Module
A class representing an up transition layer in a neural network.
Attributes:
Name | Type | Description |
---|---|---|
inChans |
int
|
The number of input channels. |
outChans |
int
|
The number of output channels. |
depth |
int
|
The depth of the layer. |
act |
str
|
The activation function to be applied. |
Source code in fmcib/models/models_genesis.py
__init__(inChans, outChans, depth, act)
Initialize the UpTransition module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inChans
|
int
|
The number of input channels. |
required |
outChans
|
int
|
The number of output channels. |
required |
depth
|
int
|
The depth of the module. |
required |
act
|
Module
|
The activation function to be used. |
required |
Returns:
Type | Description |
---|---|
None. |
Source code in fmcib/models/models_genesis.py
forward(x, skip_x)
Forward pass of the neural network.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
Input tensor. |
required |
skip_x
|
Tensor
|
Tensor to be concatenated with the upsampled convolution output. |
required |
Returns:
Type | Description |
---|---|
torch.Tensor: The output tensor after passing through the network. |
Source code in fmcib/models/models_genesis.py
_make_nConv(in_channel, depth, act, double_chnnel=False)
Make a two-layer convolutional neural network module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_channel
|
int
|
The number of input channels. |
required |
depth
|
int
|
The depth of the network. |
required |
act
|
Activation function to be used in the network. |
required | |
double_channel
|
bool
|
If True, double the number of channels in the network. Defaults to False. |
required |
Returns:
Type | Description |
---|---|
nn.Sequential: A sequential module representing the two-layer convolutional network. |
Note
- If double_channel is True, the first layer will have 32 * 2 ** (depth + 1) channels and the second layer will have the same number of channels.
- If double_channel is False, the first layer will have 32 * 2 ** depth channels and the second layer will have 32 * 2 ** depth * 2 channels.