odak.learn.models
odak.learn.models
Provides necessary definitions for components used in machine learning and deep learning.
channel_gate
¶
Bases: Module
Channel attention module with various pooling strategies. This class is heavily inspired https://github.com/Jongchan/attention-module/commit/e4ee180f1335c09db14d39a65d97c8ca3d1f7b16 (MIT License).
Source code in odak/learn/models/components.py
__init__(gate_channels, reduction_ratio=16, pool_types=['avg', 'max'])
¶
Initializes the channel gate module.
Parameters:
-
gate_channels–Number of channels of the input feature map. -
reduction_ratio(int, default:16) –Reduction ratio for the intermediate layer. -
pool_types–List of pooling operations to apply.
Source code in odak/learn/models/components.py
forward(x)
¶
Forward pass of the ChannelGate module.
Applies channel-wise attention to the input tensor.
Parameters:
-
x–Input tensor to the ChannelGate module.
Returns:
-
output(tensor) –Output tensor after applying channel attention.
Source code in odak/learn/models/components.py
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, stride=1, normalization=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. -
normalization–If True, adds a Batch Normalization layer after the convolutional layer. -
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
convolutional_block_attention
¶
Bases: Module
Convolutional Block Attention Module (CBAM) class. This class is heavily inspired https://github.com/Jongchan/attention-module/commit/e4ee180f1335c09db14d39a65d97c8ca3d1f7b16 (MIT License).
Source code in odak/learn/models/components.py
Flatten
¶
__init__(gate_channels, reduction_ratio=16, pool_types=['avg', 'max'], no_spatial=False)
¶
Initializes the convolutional block attention module.
Parameters:
-
gate_channels–Number of channels of the input feature map. -
reduction_ratio(int, default:16) –Reduction ratio for the channel attention. -
pool_types–List of pooling operations to apply for channel attention. -
no_spatial–If True, spatial attention is not applied.
Source code in odak/learn/models/components.py
forward(x)
¶
Forward pass of the convolutional block attention module.
Parameters:
-
x–Input tensor to the CBAM module.
Returns:
-
x_out(tensor) –Output tensor after applying channel and spatial attention.
Source code in odak/learn/models/components.py
double_convolution
¶
Bases: Module
A double convolution layer.
Source code in odak/learn/models/components.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
__init__(input_channels=2, mid_channels=None, output_channels=2, kernel_size=3, bias=False, normalization=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. -
normalization–If True, adds a Batch Normalization layer after the convolutional layer. -
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, normalization=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. -
normalization–If True, adds a Batch Normalization layer after the convolutional layer. -
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
gaussian_2d
¶
Bases: Module
2D Gaussian model for learning image representations using 2D Gaussian primitives.
This model represents an image as a weighted sum of 2D Gaussians, each defined by: - widths (std_x, std_y): Standard deviations along x and y axes - offsets (offset_x, offset_y): Center positions in normalized coordinates - rotations: Rotation angles for each Gaussian - alphas: Opacity/weight coefficients
Parameters:
-
number_of_elements(int, default:10) –Number of 2D Gaussian elements to use. Default is 10.
Attributes:
-
widths((Parameter, shape(2, 1, N))) –Standard deviations for x and y dimensions.
-
offsets((Parameter, shape(2, 1, N))) –Center offsets in x and y directions.
-
rotations((Parameter, shape(1, N))) –Rotation angles in radians for each Gaussian.
-
alphas((Parameter, shape(1, N))) –Opacity/weight coefficients blended with tanh activation.
Examples:
>>> model = gaussian_2d(number_of_elements=50)
>>> x = torch.linspace(-1, 1, 256)
>>> y = torch.linspace(-1, 1, 256)
>>> X, Y = torch.meshgrid(x, y, indexing='ij')
>>> output = model(X, Y)
Notes
- All parameters are initialized on CPU by default. For GPU acceleration, call .to(device) after initializing this model.
- Input coordinates x and y should typically be normalized to [-1, 1].
- Output is the sum of weighted Gaussians passed through tanh().
Source code in odak/learn/models/gaussians.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
__init__(number_of_elements=10)
¶
Initialize the 2D Gaussian model.
Parameters:
-
number_of_elements(int, default:10) –Number of Gaussian elements (default: 10).
Source code in odak/learn/models/gaussians.py
forward(x, y, residual=1e-06)
¶
Forward pass: evaluate the 2D Gaussian model at given coordinates.
Computes a weighted sum of 2D Gaussians evaluated at the input grid
coordinates (x, y). Each Gaussian is rotated and translated according
to its learned parameters.
Parameters
Parameters
x : torch.Tensor
X-coordinates of the evaluation grid. Shape should broadcast with y.
y : torch.Tensor
Y-coordinates of the evaluation grid. Shape should broadcast with x.
residual : float, optional
Small constant to avoid numerical issues (default: 1e-6).
Returns
Returns
results : torch.Tensor
The evaluated Gaussian field at input coordinates. The output
shape is determined by broadcasting x, y with the parameter shapes.
Values are passed through tanh() activation and multiplied by alphas.
Notes
Notes
- Coordinates are first rotated using learned rotation angles.
- Then translated by learned offsets for each Gaussian.
- The 2D Gaussian function is evaluated as exp(-(x^2 + y^2)) scaled by widths.
- Final output: tanh(alphas * gaussians) summed over all elements.
Notes
- Supports multiple input shapes via PyTorch broadcasting
- For grid inputs (H, W): automatically broadcasts to (H, W, N_elements)
- For flattened inputs (N, 1): broadcasts directly with parameters
Source code in odak/learn/models/gaussians.py
initialize_parameters_uniformly(ranges=None)
¶
Initialize parameters using uniform-like distributions within specified ranges.
This method re-samples the model parameters from normal distributions whose mean and standard deviation are derived from the provided ranges. For a range [a, b], it uses: mean = (a + b) / 2 std = (b - a) / 4
Parameters:
-
ranges(dict or None, default:None) –Dictionary specifying custom initialization ranges. Keys can include: - 'widths': tuple of (min, max) for Gaussian widths - 'offsets': tuple of (min, max) for center offsets - 'rotations': tuple of (min, max) for rotation angles in radians - 'alphas': tuple of (min, max) for opacity values If None, default ranges are used: { "widths": (0.1, 0.5), "offsets": (-1.0, 1.0), "rotations": (0.0, 2*pi), "alphas": (0.1, 0.2) }
Notes
- Uses torch.no_grad() to avoid tracking gradients during initialization.
- Parameters are initialized in-place using normal_() method.
Source code in odak/learn/models/gaussians.py
gaussian_3d_volume
¶
Bases: Module
Initialize the 3D Gaussian volume model. This model is useful for learning voxelized 3D volumes.
Parameters:
-
number_of_elements(int, default:10) –Number of Gaussian elements in the volume (default: 10). -
initial_centers–Initial centers of the Gaussians (shape: [N, 3]). If not provided, random initialization is used where N is `number_of_elements`. -
initial_angles–Initial angles defining the orientation of each Gaussian. If not provided, random initialization is used. -
initial_scales–Initial scales controlling the spread (variance) of each Gaussian. If not provided, random initialization is used. -
initial_alphas–Initial alphas controlling the blending between Gaussians. If not provided, random initialization is used.
Source code in odak/learn/models/gaussians.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 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 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 | |
__init__(number_of_elements=10, initial_centers=None, initial_angles=None, initial_scales=None, initial_alphas=None)
¶
Initialize the 3D Gaussian volume model.
Parameters:
-
number_of_elements(int, default:10) –Number of Gaussian elements in the volume (default: 10). -
initial_centers–Initial centers of the Gaussians (shape: [N, 3]). -
initial_angles–Initial angles for orientation. -
initial_scales–Initial scales for variance. -
initial_alphas–Initial alphas for blending.
Device Placement
All parameters are initialized on CPU by default. For GPU acceleration, call .to(device) after initializing this model. Example: model = gaussian_3d_volume().cuda() # or .to('cuda')
Source code in odak/learn/models/gaussians.py
evaluate(estimate, ground_truth, epoch_id=0, epoch_count=1, weights={'content': {'l2': 1.0, 'l1': 0.0}, 'alpha': {'smaller': 0.0, 'larger': 0.0, 'threshold': [0.0, 1.0]}, 'scale': {'smaller': 0.0, 'larger': 0.0, 'threshold': [0.0, 1.0]}, 'alpha': 0.0, 'angle': 0.0, 'center': 0.0, 'utilization': {'l2': 0.0, 'percentile': 0}})
¶
Parameters:
-
estimate–Model's output estimate. -
ground_truth(Tensor) –Ground truth values. -
epoch_id–ID of the starting epoch. Default: 0. -
epoch_count–Total number of epochs for training. Default: 1. -
weights–Dictionary containing weights for various loss components: - content: {'l2': float, 'l1': float} - scale: {'smaller': float, 'larger': float, 'threshold': List[float]} - alpha: {'smaller': float, 'larger': float, 'threshold': List[float]} - angle : float - center: float - utilization: {'l2': float, 'percentile': int}
Source code in odak/learn/models/gaussians.py
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 | |
forward(points, test=False)
¶
Forward pass: evaluate the 3D Gaussian volume at given points.
Parameters:
-
points–Input points at which to evaluate the Gaussian volume, where each row is a 3D point. -
test–If True, disables gradient computation (default: False).
Returns:
-
total_intensities(Tensor) –Total intensities at the input points, weighted by alphas.
Source code in odak/learn/models/gaussians.py
initialize_parameters(centers=None, angles=None, scales=None, alphas=None, device=torch.device('cpu'))
¶
Initialize model parameters using PyTorch tensors.
Parameters:
-
centers(Tensor, default:None) –If None (default), initializes as a tensor of shape (number_of_elements, 3) with values sampled from standard normal distribution. -
angles–If None (default), initializes similarly to centers: shape (n,3). -
scales–If None (default), initializes as a tensor of shape (number_of_elements, 3) with values uniformly distributed between 0 and 1. -
alphas–If None (default), initializes as a tensor of shape (number_of_elements, 1) with values uniformly distributed between 0 and 1. -
device–Device to be used to define the parameters. Make sure to pass the device you use with this model for proper manual parameter initilization.
Source code in odak/learn/models/gaussians.py
load_weights(weights_filename=None, device=torch.device('cpu'))
¶
Load model weights from a file.
Parameters:
-
weights_filename(str, default:None) –Path to the weights file. If None, no weights are loaded. -
device–Device to load the weights onto (default: 'cpu').
Raises:
-
ValueError : If path validation fails or extension is not allowed.– -
FileNotFoundError: If file does not exist after validation.–
Notes
- If
weights_filenameis a valid file, the model state is updated and set to eval mode. - The file path is validated for security (tilde expanded, path traversal blocked).
- A log message is emitted upon successful loading.
Source code in odak/learn/models/gaussians.py
optimize(points, ground_truth, loss_weights, learning_rate=0.01, number_of_epochs=10, scheduler_power=1, save_at_every=1, max_norm=None, weights_filename=None)
¶
Optimize model parameters using AdamW and a polynomial learning rate scheduler.
Parameters:
-
points–Input data points for the model. -
ground_truth–Ground truth values corresponding to the input points. -
loss_weights–Dictionary of weights for each loss component. -
learning_rate–Learning rate for the optimizer. Default is 1e-2. -
number_of_epochs(int, default:10) –Number of training epochs. Default is 10. -
scheduler_power–Power parameter for the polynomial learning rate scheduler. Default is 1. -
save_at_every–Save model weights every `save_at_every` epochs. Default is 1. -
max_norm–By default it is None, when set clips the gradient with the given threshold. -
weights_filename(str, default:None) –Filename for saving model weights. If None, weights are not saved.
Notes
- Uses AdamW optimizer and PolynomialLR scheduler.
- Logs loss at each epoch and saves weights periodically.
Source code in odak/learn/models/gaussians.py
save_weights(weights_filename)
¶
Save the model weights to a specified file.
Parameters:
-
weights_filename(str) –Path or filename where the weights will be saved. The path can include relative paths and tilde notation (~), which will be expanded by `validate_path`.
Example:
Save model weights to current directory with filename 'model_weights.pth'¶
save_weights('model_weights.pth')
Save model weights to home directory using ~ notation¶
save_weights('~/.weights.pth')
Raises:
-
ValueError : If path validation fails or extension is not allowed.–
Source code in odak/learn/models/gaussians.py
gaussians_2d
¶
Bases: Module
Wrapper class for the 2D Gaussian model with loss computation and evaluation utilities.
This class wraps gaussian_2d and provides additional functionality:
- Loss functions (L1, L2) pre-initialized
- Weight saving/loading methods
- Model parameter counting
Parameters:
-
number_of_elements(int, default:10) –Number of 2D Gaussian primitives in the model (default: 10). -
logger–Logger instance for tracking progress. If None, creates a new one.
Attributes:
-
model(gaussian_2d) –The underlying primitive Gaussian model.
-
l2_loss(MSELoss) –Mean squared error loss function.
-
l1_loss(L1Loss) –L1 absolute loss function.
-
logger(Logger) –Logger instance for info/debug messages.
Examples:
>>> model = gaussians_2d(number_of_elements=50)
>>> x = torch.linspace(-1, 1, 256)
>>> y = torch.linspace(-1, 1, 256)
>>> X, Y = torch.meshgrid(x, y, indexing='ij')
>>> output = model(X, Y, test=False)
Notes
- The
testflag in forward() controls gradient computation (not recommended use). - Use standard training loop with optimizer.zero_grad(), loss.backward(), optimizer.step().
Source code in odak/learn/models/gaussians.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 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 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 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | |
__init__(number_of_elements=10, logger=None)
¶
Initialize the gaussians_2d wrapper model.
Parameters:
-
number_of_elements(int, default:10) –Number of 2D Gaussian elements (default: 10). -
logger–Logger instance (default: creates new logger).
Source code in odak/learn/models/gaussians.py
forward(x, y, test=False)
¶
Forward pass through the Gaussian model.
Parameters:
-
x–X-coordinates of evaluation grid. -
y–Y-coordinates of evaluation grid. -
test–If True, runs in no_grad mode (default: False).
Returns:
-
result(Tensor) –The summed Gaussian field with shape matching x/y grids plus one dimension.
Notes
The test flag is deprecated. Use standard training pattern:
Source code in odak/learn/models/gaussians.py
load_weights(weights_filename=None, device=torch.device('cpu'))
¶
Load model weights from a file.
Parameters:
-
weights_filename(str or None, default:None) –Path to weights file. If None, skips loading. -
device–Device to load weights onto (default: CPU).
Source code in odak/learn/models/gaussians.py
save_weights(weights_filename)
¶
Save model weights to a file.
Parameters:
-
weights_filename(str) –Path to save weights (must end with .pt, .pth, or similar).
Source code in odak/learn/models/gaussians.py
global_feature_module
¶
Bases: Module
A global feature layer that processes global features from input channels and applies them to another input tensor via learned transformations.
Source code in odak/learn/models/components.py
973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 | |
__init__(input_channels, mid_channels, output_channels, kernel_size, bias=False, normalization=False, activation=torch.nn.ReLU())
¶
A global feature layer.
Parameters:
-
input_channels–Number of input channels. -
mid_channels–Number of mid channels. -
output_channels(int) –Number of output channels. -
kernel_size–Kernel size. -
bias–Set to True to let convolutional layers have bias term. -
normalization–If True, adds a Batch Normalization layer after the convolutional layer. -
activation–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
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) –Estimated output.
Source code in odak/learn/models/components.py
global_transformations
¶
Bases: Module
A global feature layer that processes global features from input channels and applies learned transformations to another input tensor.
This implementation is adapted from RSGUnet: https://github.com/MTLab/rsgunet_image_enhance.
Reference: J. Huang, P. Zhu, M. Geng et al. "Range Scaling Global U-Net for Perceptual Image Enhancement on Mobile Devices."
Source code in odak/learn/models/components.py
__init__(input_channels, output_channels)
¶
A global feature layer.
Parameters:
-
input_channels–Number of input channels. -
output_channels(int) –Number of output channels.
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) –Estimated output.
Source code in odak/learn/models/components.py
multi_layer_perceptron
¶
Bases: Module
A multi-layer perceptron model.
Source code in odak/learn/models/models.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
__init__(dimensions, activation=torch.nn.ReLU(), bias=False, model_type='conventional', siren_multiplier=1.0, input_multiplier=None)
¶
Initialize the multi-layer perceptron.
Parameters:
-
dimensions(list of int) –List of integers representing the dimensions of each layer (e.g., [2, 10, 1], where the first layer has two channels and last one has one channel).
-
activation(Module, default:ReLU()) –Nonlinear activation function. Default is
torch.nn.ReLU(). -
bias(bool, default:False) –If set to True, linear layers will include biases. Default is False.
-
siren_multiplier(float, default:1.0) –When using
SIRENmodel type, this parameter functions as a hyperparameter. The original SIREN work uses 30. You can bypass this parameter by providing input that are not normalized and larger than one. Default is 1.0. -
input_multiplier(float, default:None) –Initial value of the input multiplier before the very first layer.
-
model_type(str, default:'conventional') –Model type:
conventional,swish,SIREN,FILM SIREN,Gaussian.conventionalrefers to a standard multi layer perceptron. ForSIREN, see: Sitzmann, Vincent, et al. "Implicit neural representations with periodic activation functions." Advances in neural information processing systems 33 (2020): 7462-7473. ForSwish, see: Ramachandran, Prajit, Barret Zoph, and Quoc V. Le. "Searching for activation functions." arXiv preprint arXiv:1710.05941 (2017). ForFILM SIREN, see: Chan, Eric R., et al. "pi-gan: Periodic implicit generative adversarial networks for 3d-aware image synthesis." Proceedings of the IEEE/CVF conference on computer vision and pattern recognition. 2021. ForGaussian, see: Ramasinghe, Sameera, and Simon Lucey. "Beyond periodicity: Towards a unifying framework for activations in coordinate-mlps." In European Conference on Computer Vision, pp. 142-158. Cham: Springer Nature Switzerland, 2022. Default is "conventional".
Source code in odak/learn/models/models.py
forward(x)
¶
Forward pass of the multi-layer perceptron.
Parameters:
-
x(Tensor) –Input data.
Returns:
-
result(Tensor) –Estimated output.
Source code in odak/learn/models/models.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
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 | |
__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
positional_encoder
¶
Bases: Module
A positional encoder module.
This implementation follows this specific work: Martin-Brualla, Ricardo, Noha Radwan, Mehdi SM Sajjadi, Jonathan T. Barron, Alexey Dosovitskiy, and Daniel Duckworth. "Nerf in the wild: Neural radiance fields for unconstrained photo collections." In Proceedings of the IEEE/CVF conference on computer vision and pattern recognition, pp. 7210-7219. 2021..
Source code in odak/learn/models/components.py
__init__(L)
¶
A positional encoder module.
Parameters:
-
L–Positional encoding level.
forward(x)
¶
Forward model.
Parameters:
-
x–Input data [b x n], where `b` is batch size, `n` is the feature size.
Returns:
-
result(tensor) –Result of the forward operation.
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
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 376 377 378 379 380 381 382 383 384 | |
__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, normalization=True, 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. -
normalization–If True, adds a Batch Normalization layer after the convolutional layer. -
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.
spatial_gate
¶
Bases: Module
Spatial attention module that applies a convolution layer after channel pooling. This class is heavily inspired by https://github.com/Jongchan/attention-module/blob/master/MODELS/cbam.py.
Source code in odak/learn/models/components.py
__init__()
¶
Initializes the spatial gate module.
channel_pool(x)
¶
Applies max and average pooling on the channels.
Parameters:
-
x–Input tensor.
Returns:
-
output(tensor) –Output tensor.
Source code in odak/learn/models/components.py
forward(x)
¶
Forward pass of the SpatialGate module.
Applies spatial attention to the input tensor.
Parameters:
-
x–Input tensor to the SpatialGate module.
Returns:
-
scaled_x(tensor) –Output tensor after applying spatial attention.
Source code in odak/learn/models/components.py
spatially_adaptive_convolution
¶
Bases: Module
A spatially adaptive convolution layer.
References
C. Zheng et al. "Focal Surface Holographic Light Transport using Learned Spatially Adaptive Convolutions." C. Xu et al. "Squeezesegv3: Spatially-adaptive Convolution for Efficient Point-Cloud Segmentation." C. Zheng et al. "Windowing Decomposition Convolutional Neural Network for Image Enhancement."
Source code in odak/learn/models/components.py
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 | |
__init__(input_channels=2, output_channels=2, kernel_size=3, stride=1, padding=1, bias=False, activation=torch.nn.LeakyReLU(0.2, inplace=True))
¶
Initializes a spatially adaptive convolution layer.
Parameters:
-
input_channels–Number of input channels. -
output_channels(int, default:2) –Number of output channels. -
kernel_size–Size of the convolution kernel. -
stride–Stride of the convolution. -
padding–Padding added to both sides of the input. -
bias–If True, includes a bias term in the convolution. -
activation–Activation function to apply. If None, no activation is applied.
Source code in odak/learn/models/components.py
forward(x, sv_kernel_feature)
¶
Forward pass for the spatially adaptive convolution layer.
Parameters:
-
x–Input data tensor. Dimension: (1, C, H, W) -
sv_kernel_feature–Spatially varying kernel features. Dimension: (1, C_i * kernel_size * kernel_size, H, W)
Returns:
-
sa_output(tensor) –Estimated output tensor. Dimension: (1, output_channels, H_out, W_out)
Source code in odak/learn/models/components.py
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 | |
spatially_adaptive_module
¶
Bases: Module
A spatially adaptive module that combines learned spatially adaptive convolutions.
References
Chuanjun Zheng, Yicheng Zhan, Liang Shi, Ozan Cakmakci, and Kaan Akşit, "Focal Surface Holographic Light Transport using Learned Spatially Adaptive Convolutions," SIGGRAPH Asia 2024 Technical Communications (SA Technical Communications '24), December, 2024.
Source code in odak/learn/models/components.py
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 | |
__init__(input_channels=2, output_channels=2, kernel_size=3, stride=1, padding=1, bias=False, activation=torch.nn.LeakyReLU(0.2, inplace=True))
¶
Initializes a spatially adaptive module.
Parameters:
-
input_channels–Number of input channels. -
output_channels(int, default:2) –Number of output channels. -
kernel_size–Size of the convolution kernel. -
stride–Stride of the convolution. -
padding–Padding added to both sides of the input. -
bias–If True, includes a bias term in the convolution. -
activation–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
Source code in odak/learn/models/components.py
forward(x, sv_kernel_feature)
¶
Forward pass for the spatially adaptive module.
Parameters:
-
x–Input data tensor. Dimension: (1, C, H, W) -
sv_kernel_feature–Spatially varying kernel features. Dimension: (1, C_i * kernel_size * kernel_size, H, W)
Returns:
-
output(tensor) –Combined output tensor from standard and spatially adaptive convolutions. Dimension: (1, output_channels, H_out, W_out)
Source code in odak/learn/models/components.py
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 | |
spatially_adaptive_unet
¶
Bases: Module
Spatially varying U-Net model based on spatially adaptive convolution.
References
Chuanjun Zheng, Yicheng Zhan, Liang Shi, Ozan Cakmakci, and Kaan Akşit, "Focal Surface Holographic Light Transport using Learned Spatially Adaptive Convolutions," SIGGRAPH Asia 2024 Technical Communications (SA Technical Communications '24), December, 2024.
Source code in odak/learn/models/models.py
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 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 | |
__init__(depth=3, dimensions=8, input_channels=6, out_channels=6, kernel_size=3, bias=True, normalization=False, activation=torch.nn.LeakyReLU(0.2, inplace=True))
¶
Initialize the spatially adaptive U-Net model.
Parameters:
-
depth(int, default:3) –Number of upsampling and downsampling layers. Default is 3.
-
dimensions(int, default:8) –Number of dimensions. Default is 8.
-
input_channels(int, default:6) –Number of input channels. Default is 6.
-
out_channels(int, default:6) –Number of output channels. Default is 6.
-
kernel_size(int, default:3) –Kernel size for convolutional layers. Default is 3.
-
bias(bool, default:True) –Set to True to let convolutional layers learn a bias term. Default is True.
-
normalization(bool, default:False) –If True, adds a Batch Normalization layer after the convolutional layer. Default is False.
-
activation(Module, default:LeakyReLU(0.2, inplace=True)) –Non-linear activation layer (e.g., torch.nn.ReLU(), torch.nn.Sigmoid()). Default is torch.nn.LeakyReLU(0.2, inplace=True).
Source code in odak/learn/models/models.py
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 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 | |
forward(sv_kernel, field)
¶
Forward pass of the spatially adaptive U-Net.
Parameters:
-
sv_kernel(list of torch.Tensor) –Learned spatially varying kernels. Dimension of each element in the list: (1, C_i * kernel_size * kernel_size, H_i, W_i), where C_i, H_i, and W_i represent the channel, height, and width of each feature at a certain scale.
-
field(Tensor) –Input field data. Dimension: (1, 6, H, W)
Returns:
-
target_field(Tensor) –Estimated output. Dimension: (1, 6, H, W)
Source code in odak/learn/models/models.py
spatially_varying_kernel_generation_model
¶
Bases: Module
Spatially_varying_kernel_generation_model revised from RSGUnet: https://github.com/MTLab/rsgunet_image_enhance.
Refer to: J. Huang, P. Zhu, M. Geng et al. Range Scaling Global U-Net for Perceptual Image Enhancement on Mobile Devices.
Source code in odak/learn/models/models.py
231 232 233 234 235 236 237 238 239 240 241 242 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 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 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
__init__(depth=3, dimensions=8, input_channels=7, kernel_size=3, bias=True, normalization=False, activation=torch.nn.LeakyReLU(0.2, inplace=True))
¶
Initialize the spatially varying kernel generation model.
Parameters:
-
depth(int, default:3) –Number of upsampling and downsampling layers. Default is 3.
-
dimensions(int, default:8) –Number of dimensions. Default is 8.
-
input_channels(int, default:7) –Number of input channels. Default is 7.
-
kernel_size(int, default:3) –Kernel size for convolutional layers. Default is 3.
-
bias(bool, default:True) –Set to True to let convolutional layers learn a bias term. Default is True.
-
normalization(bool, default:False) –If True, adds a Batch Normalization layer after the convolutional layer. Default is False.
-
activation(Module, default:LeakyReLU(0.2, inplace=True)) –Non-linear activation layer (e.g., torch.nn.ReLU(), torch.nn.Sigmoid()). Default is torch.nn.LeakyReLU(0.2, inplace=True).
Source code in odak/learn/models/models.py
240 241 242 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 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 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
forward(focal_surface, field)
¶
Forward pass of the spatially varying kernel generation model.
Parameters:
-
focal_surface(Tensor) –Input focal surface data. Dimension: (1, 1, H, W)
-
field(Tensor) –Input field data. Dimension: (1, 6, H, W)
Returns:
-
sv_kernel(list of torch.Tensor) –Learned spatially varying kernels. Dimension of each element in the list: (1, C_i * kernel_size * kernel_size, H_i, W_i), where C_i, H_i, and W_i represent the channel, height, and width of each feature at a certain scale.
Source code in odak/learn/models/models.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
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
__init__(depth=4, dimensions=64, input_channels=2, output_channels=1, bilinear=False, kernel_size=3, bias=False, activation=torch.nn.ReLU(inplace=True))
¶
Initialize the U-Net model.
Parameters:
-
depth(int, default:4) –Number of upsampling and downsampling layers. Default is 4.
-
dimensions(int, default:64) –Number of dimensions. Default is 64.
-
input_channels(int, default:2) –Number of input channels. Default is 2.
-
output_channels(int, default:1) –Number of output channels. Default is 1.
-
bilinear(bool, default:False) –Uses bilinear upsampling in upsampling layers when set True. Default is False.
-
kernel_size(int, default:3) –Kernel size for convolutional layers. Default is 3.
-
bias(bool, default:False) –Set True to let convolutional layers learn a bias term. Default is False.
-
activation(Module, default:ReLU(inplace=True)) –Non-linear activation layer to be used (e.g., torch.nn.ReLU(), torch.nn.Sigmoid()). Default is torch.nn.ReLU(inplace=True).
Source code in odak/learn/models/models.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
forward(x)
¶
Forward pass of the U-Net.
Parameters:
-
x(Tensor) –Input data.
Returns:
-
result(Tensor) –Estimated output.
Source code in odak/learn/models/models.py
upsample_convtranspose2d_layer
¶
Bases: Module
An upsampling convtranspose2d layer.
Source code in odak/learn/models/components.py
__init__(input_channels, output_channels, kernel_size=2, stride=2, bias=False)
¶
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.
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
upsample_layer
¶
Bases: Module
An upsampling convolutional layer.
Source code in odak/learn/models/components.py
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 | |
__init__(input_channels, output_channels, kernel_size=3, bias=False, normalization=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. -
normalization–If True, adds a Batch Normalization layer after the convolutional layer. -
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
evaluate_3d_gaussians(points, centers=torch.zeros(1, 3), scales=torch.ones(1, 3), angles=torch.zeros(1, 3), opacity=torch.ones(1, 1))
¶
Evaluate 3D Gaussian functions at given points, with optional rotation.
Parameters:
-
points–The 3D points at which to evaluate the Gaussians. -
centers–The centers of the Gaussians. -
scales–The standard deviations (spread) of the Gaussians along each axis. -
angles–The rotation angles (in radians) for each Gaussian, applied to the points. -
opacity–Opacity of the Gaussians.
Returns:
-
intensities((Tensor, shape[n, 1])) –The evaluated Gaussian intensities at each point.
Source code in odak/learn/tools/function.py
gaussian(x, multiplier=1.0)
¶
A Gaussian non-linear activation. For more details: Ramasinghe, Sameera, and Simon Lucey. "Beyond periodicity: Towards a unifying framework for activations in coordinate-mlps." In European Conference on Computer Vision, pp. 142-158. Cham: Springer Nature Switzerland, 2022.
Parameters:
-
x–Input data. -
multiplier–Multiplier.
Returns:
-
result(float or tensor) –Ouput data.
Source code in odak/learn/models/components.py
swish(x)
¶
A swish non-linear activation. For more details: https://en.wikipedia.org/wiki/Swish_function
Parameters:
-
x–Input.
Returns:
-
out(float or tensor) –Output.
Source code in odak/learn/models/components.py
validate_path(path, allowed_extensions=None)
¶
Validates a file path for security safety.
Parameters:
-
path–Path to validate. -
allowed_extensions(list, default:None) –List of allowed extensions (e.g., ['.png', '.jpg']). If None, all extensions are allowed.
Returns:
-
safe_path(str) –The validated and secured path (with tilde expanded).
Raises:
-
ValueError : If path traversal attempt detected or extension not allowed.– -
TypeError : If path is not a string.–
Source code in odak/tools/file.py
channel_gate
¶
Bases: Module
Channel attention module with various pooling strategies. This class is heavily inspired https://github.com/Jongchan/attention-module/commit/e4ee180f1335c09db14d39a65d97c8ca3d1f7b16 (MIT License).
Source code in odak/learn/models/components.py
__init__(gate_channels, reduction_ratio=16, pool_types=['avg', 'max'])
¶
Initializes the channel gate module.
Parameters:
-
gate_channels–Number of channels of the input feature map. -
reduction_ratio(int, default:16) –Reduction ratio for the intermediate layer. -
pool_types–List of pooling operations to apply.
Source code in odak/learn/models/components.py
forward(x)
¶
Forward pass of the ChannelGate module.
Applies channel-wise attention to the input tensor.
Parameters:
-
x–Input tensor to the ChannelGate module.
Returns:
-
output(tensor) –Output tensor after applying channel attention.
Source code in odak/learn/models/components.py
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, stride=1, normalization=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. -
normalization–If True, adds a Batch Normalization layer after the convolutional layer. -
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
convolutional_block_attention
¶
Bases: Module
Convolutional Block Attention Module (CBAM) class. This class is heavily inspired https://github.com/Jongchan/attention-module/commit/e4ee180f1335c09db14d39a65d97c8ca3d1f7b16 (MIT License).
Source code in odak/learn/models/components.py
Flatten
¶
__init__(gate_channels, reduction_ratio=16, pool_types=['avg', 'max'], no_spatial=False)
¶
Initializes the convolutional block attention module.
Parameters:
-
gate_channels–Number of channels of the input feature map. -
reduction_ratio(int, default:16) –Reduction ratio for the channel attention. -
pool_types–List of pooling operations to apply for channel attention. -
no_spatial–If True, spatial attention is not applied.
Source code in odak/learn/models/components.py
forward(x)
¶
Forward pass of the convolutional block attention module.
Parameters:
-
x–Input tensor to the CBAM module.
Returns:
-
x_out(tensor) –Output tensor after applying channel and spatial attention.
Source code in odak/learn/models/components.py
double_convolution
¶
Bases: Module
A double convolution layer.
Source code in odak/learn/models/components.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
__init__(input_channels=2, mid_channels=None, output_channels=2, kernel_size=3, bias=False, normalization=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. -
normalization–If True, adds a Batch Normalization layer after the convolutional layer. -
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, normalization=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. -
normalization–If True, adds a Batch Normalization layer after the convolutional layer. -
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
global_feature_module
¶
Bases: Module
A global feature layer that processes global features from input channels and applies them to another input tensor via learned transformations.
Source code in odak/learn/models/components.py
973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 | |
__init__(input_channels, mid_channels, output_channels, kernel_size, bias=False, normalization=False, activation=torch.nn.ReLU())
¶
A global feature layer.
Parameters:
-
input_channels–Number of input channels. -
mid_channels–Number of mid channels. -
output_channels(int) –Number of output channels. -
kernel_size–Kernel size. -
bias–Set to True to let convolutional layers have bias term. -
normalization–If True, adds a Batch Normalization layer after the convolutional layer. -
activation–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
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) –Estimated output.
Source code in odak/learn/models/components.py
global_transformations
¶
Bases: Module
A global feature layer that processes global features from input channels and applies learned transformations to another input tensor.
This implementation is adapted from RSGUnet: https://github.com/MTLab/rsgunet_image_enhance.
Reference: J. Huang, P. Zhu, M. Geng et al. "Range Scaling Global U-Net for Perceptual Image Enhancement on Mobile Devices."
Source code in odak/learn/models/components.py
__init__(input_channels, output_channels)
¶
A global feature layer.
Parameters:
-
input_channels–Number of input channels. -
output_channels(int) –Number of output channels.
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) –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
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 | |
__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
positional_encoder
¶
Bases: Module
A positional encoder module.
This implementation follows this specific work: Martin-Brualla, Ricardo, Noha Radwan, Mehdi SM Sajjadi, Jonathan T. Barron, Alexey Dosovitskiy, and Daniel Duckworth. "Nerf in the wild: Neural radiance fields for unconstrained photo collections." In Proceedings of the IEEE/CVF conference on computer vision and pattern recognition, pp. 7210-7219. 2021..
Source code in odak/learn/models/components.py
__init__(L)
¶
A positional encoder module.
Parameters:
-
L–Positional encoding level.
forward(x)
¶
Forward model.
Parameters:
-
x–Input data [b x n], where `b` is batch size, `n` is the feature size.
Returns:
-
result(tensor) –Result of the forward operation.
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
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 376 377 378 379 380 381 382 383 384 | |
__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, normalization=True, 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. -
normalization–If True, adds a Batch Normalization layer after the convolutional layer. -
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.
spatial_gate
¶
Bases: Module
Spatial attention module that applies a convolution layer after channel pooling. This class is heavily inspired by https://github.com/Jongchan/attention-module/blob/master/MODELS/cbam.py.
Source code in odak/learn/models/components.py
__init__()
¶
Initializes the spatial gate module.
channel_pool(x)
¶
Applies max and average pooling on the channels.
Parameters:
-
x–Input tensor.
Returns:
-
output(tensor) –Output tensor.
Source code in odak/learn/models/components.py
forward(x)
¶
Forward pass of the SpatialGate module.
Applies spatial attention to the input tensor.
Parameters:
-
x–Input tensor to the SpatialGate module.
Returns:
-
scaled_x(tensor) –Output tensor after applying spatial attention.
Source code in odak/learn/models/components.py
spatially_adaptive_convolution
¶
Bases: Module
A spatially adaptive convolution layer.
References
C. Zheng et al. "Focal Surface Holographic Light Transport using Learned Spatially Adaptive Convolutions." C. Xu et al. "Squeezesegv3: Spatially-adaptive Convolution for Efficient Point-Cloud Segmentation." C. Zheng et al. "Windowing Decomposition Convolutional Neural Network for Image Enhancement."
Source code in odak/learn/models/components.py
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 | |
__init__(input_channels=2, output_channels=2, kernel_size=3, stride=1, padding=1, bias=False, activation=torch.nn.LeakyReLU(0.2, inplace=True))
¶
Initializes a spatially adaptive convolution layer.
Parameters:
-
input_channels–Number of input channels. -
output_channels(int, default:2) –Number of output channels. -
kernel_size–Size of the convolution kernel. -
stride–Stride of the convolution. -
padding–Padding added to both sides of the input. -
bias–If True, includes a bias term in the convolution. -
activation–Activation function to apply. If None, no activation is applied.
Source code in odak/learn/models/components.py
forward(x, sv_kernel_feature)
¶
Forward pass for the spatially adaptive convolution layer.
Parameters:
-
x–Input data tensor. Dimension: (1, C, H, W) -
sv_kernel_feature–Spatially varying kernel features. Dimension: (1, C_i * kernel_size * kernel_size, H, W)
Returns:
-
sa_output(tensor) –Estimated output tensor. Dimension: (1, output_channels, H_out, W_out)
Source code in odak/learn/models/components.py
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 | |
spatially_adaptive_module
¶
Bases: Module
A spatially adaptive module that combines learned spatially adaptive convolutions.
References
Chuanjun Zheng, Yicheng Zhan, Liang Shi, Ozan Cakmakci, and Kaan Akşit, "Focal Surface Holographic Light Transport using Learned Spatially Adaptive Convolutions," SIGGRAPH Asia 2024 Technical Communications (SA Technical Communications '24), December, 2024.
Source code in odak/learn/models/components.py
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 | |
__init__(input_channels=2, output_channels=2, kernel_size=3, stride=1, padding=1, bias=False, activation=torch.nn.LeakyReLU(0.2, inplace=True))
¶
Initializes a spatially adaptive module.
Parameters:
-
input_channels–Number of input channels. -
output_channels(int, default:2) –Number of output channels. -
kernel_size–Size of the convolution kernel. -
stride–Stride of the convolution. -
padding–Padding added to both sides of the input. -
bias–If True, includes a bias term in the convolution. -
activation–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
Source code in odak/learn/models/components.py
forward(x, sv_kernel_feature)
¶
Forward pass for the spatially adaptive module.
Parameters:
-
x–Input data tensor. Dimension: (1, C, H, W) -
sv_kernel_feature–Spatially varying kernel features. Dimension: (1, C_i * kernel_size * kernel_size, H, W)
Returns:
-
output(tensor) –Combined output tensor from standard and spatially adaptive convolutions. Dimension: (1, output_channels, H_out, W_out)
Source code in odak/learn/models/components.py
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 | |
upsample_convtranspose2d_layer
¶
Bases: Module
An upsampling convtranspose2d layer.
Source code in odak/learn/models/components.py
__init__(input_channels, output_channels, kernel_size=2, stride=2, bias=False)
¶
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.
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
upsample_layer
¶
Bases: Module
An upsampling convolutional layer.
Source code in odak/learn/models/components.py
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 | |
__init__(input_channels, output_channels, kernel_size=3, bias=False, normalization=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. -
normalization–If True, adds a Batch Normalization layer after the convolutional layer. -
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
gaussian(x, multiplier=1.0)
¶
A Gaussian non-linear activation. For more details: Ramasinghe, Sameera, and Simon Lucey. "Beyond periodicity: Towards a unifying framework for activations in coordinate-mlps." In European Conference on Computer Vision, pp. 142-158. Cham: Springer Nature Switzerland, 2022.
Parameters:
-
x–Input data. -
multiplier–Multiplier.
Returns:
-
result(float or tensor) –Ouput data.
Source code in odak/learn/models/components.py
swish(x)
¶
A swish non-linear activation. For more details: https://en.wikipedia.org/wiki/Swish_function
Parameters:
-
x–Input.
Returns:
-
out(float or tensor) –Output.
Source code in odak/learn/models/components.py
channel_gate
¶
Bases: Module
Channel attention module with various pooling strategies. This class is heavily inspired https://github.com/Jongchan/attention-module/commit/e4ee180f1335c09db14d39a65d97c8ca3d1f7b16 (MIT License).
Source code in odak/learn/models/components.py
__init__(gate_channels, reduction_ratio=16, pool_types=['avg', 'max'])
¶
Initializes the channel gate module.
Parameters:
-
gate_channels–Number of channels of the input feature map. -
reduction_ratio(int, default:16) –Reduction ratio for the intermediate layer. -
pool_types–List of pooling operations to apply.
Source code in odak/learn/models/components.py
forward(x)
¶
Forward pass of the ChannelGate module.
Applies channel-wise attention to the input tensor.
Parameters:
-
x–Input tensor to the ChannelGate module.
Returns:
-
output(tensor) –Output tensor after applying channel attention.
Source code in odak/learn/models/components.py
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, stride=1, normalization=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. -
normalization–If True, adds a Batch Normalization layer after the convolutional layer. -
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
convolutional_block_attention
¶
Bases: Module
Convolutional Block Attention Module (CBAM) class. This class is heavily inspired https://github.com/Jongchan/attention-module/commit/e4ee180f1335c09db14d39a65d97c8ca3d1f7b16 (MIT License).
Source code in odak/learn/models/components.py
Flatten
¶
__init__(gate_channels, reduction_ratio=16, pool_types=['avg', 'max'], no_spatial=False)
¶
Initializes the convolutional block attention module.
Parameters:
-
gate_channels–Number of channels of the input feature map. -
reduction_ratio(int, default:16) –Reduction ratio for the channel attention. -
pool_types–List of pooling operations to apply for channel attention. -
no_spatial–If True, spatial attention is not applied.
Source code in odak/learn/models/components.py
forward(x)
¶
Forward pass of the convolutional block attention module.
Parameters:
-
x–Input tensor to the CBAM module.
Returns:
-
x_out(tensor) –Output tensor after applying channel and spatial attention.
Source code in odak/learn/models/components.py
double_convolution
¶
Bases: Module
A double convolution layer.
Source code in odak/learn/models/components.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
__init__(input_channels=2, mid_channels=None, output_channels=2, kernel_size=3, bias=False, normalization=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. -
normalization–If True, adds a Batch Normalization layer after the convolutional layer. -
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, normalization=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. -
normalization–If True, adds a Batch Normalization layer after the convolutional layer. -
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
global_feature_module
¶
Bases: Module
A global feature layer that processes global features from input channels and applies them to another input tensor via learned transformations.
Source code in odak/learn/models/components.py
973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 | |
__init__(input_channels, mid_channels, output_channels, kernel_size, bias=False, normalization=False, activation=torch.nn.ReLU())
¶
A global feature layer.
Parameters:
-
input_channels–Number of input channels. -
mid_channels–Number of mid channels. -
output_channels(int) –Number of output channels. -
kernel_size–Kernel size. -
bias–Set to True to let convolutional layers have bias term. -
normalization–If True, adds a Batch Normalization layer after the convolutional layer. -
activation–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
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) –Estimated output.
Source code in odak/learn/models/components.py
global_transformations
¶
Bases: Module
A global feature layer that processes global features from input channels and applies learned transformations to another input tensor.
This implementation is adapted from RSGUnet: https://github.com/MTLab/rsgunet_image_enhance.
Reference: J. Huang, P. Zhu, M. Geng et al. "Range Scaling Global U-Net for Perceptual Image Enhancement on Mobile Devices."
Source code in odak/learn/models/components.py
__init__(input_channels, output_channels)
¶
A global feature layer.
Parameters:
-
input_channels–Number of input channels. -
output_channels(int) –Number of output channels.
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) –Estimated output.
Source code in odak/learn/models/components.py
multi_layer_perceptron
¶
Bases: Module
A multi-layer perceptron model.
Source code in odak/learn/models/models.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
__init__(dimensions, activation=torch.nn.ReLU(), bias=False, model_type='conventional', siren_multiplier=1.0, input_multiplier=None)
¶
Initialize the multi-layer perceptron.
Parameters:
-
dimensions(list of int) –List of integers representing the dimensions of each layer (e.g., [2, 10, 1], where the first layer has two channels and last one has one channel).
-
activation(Module, default:ReLU()) –Nonlinear activation function. Default is
torch.nn.ReLU(). -
bias(bool, default:False) –If set to True, linear layers will include biases. Default is False.
-
siren_multiplier(float, default:1.0) –When using
SIRENmodel type, this parameter functions as a hyperparameter. The original SIREN work uses 30. You can bypass this parameter by providing input that are not normalized and larger than one. Default is 1.0. -
input_multiplier(float, default:None) –Initial value of the input multiplier before the very first layer.
-
model_type(str, default:'conventional') –Model type:
conventional,swish,SIREN,FILM SIREN,Gaussian.conventionalrefers to a standard multi layer perceptron. ForSIREN, see: Sitzmann, Vincent, et al. "Implicit neural representations with periodic activation functions." Advances in neural information processing systems 33 (2020): 7462-7473. ForSwish, see: Ramachandran, Prajit, Barret Zoph, and Quoc V. Le. "Searching for activation functions." arXiv preprint arXiv:1710.05941 (2017). ForFILM SIREN, see: Chan, Eric R., et al. "pi-gan: Periodic implicit generative adversarial networks for 3d-aware image synthesis." Proceedings of the IEEE/CVF conference on computer vision and pattern recognition. 2021. ForGaussian, see: Ramasinghe, Sameera, and Simon Lucey. "Beyond periodicity: Towards a unifying framework for activations in coordinate-mlps." In European Conference on Computer Vision, pp. 142-158. Cham: Springer Nature Switzerland, 2022. Default is "conventional".
Source code in odak/learn/models/models.py
forward(x)
¶
Forward pass of the multi-layer perceptron.
Parameters:
-
x(Tensor) –Input data.
Returns:
-
result(Tensor) –Estimated output.
Source code in odak/learn/models/models.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
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 | |
__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
positional_encoder
¶
Bases: Module
A positional encoder module.
This implementation follows this specific work: Martin-Brualla, Ricardo, Noha Radwan, Mehdi SM Sajjadi, Jonathan T. Barron, Alexey Dosovitskiy, and Daniel Duckworth. "Nerf in the wild: Neural radiance fields for unconstrained photo collections." In Proceedings of the IEEE/CVF conference on computer vision and pattern recognition, pp. 7210-7219. 2021..
Source code in odak/learn/models/components.py
__init__(L)
¶
A positional encoder module.
Parameters:
-
L–Positional encoding level.
forward(x)
¶
Forward model.
Parameters:
-
x–Input data [b x n], where `b` is batch size, `n` is the feature size.
Returns:
-
result(tensor) –Result of the forward operation.
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
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 376 377 378 379 380 381 382 383 384 | |
__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, normalization=True, 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. -
normalization–If True, adds a Batch Normalization layer after the convolutional layer. -
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.
spatial_gate
¶
Bases: Module
Spatial attention module that applies a convolution layer after channel pooling. This class is heavily inspired by https://github.com/Jongchan/attention-module/blob/master/MODELS/cbam.py.
Source code in odak/learn/models/components.py
__init__()
¶
Initializes the spatial gate module.
channel_pool(x)
¶
Applies max and average pooling on the channels.
Parameters:
-
x–Input tensor.
Returns:
-
output(tensor) –Output tensor.
Source code in odak/learn/models/components.py
forward(x)
¶
Forward pass of the SpatialGate module.
Applies spatial attention to the input tensor.
Parameters:
-
x–Input tensor to the SpatialGate module.
Returns:
-
scaled_x(tensor) –Output tensor after applying spatial attention.
Source code in odak/learn/models/components.py
spatially_adaptive_convolution
¶
Bases: Module
A spatially adaptive convolution layer.
References
C. Zheng et al. "Focal Surface Holographic Light Transport using Learned Spatially Adaptive Convolutions." C. Xu et al. "Squeezesegv3: Spatially-adaptive Convolution for Efficient Point-Cloud Segmentation." C. Zheng et al. "Windowing Decomposition Convolutional Neural Network for Image Enhancement."
Source code in odak/learn/models/components.py
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 | |
__init__(input_channels=2, output_channels=2, kernel_size=3, stride=1, padding=1, bias=False, activation=torch.nn.LeakyReLU(0.2, inplace=True))
¶
Initializes a spatially adaptive convolution layer.
Parameters:
-
input_channels–Number of input channels. -
output_channels(int, default:2) –Number of output channels. -
kernel_size–Size of the convolution kernel. -
stride–Stride of the convolution. -
padding–Padding added to both sides of the input. -
bias–If True, includes a bias term in the convolution. -
activation–Activation function to apply. If None, no activation is applied.
Source code in odak/learn/models/components.py
forward(x, sv_kernel_feature)
¶
Forward pass for the spatially adaptive convolution layer.
Parameters:
-
x–Input data tensor. Dimension: (1, C, H, W) -
sv_kernel_feature–Spatially varying kernel features. Dimension: (1, C_i * kernel_size * kernel_size, H, W)
Returns:
-
sa_output(tensor) –Estimated output tensor. Dimension: (1, output_channels, H_out, W_out)
Source code in odak/learn/models/components.py
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 | |
spatially_adaptive_module
¶
Bases: Module
A spatially adaptive module that combines learned spatially adaptive convolutions.
References
Chuanjun Zheng, Yicheng Zhan, Liang Shi, Ozan Cakmakci, and Kaan Akşit, "Focal Surface Holographic Light Transport using Learned Spatially Adaptive Convolutions," SIGGRAPH Asia 2024 Technical Communications (SA Technical Communications '24), December, 2024.
Source code in odak/learn/models/components.py
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 | |
__init__(input_channels=2, output_channels=2, kernel_size=3, stride=1, padding=1, bias=False, activation=torch.nn.LeakyReLU(0.2, inplace=True))
¶
Initializes a spatially adaptive module.
Parameters:
-
input_channels–Number of input channels. -
output_channels(int, default:2) –Number of output channels. -
kernel_size–Size of the convolution kernel. -
stride–Stride of the convolution. -
padding–Padding added to both sides of the input. -
bias–If True, includes a bias term in the convolution. -
activation–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
Source code in odak/learn/models/components.py
forward(x, sv_kernel_feature)
¶
Forward pass for the spatially adaptive module.
Parameters:
-
x–Input data tensor. Dimension: (1, C, H, W) -
sv_kernel_feature–Spatially varying kernel features. Dimension: (1, C_i * kernel_size * kernel_size, H, W)
Returns:
-
output(tensor) –Combined output tensor from standard and spatially adaptive convolutions. Dimension: (1, output_channels, H_out, W_out)
Source code in odak/learn/models/components.py
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 | |
spatially_adaptive_unet
¶
Bases: Module
Spatially varying U-Net model based on spatially adaptive convolution.
References
Chuanjun Zheng, Yicheng Zhan, Liang Shi, Ozan Cakmakci, and Kaan Akşit, "Focal Surface Holographic Light Transport using Learned Spatially Adaptive Convolutions," SIGGRAPH Asia 2024 Technical Communications (SA Technical Communications '24), December, 2024.
Source code in odak/learn/models/models.py
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 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 | |
__init__(depth=3, dimensions=8, input_channels=6, out_channels=6, kernel_size=3, bias=True, normalization=False, activation=torch.nn.LeakyReLU(0.2, inplace=True))
¶
Initialize the spatially adaptive U-Net model.
Parameters:
-
depth(int, default:3) –Number of upsampling and downsampling layers. Default is 3.
-
dimensions(int, default:8) –Number of dimensions. Default is 8.
-
input_channels(int, default:6) –Number of input channels. Default is 6.
-
out_channels(int, default:6) –Number of output channels. Default is 6.
-
kernel_size(int, default:3) –Kernel size for convolutional layers. Default is 3.
-
bias(bool, default:True) –Set to True to let convolutional layers learn a bias term. Default is True.
-
normalization(bool, default:False) –If True, adds a Batch Normalization layer after the convolutional layer. Default is False.
-
activation(Module, default:LeakyReLU(0.2, inplace=True)) –Non-linear activation layer (e.g., torch.nn.ReLU(), torch.nn.Sigmoid()). Default is torch.nn.LeakyReLU(0.2, inplace=True).
Source code in odak/learn/models/models.py
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 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 | |
forward(sv_kernel, field)
¶
Forward pass of the spatially adaptive U-Net.
Parameters:
-
sv_kernel(list of torch.Tensor) –Learned spatially varying kernels. Dimension of each element in the list: (1, C_i * kernel_size * kernel_size, H_i, W_i), where C_i, H_i, and W_i represent the channel, height, and width of each feature at a certain scale.
-
field(Tensor) –Input field data. Dimension: (1, 6, H, W)
Returns:
-
target_field(Tensor) –Estimated output. Dimension: (1, 6, H, W)
Source code in odak/learn/models/models.py
spatially_varying_kernel_generation_model
¶
Bases: Module
Spatially_varying_kernel_generation_model revised from RSGUnet: https://github.com/MTLab/rsgunet_image_enhance.
Refer to: J. Huang, P. Zhu, M. Geng et al. Range Scaling Global U-Net for Perceptual Image Enhancement on Mobile Devices.
Source code in odak/learn/models/models.py
231 232 233 234 235 236 237 238 239 240 241 242 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 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 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
__init__(depth=3, dimensions=8, input_channels=7, kernel_size=3, bias=True, normalization=False, activation=torch.nn.LeakyReLU(0.2, inplace=True))
¶
Initialize the spatially varying kernel generation model.
Parameters:
-
depth(int, default:3) –Number of upsampling and downsampling layers. Default is 3.
-
dimensions(int, default:8) –Number of dimensions. Default is 8.
-
input_channels(int, default:7) –Number of input channels. Default is 7.
-
kernel_size(int, default:3) –Kernel size for convolutional layers. Default is 3.
-
bias(bool, default:True) –Set to True to let convolutional layers learn a bias term. Default is True.
-
normalization(bool, default:False) –If True, adds a Batch Normalization layer after the convolutional layer. Default is False.
-
activation(Module, default:LeakyReLU(0.2, inplace=True)) –Non-linear activation layer (e.g., torch.nn.ReLU(), torch.nn.Sigmoid()). Default is torch.nn.LeakyReLU(0.2, inplace=True).
Source code in odak/learn/models/models.py
240 241 242 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 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 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
forward(focal_surface, field)
¶
Forward pass of the spatially varying kernel generation model.
Parameters:
-
focal_surface(Tensor) –Input focal surface data. Dimension: (1, 1, H, W)
-
field(Tensor) –Input field data. Dimension: (1, 6, H, W)
Returns:
-
sv_kernel(list of torch.Tensor) –Learned spatially varying kernels. Dimension of each element in the list: (1, C_i * kernel_size * kernel_size, H_i, W_i), where C_i, H_i, and W_i represent the channel, height, and width of each feature at a certain scale.
Source code in odak/learn/models/models.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
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
__init__(depth=4, dimensions=64, input_channels=2, output_channels=1, bilinear=False, kernel_size=3, bias=False, activation=torch.nn.ReLU(inplace=True))
¶
Initialize the U-Net model.
Parameters:
-
depth(int, default:4) –Number of upsampling and downsampling layers. Default is 4.
-
dimensions(int, default:64) –Number of dimensions. Default is 64.
-
input_channels(int, default:2) –Number of input channels. Default is 2.
-
output_channels(int, default:1) –Number of output channels. Default is 1.
-
bilinear(bool, default:False) –Uses bilinear upsampling in upsampling layers when set True. Default is False.
-
kernel_size(int, default:3) –Kernel size for convolutional layers. Default is 3.
-
bias(bool, default:False) –Set True to let convolutional layers learn a bias term. Default is False.
-
activation(Module, default:ReLU(inplace=True)) –Non-linear activation layer to be used (e.g., torch.nn.ReLU(), torch.nn.Sigmoid()). Default is torch.nn.ReLU(inplace=True).
Source code in odak/learn/models/models.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
forward(x)
¶
Forward pass of the U-Net.
Parameters:
-
x(Tensor) –Input data.
Returns:
-
result(Tensor) –Estimated output.
Source code in odak/learn/models/models.py
upsample_convtranspose2d_layer
¶
Bases: Module
An upsampling convtranspose2d layer.
Source code in odak/learn/models/components.py
__init__(input_channels, output_channels, kernel_size=2, stride=2, bias=False)
¶
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.
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
upsample_layer
¶
Bases: Module
An upsampling convolutional layer.
Source code in odak/learn/models/components.py
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 | |
__init__(input_channels, output_channels, kernel_size=3, bias=False, normalization=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. -
normalization–If True, adds a Batch Normalization layer after the convolutional layer. -
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
gaussian(x, multiplier=1.0)
¶
A Gaussian non-linear activation. For more details: Ramasinghe, Sameera, and Simon Lucey. "Beyond periodicity: Towards a unifying framework for activations in coordinate-mlps." In European Conference on Computer Vision, pp. 142-158. Cham: Springer Nature Switzerland, 2022.
Parameters:
-
x–Input data. -
multiplier–Multiplier.
Returns:
-
result(float or tensor) –Ouput data.
Source code in odak/learn/models/components.py
swish(x)
¶
A swish non-linear activation. For more details: https://en.wikipedia.org/wiki/Swish_function
Parameters:
-
x–Input.
Returns:
-
out(float or tensor) –Output.