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=True, 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
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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|
__init__(input_channels=2, mid_channels=None, output_channels=2, kernel_size=3, bias=False, normalization=True, 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, activation=torch.nn.ReLU())
¶
A downscaling component with a double convolution.
Parameters:
-
input_channels
–Number of input channels.
-
output_channels
(int
) –Number of output channels.
-
kernel_size
–Kernel size.
-
bias
–Set to True to let convolutional layers have bias term.
-
activation
–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
Source code in odak/learn/models/components.py
forward(x)
¶
Forward model.
Parameters:
-
x
–First input data.
Returns:
-
result
(tensor
) –Estimated output.
Source code in odak/learn/models/components.py
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
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 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 |
|
__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
__init__(dimensions, activation=torch.nn.ReLU(), bias=False, model_type='conventional', siren_multiplier=1.0, input_multiplier=None)
¶
Parameters:
-
dimensions
–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
–Nonlinear activation function. Default is `torch.nn.ReLU()`.
-
bias
–If set to True, linear layers will include biases.
-
siren_multiplier
–When using `SIREN` model 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 then one.
-
input_multiplier
–Initial value of the input multiplier before the very first layer.
-
model_type
–Model type: `conventional`, `swish`, `SIREN`, `FILM SIREN`, `Gaussian`. `conventional` refers to a standard multi layer perceptron. For `SIREN,` see: Sitzmann, Vincent, et al. "Implicit neural representations with periodic activation functions." Advances in neural information processing systems 33 (2020): 7462-7473. For `Swish,` see: Ramachandran, Prajit, Barret Zoph, and Quoc V. Le. "Searching for activation functions." arXiv preprint arXiv:1710.05941 (2017). For `FILM 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. For `Gaussian,` 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.
Source code in odak/learn/models/models.py
forward(x)
¶
Forward model.
Parameters:
-
x
–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
__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.
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.
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
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 |
|
__init__(input_channels=2, output_channels=2, kernel_size=1, bias=False, activation=torch.nn.ReLU())
¶
An attention layer class.
Parameters:
-
input_channels
–Number of input channels.
-
output_channels
(int or optional
, default:2
) –Number of middle channels.
-
kernel_size
–Kernel size.
-
bias
–Set to True to let convolutional layers have bias term.
-
activation
–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
Source code in odak/learn/models/components.py
forward(x0, x1)
¶
Forward model.
Parameters:
-
x0
–First input data.
-
x1
–Seconnd input data.
Returns:
-
result
(tensor
) –Estimated output.
Source code in odak/learn/models/components.py
residual_layer
¶
Bases: Module
A residual layer.
Source code in odak/learn/models/components.py
__init__(input_channels=2, mid_channels=16, kernel_size=3, bias=False, activation=torch.nn.ReLU())
¶
A convolutional layer class.
Parameters:
-
input_channels
–Number of input channels.
-
mid_channels
–Number of middle channels.
-
kernel_size
–Kernel size.
-
bias
–Set to True to let convolutional layers have bias term.
-
activation
–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
Source code in odak/learn/models/components.py
forward(x)
¶
Forward model.
Parameters:
-
x
–Input data.
Returns:
-
result
(tensor
) –Estimated output.
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
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 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 |
|
__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
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 |
|
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
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 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 |
|
__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
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 |
|
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
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 |
|
__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))
¶
U-Net model.
Parameters:
-
depth
–Number of upsampling and downsampling layers.
-
dimensions
–Number of dimensions.
-
input_channels
(int
, default:6
) –Number of input channels.
-
out_channels
–Number of output channels.
-
bias
–Set to True to let convolutional layers learn a bias term.
-
normalization
–If True, adds a Batch Normalization layer after the convolutional layer.
-
activation
–Non-linear activation layer (e.g., torch.nn.ReLU(), torch.nn.Sigmoid()).
Source code in odak/learn/models/models.py
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 |
|
forward(sv_kernel, field)
¶
Forward model.
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
–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
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 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 |
|
__init__(depth=3, dimensions=8, input_channels=7, kernel_size=3, bias=True, normalization=False, activation=torch.nn.LeakyReLU(0.2, inplace=True))
¶
U-Net model.
Parameters:
-
depth
–Number of upsampling and downsampling layers.
-
dimensions
–Number of dimensions.
-
input_channels
(int
, default:7
) –Number of input channels.
-
bias
–Set to True to let convolutional layers learn a bias term.
-
normalization
–If True, adds a Batch Normalization layer after the convolutional layer.
-
activation
–Non-linear activation layer (e.g., torch.nn.ReLU(), torch.nn.Sigmoid()).
Source code in odak/learn/models/models.py
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 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 |
|
forward(focal_surface, field)
¶
Forward model.
Parameters:
-
focal_surface
(tensor
) –Input focal surface data. Dimension: (1, 1, H, W)
-
field
–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
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 |
|
__init__(depth=4, dimensions=64, input_channels=2, output_channels=1, bilinear=False, kernel_size=3, bias=False, activation=torch.nn.ReLU(inplace=True))
¶
U-Net model.
Parameters:
-
depth
–Number of upsampling and downsampling
-
dimensions
–Number of dimensions.
-
input_channels
–Number of input channels.
-
output_channels
–Number of output channels.
-
bilinear
–Uses bilinear upsampling in upsampling layers when set True.
-
bias
–Set True to let convolutional layers learn a bias term.
-
activation
–Non-linear activation layer to be used (e.g., torch.nn.ReLU(), torch.nn.Sigmoid().
Source code in odak/learn/models/models.py
forward(x)
¶
Forward model.
Parameters:
-
x
–Input data.
Returns:
-
result
(tensor
) –Estimated output.
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
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 |
|
__init__(input_channels, output_channels, kernel_size=3, bias=False, activation=torch.nn.ReLU(), bilinear=True)
¶
A downscaling component with a double convolution.
Parameters:
-
input_channels
–Number of input channels.
-
output_channels
(int
) –Number of output channels.
-
kernel_size
–Kernel size.
-
bias
–Set to True to let convolutional layers have bias term.
-
activation
–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
-
bilinear
–If set to True, bilinear sampling is used.
Source code in odak/learn/models/components.py
forward(x1, x2)
¶
Forward model.
Parameters:
-
x1
–First input data.
-
x2
–Second input data.
Returns:
-
result
(tensor
) –Result of the forward operation
Source code in odak/learn/models/components.py
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=True, 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
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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|
__init__(input_channels=2, mid_channels=None, output_channels=2, kernel_size=3, bias=False, normalization=True, 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, activation=torch.nn.ReLU())
¶
A downscaling component with a double convolution.
Parameters:
-
input_channels
–Number of input channels.
-
output_channels
(int
) –Number of output channels.
-
kernel_size
–Kernel size.
-
bias
–Set to True to let convolutional layers have bias term.
-
activation
–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
Source code in odak/learn/models/components.py
forward(x)
¶
Forward model.
Parameters:
-
x
–First input data.
Returns:
-
result
(tensor
) –Estimated output.
Source code in odak/learn/models/components.py
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
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 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 |
|
__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
__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.
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.
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
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 |
|
__init__(input_channels=2, output_channels=2, kernel_size=1, bias=False, activation=torch.nn.ReLU())
¶
An attention layer class.
Parameters:
-
input_channels
–Number of input channels.
-
output_channels
(int or optional
, default:2
) –Number of middle channels.
-
kernel_size
–Kernel size.
-
bias
–Set to True to let convolutional layers have bias term.
-
activation
–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
Source code in odak/learn/models/components.py
forward(x0, x1)
¶
Forward model.
Parameters:
-
x0
–First input data.
-
x1
–Seconnd input data.
Returns:
-
result
(tensor
) –Estimated output.
Source code in odak/learn/models/components.py
residual_layer
¶
Bases: Module
A residual layer.
Source code in odak/learn/models/components.py
__init__(input_channels=2, mid_channels=16, kernel_size=3, bias=False, activation=torch.nn.ReLU())
¶
A convolutional layer class.
Parameters:
-
input_channels
–Number of input channels.
-
mid_channels
–Number of middle channels.
-
kernel_size
–Kernel size.
-
bias
–Set to True to let convolutional layers have bias term.
-
activation
–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
Source code in odak/learn/models/components.py
forward(x)
¶
Forward model.
Parameters:
-
x
–Input data.
Returns:
-
result
(tensor
) –Estimated output.
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
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 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 |
|
__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
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 |
|
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
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 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 |
|
__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
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 |
|
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
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 |
|
__init__(input_channels, output_channels, kernel_size=3, bias=False, activation=torch.nn.ReLU(), bilinear=True)
¶
A downscaling component with a double convolution.
Parameters:
-
input_channels
–Number of input channels.
-
output_channels
(int
) –Number of output channels.
-
kernel_size
–Kernel size.
-
bias
–Set to True to let convolutional layers have bias term.
-
activation
–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
-
bilinear
–If set to True, bilinear sampling is used.
Source code in odak/learn/models/components.py
forward(x1, x2)
¶
Forward model.
Parameters:
-
x1
–First input data.
-
x2
–Second input data.
Returns:
-
result
(tensor
) –Result of the forward operation
Source code in odak/learn/models/components.py
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=True, 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
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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|
__init__(input_channels=2, mid_channels=None, output_channels=2, kernel_size=3, bias=False, normalization=True, 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, activation=torch.nn.ReLU())
¶
A downscaling component with a double convolution.
Parameters:
-
input_channels
–Number of input channels.
-
output_channels
(int
) –Number of output channels.
-
kernel_size
–Kernel size.
-
bias
–Set to True to let convolutional layers have bias term.
-
activation
–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
Source code in odak/learn/models/components.py
forward(x)
¶
Forward model.
Parameters:
-
x
–First input data.
Returns:
-
result
(tensor
) –Estimated output.
Source code in odak/learn/models/components.py
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
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 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 |
|
__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
__init__(dimensions, activation=torch.nn.ReLU(), bias=False, model_type='conventional', siren_multiplier=1.0, input_multiplier=None)
¶
Parameters:
-
dimensions
–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
–Nonlinear activation function. Default is `torch.nn.ReLU()`.
-
bias
–If set to True, linear layers will include biases.
-
siren_multiplier
–When using `SIREN` model 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 then one.
-
input_multiplier
–Initial value of the input multiplier before the very first layer.
-
model_type
–Model type: `conventional`, `swish`, `SIREN`, `FILM SIREN`, `Gaussian`. `conventional` refers to a standard multi layer perceptron. For `SIREN,` see: Sitzmann, Vincent, et al. "Implicit neural representations with periodic activation functions." Advances in neural information processing systems 33 (2020): 7462-7473. For `Swish,` see: Ramachandran, Prajit, Barret Zoph, and Quoc V. Le. "Searching for activation functions." arXiv preprint arXiv:1710.05941 (2017). For `FILM 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. For `Gaussian,` 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.
Source code in odak/learn/models/models.py
forward(x)
¶
Forward model.
Parameters:
-
x
–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
__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.
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.
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
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 |
|
__init__(input_channels=2, output_channels=2, kernel_size=1, bias=False, activation=torch.nn.ReLU())
¶
An attention layer class.
Parameters:
-
input_channels
–Number of input channels.
-
output_channels
(int or optional
, default:2
) –Number of middle channels.
-
kernel_size
–Kernel size.
-
bias
–Set to True to let convolutional layers have bias term.
-
activation
–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
Source code in odak/learn/models/components.py
forward(x0, x1)
¶
Forward model.
Parameters:
-
x0
–First input data.
-
x1
–Seconnd input data.
Returns:
-
result
(tensor
) –Estimated output.
Source code in odak/learn/models/components.py
residual_layer
¶
Bases: Module
A residual layer.
Source code in odak/learn/models/components.py
__init__(input_channels=2, mid_channels=16, kernel_size=3, bias=False, activation=torch.nn.ReLU())
¶
A convolutional layer class.
Parameters:
-
input_channels
–Number of input channels.
-
mid_channels
–Number of middle channels.
-
kernel_size
–Kernel size.
-
bias
–Set to True to let convolutional layers have bias term.
-
activation
–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
Source code in odak/learn/models/components.py
forward(x)
¶
Forward model.
Parameters:
-
x
–Input data.
Returns:
-
result
(tensor
) –Estimated output.
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
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 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 |
|
__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
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 |
|
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
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 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 |
|
__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
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 |
|
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
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 |
|
__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))
¶
U-Net model.
Parameters:
-
depth
–Number of upsampling and downsampling layers.
-
dimensions
–Number of dimensions.
-
input_channels
(int
, default:6
) –Number of input channels.
-
out_channels
–Number of output channels.
-
bias
–Set to True to let convolutional layers learn a bias term.
-
normalization
–If True, adds a Batch Normalization layer after the convolutional layer.
-
activation
–Non-linear activation layer (e.g., torch.nn.ReLU(), torch.nn.Sigmoid()).
Source code in odak/learn/models/models.py
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 |
|
forward(sv_kernel, field)
¶
Forward model.
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
–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
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 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 |
|
__init__(depth=3, dimensions=8, input_channels=7, kernel_size=3, bias=True, normalization=False, activation=torch.nn.LeakyReLU(0.2, inplace=True))
¶
U-Net model.
Parameters:
-
depth
–Number of upsampling and downsampling layers.
-
dimensions
–Number of dimensions.
-
input_channels
(int
, default:7
) –Number of input channels.
-
bias
–Set to True to let convolutional layers learn a bias term.
-
normalization
–If True, adds a Batch Normalization layer after the convolutional layer.
-
activation
–Non-linear activation layer (e.g., torch.nn.ReLU(), torch.nn.Sigmoid()).
Source code in odak/learn/models/models.py
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 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 |
|
forward(focal_surface, field)
¶
Forward model.
Parameters:
-
focal_surface
(tensor
) –Input focal surface data. Dimension: (1, 1, H, W)
-
field
–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
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 |
|
__init__(depth=4, dimensions=64, input_channels=2, output_channels=1, bilinear=False, kernel_size=3, bias=False, activation=torch.nn.ReLU(inplace=True))
¶
U-Net model.
Parameters:
-
depth
–Number of upsampling and downsampling
-
dimensions
–Number of dimensions.
-
input_channels
–Number of input channels.
-
output_channels
–Number of output channels.
-
bilinear
–Uses bilinear upsampling in upsampling layers when set True.
-
bias
–Set True to let convolutional layers learn a bias term.
-
activation
–Non-linear activation layer to be used (e.g., torch.nn.ReLU(), torch.nn.Sigmoid().
Source code in odak/learn/models/models.py
forward(x)
¶
Forward model.
Parameters:
-
x
–Input data.
Returns:
-
result
(tensor
) –Estimated output.
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
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 |
|
__init__(input_channels, output_channels, kernel_size=3, bias=False, activation=torch.nn.ReLU(), bilinear=True)
¶
A downscaling component with a double convolution.
Parameters:
-
input_channels
–Number of input channels.
-
output_channels
(int
) –Number of output channels.
-
kernel_size
–Kernel size.
-
bias
–Set to True to let convolutional layers have bias term.
-
activation
–Nonlinear activation layer to be used. If None, uses torch.nn.ReLU().
-
bilinear
–If set to True, bilinear sampling is used.
Source code in odak/learn/models/components.py
forward(x1, x2)
¶
Forward model.
Parameters:
-
x1
–First input data.
-
x2
–Second input data.
Returns:
-
result
(tensor
) –Result of the forward operation
Source code in odak/learn/models/components.py
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.