odak.learn.models
odak.learn.models
¶
Provides necessary definitions for components used in machine learning and deep learning.
convolution_layer
¶
Bases: Module
A convolution layer.
Source code in odak/learn/models/components.py
__init__(input_channels=2, output_channels=2, kernel_size=3, bias=False, activation=torch.nn.ReLU())
¶
A convolutional layer class.
Parameters:
-
input_channels
–Number of input channels.
-
output_channels
(int
, default:2
) –Number of output channels.
-
kernel_size
–Kernel size.
-
bias
–Set to True to let convolutional layers have bias term.
-
activation
–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
Source code in odak/learn/models/components.py
forward(x)
¶
Forward model.
Parameters:
-
x
–Input data.
Returns:
-
result
(tensor
) –Estimated output.
Source code in odak/learn/models/components.py
double_convolution
¶
Bases: Module
A double convolution layer.
Source code in odak/learn/models/components.py
__init__(input_channels=2, mid_channels=None, output_channels=2, kernel_size=3, bias=False, activation=torch.nn.ReLU())
¶
Double convolution model.
Parameters:
-
input_channels
–Number of input channels.
-
mid_channels
–Number of channels in the hidden layer between two convolutions.
-
output_channels
(int
, default:2
) –Number of output channels.
-
kernel_size
–Kernel size.
-
bias
–Set to True to let convolutional layers have bias term.
-
activation
–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
Source code in odak/learn/models/components.py
forward(x)
¶
Forward model.
Parameters:
-
x
–Input data.
Returns:
-
result
(tensor
) –Estimated output.
Source code in odak/learn/models/components.py
downsample_layer
¶
Bases: Module
A downscaling component followed by a double convolution.
Source code in odak/learn/models/components.py
__init__(input_channels, output_channels, kernel_size=3, bias=False, activation=torch.nn.ReLU())
¶
A downscaling component with a double convolution.
Parameters:
-
input_channels
–Number of input channels.
-
output_channels
(int
) –Number of output channels.
-
kernel_size
–Kernel size.
-
bias
–Set to True to let convolutional layers have bias term.
-
activation
–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
Source code in odak/learn/models/components.py
forward(x)
¶
Forward model.
Parameters:
-
x
–First input data.
Returns:
-
result
(tensor
) –Estimated output.
Source code in odak/learn/models/components.py
non_local_layer
¶
Bases: Module
Self-Attention Layer [zi = Wzyi + xi] (non-local block : ref https://arxiv.org/abs/1711.07971)
Source code in odak/learn/models/components.py
__init__(input_channels=1024, bottleneck_channels=512, kernel_size=1, bias=False)
¶
Parameters:
-
input_channels
–Number of input channels.
-
bottleneck_channels
(int
, default:512
) –Number of middle channels.
-
kernel_size
–Kernel size.
-
bias
–Set to True to let convolutional layers have bias term.
Source code in odak/learn/models/components.py
forward(x)
¶
Forward model [zi = Wzyi + xi]
Parameters:
-
x
–First input data.
Returns:
-
z
(tensor
) –Estimated output.
Source code in odak/learn/models/components.py
normalization
¶
Bases: Module
A normalization layer.
Source code in odak/learn/models/components.py
__init__(dim=1)
¶
Normalization layer.
Parameters:
-
dim
–Dimension (axis) to normalize.
Source code in odak/learn/models/components.py
forward(x)
¶
Forward model.
Parameters:
-
x
–Input data.
Returns:
-
result
(tensor
) –Estimated output.
Source code in odak/learn/models/components.py
residual_attention_layer
¶
Bases: Module
A residual block with an attention layer.
Source code in odak/learn/models/components.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 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 |
|
__init__(input_channels=2, output_channels=2, kernel_size=1, bias=False, activation=torch.nn.ReLU())
¶
An attention layer class.
Parameters:
-
input_channels
–Number of input channels.
-
output_channels
(int or optional
, default:2
) –Number of middle channels.
-
kernel_size
–Kernel size.
-
bias
–Set to True to let convolutional layers have bias term.
-
activation
–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
Source code in odak/learn/models/components.py
forward(x0, x1)
¶
Forward model.
Parameters:
-
x0
–First input data.
-
x1
–Seconnd input data.
Returns:
-
result
(tensor
) –Estimated output.
Source code in odak/learn/models/components.py
residual_layer
¶
Bases: Module
A residual layer.
Source code in odak/learn/models/components.py
__init__(input_channels=2, mid_channels=16, kernel_size=3, bias=False, activation=torch.nn.ReLU())
¶
A convolutional layer class.
Parameters:
-
input_channels
–Number of input channels.
-
mid_channels
–Number of middle channels.
-
kernel_size
–Kernel size.
-
bias
–Set to True to let convolutional layers have bias term.
-
activation
–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
Source code in odak/learn/models/components.py
forward(x)
¶
Forward model.
Parameters:
-
x
–Input data.
Returns:
-
result
(tensor
) –Estimated output.
upsample_layer
¶
Bases: Module
An upsampling convolutional layer.
Source code in odak/learn/models/components.py
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
|
__init__(input_channels, output_channels, kernel_size=3, bias=False, activation=torch.nn.ReLU(), bilinear=True)
¶
A downscaling component with a double convolution.
Parameters:
-
input_channels
–Number of input channels.
-
output_channels
(int
) –Number of output channels.
-
kernel_size
–Kernel size.
-
bias
–Set to True to let convolutional layers have bias term.
-
activation
–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
-
bilinear
–If set to True, bilinear sampling is used.
Source code in odak/learn/models/components.py
forward(x1, x2)
¶
Forward model.
Parameters:
-
x1
–First input data.
-
x2
–Second input data.
Returns:
-
result
(tensor
) –Result of the forward operation
Source code in odak/learn/models/components.py
unet
¶
Bases: Module
A U-Net model, heavily inspired from https://github.com/milesial/Pytorch-UNet/tree/master/unet
and more can be read from Ronneberger, Olaf, Philipp Fischer, and Thomas Brox. "U-net: Convolutional networks for biomedical image segmentation." Medical Image Computing and Computer-Assisted Intervention–MICCAI 2015: 18th International Conference, Munich, Germany, October 5-9, 2015, Proceedings, Part III 18. Springer International Publishing, 2015.
Source code in odak/learn/models/models.py
__init__(depth=4, dimensions=64, input_channels=2, output_channels=1, bilinear=False, kernel_size=3, bias=False, activation=torch.nn.ReLU(inplace=True))
¶
U-Net model.
Parameters:
-
depth
–Number of upsampling and downsampling
-
dimensions
–Number of dimensions.
-
input_channels
–Number of input channels.
-
output_channels
–Number of output channels.
-
bilinear
–Uses bilinear upsampling in upsampling layers when set True.
-
bias
–Set True to let convolutional layers learn a bias term.
-
activation
–Non-linear activation layer to be used (e.g., torch.nn.ReLU(), torch.nn.Sigmoid().
Source code in odak/learn/models/models.py
forward(x)
¶
Forward model.
Parameters:
-
x
–Input data.
Returns:
-
result
(tensor
) –Estimated output.