odak.learn.wave
angular_spectrum(field, k, distance, dx, wavelength, zero_padding=False, aperture=1.0)
¶
A definition to calculate convolution with Angular Spectrum method for beam propagation.
Parameters:
-
field
–Complex field [m x n].
-
k
–Wave number of a wave, see odak.wave.wavenumber for more.
-
distance
–Propagation distance.
-
dx
–Size of one single pixel in the field grid (in meters).
-
wavelength
–Wavelength of the electric field.
-
zero_padding
–Zero pad in Fourier domain.
-
aperture
–Fourier domain aperture (e.g., pinhole in a typical holographic display). The default is one, but an aperture could be as large as input field [m x n].
Returns:
-
result
(complex
) –Final complex field (MxN).
Source code in odak/learn/wave/classical.py
band_limited_angular_spectrum(field, k, distance, dx, wavelength, zero_padding=False, aperture=1.0)
¶
A definition to calculate bandlimited angular spectrum based beam propagation. For more
Matsushima, Kyoji, and Tomoyoshi Shimobaba. "Band-limited angular spectrum method for numerical simulation of free-space propagation in far and near fields." Optics express 17.22 (2009): 19662-19673
.
Parameters:
-
field
–A complex field. The expected size is [m x n].
-
k
–Wave number of a wave, see odak.wave.wavenumber for more.
-
distance
–Propagation distance.
-
dx
–Size of one single pixel in the field grid (in meters).
-
wavelength
–Wavelength of the electric field.
-
zero_padding
–Zero pad in Fourier domain.
-
aperture
–Fourier domain aperture (e.g., pinhole in a typical holographic display). The default is one, but an aperture could be as large as input field [m x n].
Returns:
-
result
(complex
) –Final complex field [m x n].
Source code in odak/learn/wave/classical.py
custom(field, kernel, zero_padding=False, aperture=1.0)
¶
A definition to calculate convolution based Fresnel approximation for beam propagation.
Parameters:
-
field
–Complex field [m x n].
-
kernel
–Custom complex kernel for beam propagation.
-
zero_padding
–Zero pad in Fourier domain.
-
aperture
–Fourier domain aperture (e.g., pinhole in a typical holographic display). The default is one, but an aperture could be as large as input field [m x n].
Returns:
-
result
(complex
) –Final complex field (MxN).
Source code in odak/learn/wave/classical.py
fraunhofer(field, k, distance, dx, wavelength)
¶
A definition to calculate light transport usin Fraunhofer approximation.
Parameters:
-
field
–Complex field (MxN).
-
k
–Wave number of a wave, see odak.wave.wavenumber for more.
-
distance
–Propagation distance.
-
dx
–Size of one single pixel in the field grid (in meters).
-
wavelength
–Wavelength of the electric field.
Returns:
-
result
(complex
) –Final complex field (MxN).
Source code in odak/learn/wave/classical.py
gerchberg_saxton(field, n_iterations, distance, dx, wavelength, slm_range=6.28, propagation_type='Transfer Function Fresnel')
¶
Definition to compute a hologram using an iterative method called Gerchberg-Saxton phase retrieval algorithm. For more on the method, see: Gerchberg, Ralph W. "A practical algorithm for the determination of phase from image and diffraction plane pictures." Optik 35 (1972): 237-246.
Parameters:
-
field
–Complex field (MxN).
-
distance
–Propagation distance.
-
dx
–Size of one single pixel in the field grid (in meters).
-
wavelength
–Wavelength of the electric field.
-
slm_range
–Typically this is equal to two pi. See odak.wave.adjust_phase_only_slm_range() for more.
-
propagation_type
(str
, default:'Transfer Function Fresnel'
) –Type of the propagation (see odak.learn.wave.propagate_beam).
Returns:
-
hologram
(cfloat
) –Calculated complex hologram.
-
reconstruction
(cfloat
) –Calculated reconstruction using calculated hologram.
Source code in odak/learn/wave/classical.py
get_angular_spectrum_kernel(nu, nv, dx=8e-06, wavelength=5.15e-07, distance=0.0, device=torch.device('cpu'))
¶
Helper function for odak.learn.wave.angular_spectrum.
Parameters:
-
nu
–Resolution at X axis in pixels.
-
nv
–Resolution at Y axis in pixels.
-
dx
–Pixel pitch in meters.
-
wavelength
–Wavelength in meters.
-
distance
–Distance in meters.
-
device
–Device, for more see torch.device().
Returns:
-
H
(float
) –Complex kernel in Fourier domain.
Source code in odak/learn/wave/classical.py
get_band_limited_angular_spectrum_kernel(nu, nv, dx=8e-06, wavelength=5.15e-07, distance=0.0, device=torch.device('cpu'))
¶
Helper function for odak.learn.wave.band_limited_angular_spectrum.
Parameters:
-
nu
–Resolution at X axis in pixels.
-
nv
–Resolution at Y axis in pixels.
-
dx
–Pixel pitch in meters.
-
wavelength
–Wavelength in meters.
-
distance
–Distance in meters.
-
device
–Device, for more see torch.device().
Returns:
-
H
(complex64
) –Complex kernel in Fourier domain.
Source code in odak/learn/wave/classical.py
get_impulse_response_fresnel_kernel(nu, nv, dx=8e-06, wavelength=5.15e-07, distance=0.0, device=torch.device('cpu'), scale=1, aperture_samples=[20, 20, 5, 5])
¶
Helper function for odak.learn.wave.impulse_response_fresnel.
Parameters:
-
nu
–Resolution at X axis in pixels.
-
nv
–Resolution at Y axis in pixels.
-
dx
–Pixel pitch in meters.
-
wavelength
–Wavelength in meters.
-
distance
–Distance in meters.
-
device
–Device, for more see torch.device().
-
scale
–Scale with respect to nu and nv (e.g., scale = 2 leads to 2 x nu and 2 x nv resolution for H).
-
aperture_samples
–Number of samples to represent a rectangular pixel. First two is for XY of hologram plane pixels, and second two is for image plane pixels.
Returns:
-
H
(complex64
) –Complex kernel in Fourier domain.
Source code in odak/learn/wave/classical.py
get_incoherent_angular_spectrum_kernel(nu, nv, dx=8e-06, wavelength=5.15e-07, distance=0.0, device=torch.device('cpu'))
¶
Helper function for odak.learn.wave.angular_spectrum.
Parameters:
-
nu
–Resolution at X axis in pixels.
-
nv
–Resolution at Y axis in pixels.
-
dx
–Pixel pitch in meters.
-
wavelength
–Wavelength in meters.
-
distance
–Distance in meters.
-
device
–Device, for more see torch.device().
Returns:
-
H
(float
) –Complex kernel in Fourier domain.
Source code in odak/learn/wave/classical.py
get_light_kernels(wavelengths, distances, pixel_pitches, resolution=[1080, 1920], resolution_factor=1, samples=[50, 50, 5, 5], propagation_type='Bandlimited Angular Spectrum', kernel_type='spatial', device=torch.device('cpu'))
¶
Utility function to request a tensor filled with light transport kernels according to the given optical configurations.
Parameters:
-
wavelengths
–A list of wavelengths.
-
distances
–A list of propagation distances.
-
pixel_pitches
–A list of pixel_pitches.
-
resolution
–Resolution of the light transport kernel.
-
resolution_factor
–If `Impulse Response Fresnel` propagation is used, this resolution factor could be set larger than one leading to higher resolution light transport kernels than the provided native `resolution`. For more, see odak.learn.wave.get_impulse_response_kernel().
-
samples
–If `Impulse Response Fresnel` propagation is used, these sample counts will be used to calculate the light transport kernel. For more, see odak.learn.wave.get_impulse_response_kernel().
-
propagation_type
–Propagation type. For more, see odak.learn.wave.propagate_beam().
-
kernel_type
–If set to `spatial`, light transport kernels will be provided in space. But if set to `fourier`, these kernels will be provided in the Fourier domain.
-
device
–Device used for computation (i.e., cpu, cuda).
Returns:
-
light_kernels_amplitude
(tensor
) –Amplitudes of the light kernels generated [w x d x p x m x n].
-
light_kernels_phase
(tensor
) –Phases of the light kernels generated [w x d x p x m x n].
-
light_kernels_complex
(tensor
) –Complex light kernels generated [w x d x p x m x n].
-
light_parameters
(tensor
) –Parameters of each pixel in light_kernels* [w x d x p x m x n x 5]. Last dimension contains, wavelengths, distances, pixel pitches, X and Y locations in order.
Source code in odak/learn/wave/classical.py
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 |
|
get_point_wise_impulse_response_fresnel_kernel(aperture_points, aperture_field, target_points, resolution, resolution_factor=1, wavelength=5.15e-07, distance=0.0, randomization=False, device=torch.device('cpu'))
¶
This function is a freeform point spread function calculation routine for an aperture defined with a complex field, aperture_field
, and locations in space, aperture_points
.
The point spread function is calculated over provided points, target_points
.
The final result is reshaped to follow the provided resolution
.
Parameters:
-
aperture_points
–Points representing an aperture in Euler space (XYZ) [m x 3].
-
aperture_field
–Complex field for each point provided by `aperture_points` [1 x m].
-
target_points
–Target points where the propagated field will be calculated [n x 1].
-
resolution
–Final resolution that the propagated field will be reshaped [X x Y].
-
resolution_factor
–Scale with respect to `resolution` (e.g., scale = 2 leads to `2 x resolution` for the final complex field.
-
wavelength
–Wavelength in meters.
-
randomization
–If set `True`, this will help generate a noisy response roughly approximating a real life case, where imperfections occur.
-
distance
–Distance in meters.
Returns:
-
h
(float
) –Complex field in spatial domain.
Source code in odak/learn/wave/classical.py
get_propagation_kernel(nu, nv, dx=8e-06, wavelength=5.15e-07, distance=0.0, device=torch.device('cpu'), propagation_type='Bandlimited Angular Spectrum', scale=1, samples=[20, 20, 5, 5])
¶
Get propagation kernel for the propagation type.
Parameters:
-
nu
–Resolution at X axis in pixels.
-
nv
–Resolution at Y axis in pixels.
-
dx
–Pixel pitch in meters.
-
wavelength
–Wavelength in meters.
-
distance
–Distance in meters.
-
device
–Device, for more see torch.device().
-
propagation_type
–Propagation type. The options are `Angular Spectrum`, `Bandlimited Angular Spectrum` and `Transfer Function Fresnel`.
-
scale
–Scale factor for scaled beam propagation.
-
samples
–When using `Impulse Response Fresnel` propagation, these sample counts along X and Y will be used to represent a rectangular aperture. First two is for a hologram pixel and second two is for an image plane pixel.
Returns:
-
kernel
(tensor
) –Complex kernel for the given propagation type.
Source code in odak/learn/wave/classical.py
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 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 |
|
get_seperable_impulse_response_fresnel_kernel(nu, nv, dx=3.74e-06, wavelength=5.15e-07, distance=0.0, scale=1, aperture_samples=[50, 50, 5, 5], device=torch.device('cpu'))
¶
Returns impulse response fresnel kernel in separable form.
Parameters:
-
nu
–Resolution at X axis in pixels.
-
nv
–Resolution at Y axis in pixels.
-
dx
–Pixel pitch in meters.
-
wavelength
–Wavelength in meters.
-
distance
–Distance in meters.
-
device
–Device, for more see torch.device().
-
scale
–Scale with respect to nu and nv (e.g., scale = 2 leads to 2 x nu and 2 x nv resolution for H).
-
aperture_samples
–Number of samples to represent a rectangular pixel. First two is for XY of hologram plane pixels, and second two is for image plane pixels.
Returns:
-
H
(complex64
) –Complex kernel in Fourier domain.
-
h
(complex64
) –Complex kernel in spatial domain.
-
h_x
(complex64
) –1D complex kernel in spatial domain along X axis.
-
h_y
(complex64
) –1D complex kernel in spatial domain along Y axis.
Source code in odak/learn/wave/classical.py
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 |
|
get_transfer_function_fresnel_kernel(nu, nv, dx=8e-06, wavelength=5.15e-07, distance=0.0, device=torch.device('cpu'))
¶
Helper function for odak.learn.wave.transfer_function_fresnel.
Parameters:
-
nu
–Resolution at X axis in pixels.
-
nv
–Resolution at Y axis in pixels.
-
dx
–Pixel pitch in meters.
-
wavelength
–Wavelength in meters.
-
distance
–Distance in meters.
-
device
–Device, for more see torch.device().
Returns:
-
H
(complex64
) –Complex kernel in Fourier domain.
Source code in odak/learn/wave/classical.py
impulse_response_fresnel(field, k, distance, dx, wavelength, zero_padding=False, aperture=1.0, scale=1, samples=[20, 20, 5, 5])
¶
A definition to calculate convolution based Fresnel approximation for beam propagation.
Parameters:
-
field
–Complex field (MxN).
-
k
–Wave number of a wave, see odak.wave.wavenumber for more.
-
distance
–Propagation distance.
-
dx
–Size of one single pixel in the field grid (in meters).
-
wavelength
–Wavelength of the electric field.
-
zero_padding
–Zero pad in Fourier domain.
-
aperture
–Fourier domain aperture (e.g., pinhole in a typical holographic display). The default is one, but an aperture could be as large as input field [m x n].
-
scale
–Resolution factor to scale generated kernel.
-
samples
–When using `Impulse Response Fresnel` propagation, these sample counts along X and Y will be used to represent a rectangular aperture. First two is for hologram plane pixel and the last two is for image plane pixel.
Returns:
-
result
(complex
) –Final complex field (MxN).
Source code in odak/learn/wave/classical.py
incoherent_angular_spectrum(field, k, distance, dx, wavelength, zero_padding=False, aperture=1.0)
¶
A definition to calculate incoherent beam propagation with Angular Spectrum method.
Parameters:
-
field
–Complex field [m x n].
-
k
–Wave number of a wave, see odak.wave.wavenumber for more.
-
distance
–Propagation distance.
-
dx
–Size of one single pixel in the field grid (in meters).
-
wavelength
–Wavelength of the electric field.
-
zero_padding
–Zero pad in Fourier domain.
-
aperture
–Fourier domain aperture (e.g., pinhole in a typical holographic display). The default is one, but an aperture could be as large as input field [m x n].
Returns:
-
result
(complex
) –Final complex field [m x n].
Source code in odak/learn/wave/classical.py
point_wise(target, wavelength, distance, dx, device, lens_size=401)
¶
Naive point-wise hologram calculation method. For more information, refer to Maimone, Andrew, Andreas Georgiou, and Joel S. Kollin. "Holographic near-eye displays for virtual and augmented reality." ACM Transactions on Graphics (TOG) 36.4 (2017): 1-16.
Parameters:
-
target
–float input target to be converted into a hologram (Target should be in range of 0 and 1).
-
wavelength
–Wavelength of the electric field.
-
distance
–Propagation distance.
-
dx
–Size of one single pixel in the field grid (in meters).
-
device
–Device type (cuda or cpu)`.
-
lens_size
–Size of lens for masking sub holograms(in pixels).
Returns:
-
hologram
(cfloat
) –Calculated complex hologram.
Source code in odak/learn/wave/classical.py
propagate_beam(field, k, distance, dx, wavelength, propagation_type='Bandlimited Angular Spectrum', kernel=None, zero_padding=[True, False, True], aperture=1.0, scale=1, samples=[20, 20, 5, 5])
¶
Definitions for various beam propagation methods mostly in accordence with "Computational Fourier Optics" by David Vuelz.
Parameters:
-
field
–Complex field [m x n].
-
k
–Wave number of a wave, see odak.wave.wavenumber for more.
-
distance
–Propagation distance.
-
dx
–Size of one single pixel in the field grid (in meters).
-
wavelength
–Wavelength of the electric field.
-
propagation_type
(str
, default:'Bandlimited Angular Spectrum'
) –Type of the propagation. The options are Impulse Response Fresnel, Transfer Function Fresnel, Angular Spectrum, Bandlimited Angular Spectrum, Fraunhofer.
-
kernel
–Custom complex kernel.
-
zero_padding
–Zero padding the input field if the first item in the list set True. Zero padding in the Fourier domain if the second item in the list set to True. Cropping the result with half resolution if the third item in the list is set to true. Note that in Fraunhofer propagation, setting the second item True or False will have no effect.
-
aperture
–Aperture at Fourier domain default:[2m x 2n], otherwise depends on `zero_padding`. If provided as a floating point 1, there will be no aperture in Fourier domain.
-
scale
–Resolution factor to scale generated kernel.
-
samples
–When using `Impulse Response Fresnel` propagation, these sample counts along X and Y will be used to represent a rectangular aperture. First two is for a hologram pixel and second two is for an image plane pixel.
Returns:
-
result
(complex
) –Final complex field [m x n].
Source code in odak/learn/wave/classical.py
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 |
|
seperable_impulse_response_fresnel(field, k, distance, dx, wavelength, zero_padding=False, aperture=1.0, scale=1, samples=[20, 20, 5, 5])
¶
A definition to calculate convolution based Fresnel approximation for beam propagation for a rectangular aperture using the seperable property.
Parameters:
-
field
–Complex field (MxN).
-
k
–Wave number of a wave, see odak.wave.wavenumber for more.
-
distance
–Propagation distance.
-
dx
–Size of one single pixel in the field grid (in meters).
-
wavelength
–Wavelength of the electric field.
-
zero_padding
–Zero pad in Fourier domain.
-
aperture
–Fourier domain aperture (e.g., pinhole in a typical holographic display). The default is one, but an aperture could be as large as input field [m x n].
-
scale
–Resolution factor to scale generated kernel.
-
samples
–When using `Impulse Response Fresnel` propagation, these sample counts along X and Y will be used to represent a rectangular aperture. First two is for hologram plane pixel and the last two is for image plane pixel.
Returns:
-
result
(complex
) –Final complex field (MxN).
Source code in odak/learn/wave/classical.py
shift_w_double_phase(phase, depth_shift, pixel_pitch, wavelength, propagation_type='Transfer Function Fresnel', kernel_length=4, sigma=0.5, amplitude=None)
¶
Shift a phase-only hologram by propagating the complex hologram and double phase principle. Coded following in here and Shi, L., Li, B., Kim, C., Kellnhofer, P., & Matusik, W. (2021). Towards real-time photorealistic 3D holography with deep neural networks. Nature, 591(7849), 234-239.
Parameters:
-
phase
–Phase value of a phase-only hologram.
-
depth_shift
–Distance in meters.
-
pixel_pitch
–Pixel pitch size in meters.
-
wavelength
–Wavelength of light.
-
propagation_type
(str
, default:'Transfer Function Fresnel'
) –Beam propagation type. For more see odak.learn.wave.propagate_beam().
-
kernel_length
–Kernel length for the Gaussian blur kernel.
-
sigma
–Standard deviation for the Gaussian blur kernel.
-
amplitude
–Amplitude value of a complex hologram.
Source code in odak/learn/wave/classical.py
1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 |
|
stochastic_gradient_descent(target, wavelength, distance, pixel_pitch, propagation_type='Bandlimited Angular Spectrum', n_iteration=100, loss_function=None, learning_rate=0.1)
¶
Definition to generate phase and reconstruction from target image via stochastic gradient descent.
Parameters:
-
target
–Target field amplitude [m x n]. Keep the target values between zero and one.
-
wavelength
–Set if the converted array requires gradient.
-
distance
–Hologram plane distance wrt SLM plane.
-
pixel_pitch
–SLM pixel pitch in meters.
-
propagation_type
–Type of the propagation (see odak.learn.wave.propagate_beam()).
-
n_iteration
–Number of iteration.
-
loss_function
–If none it is set to be l2 loss.
-
learning_rate
–Learning rate.
Returns:
-
hologram
(Tensor
) –Phase only hologram as torch array
-
reconstruction_intensity
(Tensor
) –Reconstruction as torch array
Source code in odak/learn/wave/classical.py
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 |
|
transfer_function_fresnel(field, k, distance, dx, wavelength, zero_padding=False, aperture=1.0)
¶
A definition to calculate convolution based Fresnel approximation for beam propagation.
Parameters:
-
field
–Complex field (MxN).
-
k
–Wave number of a wave, see odak.wave.wavenumber for more.
-
distance
–Propagation distance.
-
dx
–Size of one single pixel in the field grid (in meters).
-
wavelength
–Wavelength of the electric field.
-
zero_padding
–Zero pad in Fourier domain.
-
aperture
–Fourier domain aperture (e.g., pinhole in a typical holographic display). The default is one, but an aperture could be as large as input field [m x n].
Returns:
-
result
(complex
) –Final complex field (MxN).
Source code in odak/learn/wave/classical.py
blazed_grating(nx, ny, levels=2, axis='x')
¶
A defininition to generate a blazed grating (also known as ramp grating). For more consult de Blas, Mario García, et al. "High resolution 2D beam steerer made from cascaded 1D liquid crystal phase gratings." Scientific Reports 12.1 (2022): 5145 and Igasaki, Yasunori, et al. "High efficiency electrically-addressable phase-only spatial light modulator." optical review 6 (1999): 339-344.
Parameters:
-
nx
–Size of the output along X.
-
ny
–Size of the output along Y.
-
levels
–Number of pixels.
-
axis
–Axis of glazed grating. It could be `x` or `y`.
Source code in odak/learn/wave/lens.py
linear_grating(nx, ny, every=2, add=None, axis='x')
¶
A definition to generate a linear grating. This could also be interpreted as two levels blazed grating. For more on blazed gratings see odak.learn.wave.blazed_grating() function.
Parameters:
-
nx
–Size of the output along X.
-
ny
–Size of the output along Y.
-
every
–Add the add value at every given number.
-
add
–Angle to be added.
-
axis
–Axis eiter X,Y or both.
Returns:
-
field
(tensor
) –Linear grating term.
Source code in odak/learn/wave/lens.py
prism_grating(nx, ny, k, angle, dx=0.001, axis='x', phase_offset=0.0)
¶
A definition to generate 2D phase function that represents a prism. See Goodman's Introduction to Fourier Optics book or Engström, David, et al. "Improved beam steering accuracy of a single beam with a 1D phase-only spatial light modulator." Optics express 16.22 (2008): 18275-18287. for more.
Parameters:
-
nx
–Size of the output along X.
-
ny
–Size of the output along Y.
-
k
–See odak.wave.wavenumber for more.
-
angle
–Tilt angle of the prism in degrees.
-
dx
–Pixel pitch.
-
axis
–Axis of the prism.
-
phase_offset
(float
, default:0.0
) –Phase offset in angles. Default is zero.
Returns:
-
prism
(tensor
) –Generated phase function for a prism.
Source code in odak/learn/wave/lens.py
quadratic_phase_function(nx, ny, k, focal=0.4, dx=0.001, offset=[0, 0])
¶
A definition to generate 2D quadratic phase function, which is typically use to represent lenses.
Parameters:
-
nx
–Size of the output along X.
-
ny
–Size of the output along Y.
-
k
–See odak.wave.wavenumber for more.
-
focal
–Focal length of the quadratic phase function.
-
dx
–Pixel pitch.
-
offset
–Deviation from the center along X and Y axes.
Returns:
-
qpf
(tensor
) –Generated quadratic phase function.
Source code in odak/learn/wave/lens.py
multiplane_loss
¶
Loss function for computing loss in multiplanar images. Unlike, previous methods, this loss function accounts for defocused parts of an image.
Source code in odak/learn/wave/loss.py
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 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 |
|
__call__(image, target, plane_id=None, inject_noise=False, noise_ratio=0.001)
¶
Calculates the multiplane loss against a given target.
Parameters:
-
image
–Image to compare with a target [3 x m x n].
-
target
–Target image for comparison [3 x m x n].
-
plane_id
–Number of the plane under test.
-
inject_noise
–When True, noise is added on the targets at the given `noise_ratio`.
-
noise_ratio
–Noise ratio.
Returns:
-
loss
(tensor
) –Computed loss.
Source code in odak/learn/wave/loss.py
__init__(target_image, target_depth, blur_ratio=0.25, target_blur_size=10, number_of_planes=4, weights=[1.0, 2.1, 0.6], multiplier=1.0, scheme='defocus', reduction='mean', device=torch.device('cpu'))
¶
Parameters:
-
target_image
–Color target image [3 x m x n].
-
target_depth
–Monochrome target depth, same resolution as target_image.
-
target_blur_size
–Maximum target blur size.
-
blur_ratio
–Blur ratio, a value between zero and one.
-
number_of_planes
–Number of planes.
-
weights
–Weights of the loss function.
-
multiplier
–Multiplier to multipy with targets.
-
scheme
–The type of the loss, `naive` without defocus or `defocus` with defocus.
-
reduction
–Reduction can either be 'mean', 'none' or 'sum'. For more see: https://pytorch.org/docs/stable/generated/torch.nn.MSELoss.html#torch.nn.MSELoss
-
device
–Device to be used (e.g., cuda, cpu, opencl).
Source code in odak/learn/wave/loss.py
add_defocus_blur()
¶
Internal function for adding defocus blur to the multiplane targets. Users can query the results with get_targets() within the same class.
Source code in odak/learn/wave/loss.py
get_targets()
¶
Returns:
-
targets
(tensor
) –Returns a copy of the targets.
-
target_depth
(tensor
) –Returns a copy of the normalized quantized depth map.
Source code in odak/learn/wave/loss.py
set_targets()
¶
Internal function for slicing the depth into planes without considering defocus. Users can query the results with get_targets() within the same class.
Source code in odak/learn/wave/loss.py
perceptual_multiplane_loss
¶
Perceptual loss function for computing loss in multiplanar images. Unlike, previous methods, this loss function accounts for defocused parts of an image.
Source code in odak/learn/wave/loss.py
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 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 |
|
__call__(image, target, plane_id=None, inject_noise=False, noise_ratio=0.001)
¶
Calculates the multiplane loss against a given target.
Parameters:
-
image
–Image to compare with a target [3 x m x n].
-
target
–Target image for comparison [3 x m x n].
-
plane_id
–Number of the plane under test.
-
inject_noise
–When True, noise is added on the targets at the given `noise_ratio`.
-
noise_ratio
–Noise ratio.
Returns:
-
loss
(tensor
) –Computed loss.
Source code in odak/learn/wave/loss.py
__init__(target_image, target_depth, blur_ratio=0.25, target_blur_size=10, number_of_planes=4, multiplier=1.0, scheme='defocus', base_loss_weights={'base_l2_loss': 1.0, 'loss_l2_mask': 1.0, 'loss_l2_cor': 1.0, 'base_l1_loss': 1.0, 'loss_l1_mask': 1.0, 'loss_l1_cor': 1.0}, additional_loss_weights={'cvvdp': 1.0}, reduction='mean', return_components=False, device=torch.device('cpu'))
¶
Parameters:
-
target_image
–Color target image [3 x m x n].
-
target_depth
–Monochrome target depth, same resolution as target_image.
-
target_blur_size
–Maximum target blur size.
-
blur_ratio
–Blur ratio, a value between zero and one.
-
number_of_planes
–Number of planes.
-
multiplier
–Multiplier to multipy with targets.
-
scheme
–The type of the loss, `naive` without defocus or `defocus` with defocus.
-
base_loss_weights
–Weights of the base loss functions. Default is {'base_l2_loss': 1., 'loss_l2_mask': 1., 'loss_l2_cor': 1., 'base_l1_loss': 1., 'loss_l1_mask': 1., 'loss_l1_cor': 1.}.
-
additional_loss_weights
(dict
, default:{'cvvdp': 1.0}
) –Additional loss terms and their weights (e.g., {'cvvdp': 1.}). Supported loss terms are 'cvvdp', 'fvvdp', 'lpips', 'psnr', 'ssim', 'msssim'.
-
reduction
–Reduction can either be 'mean', 'none' or 'sum'. For more see: https://pytorch.org/docs/stable/generated/torch.nn.MSELoss.html#torch.nn.MSELoss
-
return_components
–If True (False by default), returns the components of the loss as a dict.
-
device
–Device to be used (e.g., cuda, cpu, opencl).
Source code in odak/learn/wave/loss.py
add_defocus_blur()
¶
Internal function for adding defocus blur to the multiplane targets. Users can query the results with get_targets() within the same class.
Source code in odak/learn/wave/loss.py
get_targets()
¶
Returns:
-
targets
(tensor
) –Returns a copy of the targets.
-
target_depth
(tensor
) –Returns a copy of the normalized quantized depth map.
Source code in odak/learn/wave/loss.py
set_targets()
¶
Internal function for slicing the depth into planes without considering defocus. Users can query the results with get_targets() within the same class.
Source code in odak/learn/wave/loss.py
phase_gradient
¶
Bases: Module
The class 'phase_gradient' provides a regularization function to measure the variation(Gradient or Laplace) of the phase of the complex amplitude.
This implements a convolution of the phase with a kernel.
The kernel is a simple 3 by 3 Laplacian kernel here, but you can also try other edge detection methods.
Source code in odak/learn/wave/loss.py
__init__(kernel=None, loss=nn.MSELoss(), device=torch.device('cpu'))
¶
Parameters:
-
kernel
–Convolution filter kernel, 3 by 3 Laplacian kernel by default.
-
loss
–loss function, L2 Loss by default.
Source code in odak/learn/wave/loss.py
forward(phase)
¶
Calculates the phase gradient Loss.
Parameters:
-
phase
–Phase of the complex amplitude.
Returns:
-
loss_value
(tensor
) –The computed loss.
Source code in odak/learn/wave/loss.py
functional_conv2d(phase)
¶
Calculates the gradient of the phase.
Parameters:
-
phase
–Phase of the complex amplitude.
Returns:
-
edge_detect
(tensor
) –The computed phase gradient.
Source code in odak/learn/wave/loss.py
speckle_contrast
¶
Bases: Module
The class 'speckle_contrast' provides a regularization function to measure the speckle contrast of the intensity of the complex amplitude using C=sigma/mean. Where C is the speckle contrast, mean and sigma are mean and standard deviation of the intensity.
We refer to the following paper:
Kim et al.(2020). Light source optimization for partially coherent holographic displays with consideration of speckle contrast, resolution, and depth of field. Scientific Reports. 10. 18832. 10.1038/s41598-020-75947-0.
Source code in odak/learn/wave/loss.py
__init__(kernel_size=11, step_size=(1, 1), loss=nn.MSELoss(), device=torch.device('cpu'))
¶
Parameters:
-
kernel_size
–Convolution filter kernel size, 11 by 11 average kernel by default.
-
step_size
–Convolution stride in height and width direction.
-
loss
–loss function, L2 Loss by default.
Source code in odak/learn/wave/loss.py
forward(intensity)
¶
Calculates the speckle contrast Loss.
Parameters:
-
intensity
–intensity of the complex amplitude.
Returns:
-
loss_value
(tensor
) –The computed loss.
Source code in odak/learn/wave/loss.py
functional_conv2d(intensity)
¶
Calculates the speckle contrast of the intensity.
Parameters:
-
intensity
–Intensity of the complex field.
Returns:
-
Speckle_C
(tensor
) –The computed speckle contrast.
Source code in odak/learn/wave/loss.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
focal_surface_light_propagation
¶
Bases: Module
focal_surface_light_propagation model.
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/wave/models.py
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 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 |
|
__init__(depth=3, dimensions=8, input_channels=6, out_channels=6, kernel_size=3, bias=True, device=torch.device('cpu'), activation=torch.nn.LeakyReLU(0.2, inplace=True))
¶
Initializes the focal surface light propagation model.
Parameters:
-
depth
–Number of downsampling and upsampling layers.
-
dimensions
–Number of dimensions/features in the model.
-
input_channels
–Number of input channels.
-
out_channels
–Number of output channels.
-
kernel_size
–Size of the convolution kernel.
-
bias
–If True, allows convolutional layers to learn a bias term.
-
device
–Default device is CPU.
-
activation
–Activation function (e.g., torch.nn.ReLU(), torch.nn.Sigmoid()).
Source code in odak/learn/wave/models.py
forward(focal_surface, phase_only_hologram)
¶
Forward pass through the model.
Parameters:
-
focal_surface
–Input focal surface.
-
phase_only_hologram
–Input phase-only hologram.
Returns:
-
result
(Tensor
) –Output tensor after light propagation.
Source code in odak/learn/wave/models.py
generate_input_field(phase_only_hologram)
¶
Generates an input field by combining the real and imaginary parts.
Parameters:
-
phase_only_hologram
–Input phase-only hologram.
Returns:
-
input_field
(Tensor
) –Concatenated real and imaginary parts of the complex field.
Source code in odak/learn/wave/models.py
load_weights(weight_filename, key_mapping_filename)
¶
Function to load weights for this multi-layer perceptron from a file.
Parameters:
-
weight_filename
–Path to the old model's weight file.
-
key_mapping_filename
(str
) –Path to the JSON file containing the key mappings.
Source code in odak/learn/wave/models.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
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 1034 1035 1036 1037 1038 1039 1040 1041 |
|
__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
holobeam_multiholo
¶
Bases: Module
The learned holography model used in the paper, Akşit, Kaan, and Yuta Itoh. "HoloBeam: Paper-Thin Near-Eye Displays." In 2023 IEEE Conference Virtual Reality and 3D User Interfaces (VR), pp. 581-591. IEEE, 2023.
Parameters:
-
n_input
–Number of channels in the input.
-
n_hidden
–Number of channels in the hidden layers.
-
n_output
–Number of channels in the output layer.
-
device
–Default device is CPU.
-
reduction
–Reduction used for torch.nn.MSELoss and torch.nn.L1Loss. The default is 'sum'.
Source code in odak/learn/wave/models.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 |
|
evaluate(input_data, ground_truth, weights=[1.0, 0.1])
¶
Internal function for evaluating.
fit(dataloader, number_of_epochs=100, learning_rate=1e-05, directory='./output', save_at_every=100)
¶
Function to train the weights of the multi layer perceptron.
Parameters:
-
dataloader
–Data loader.
-
number_of_epochs
(int
, default:100
) –Number of epochs.
-
learning_rate
–Learning rate of the optimizer.
-
directory
–Output directory.
-
save_at_every
–Save the model at every given epoch count.
Source code in odak/learn/wave/models.py
forward(x, test=False)
¶
Internal function representing the forward model.
Source code in odak/learn/wave/models.py
load_weights(filename='./weights.pt')
¶
Function to load weights for this multi layer perceptron from a file.
Parameters:
-
filename
–Filename.
Source code in odak/learn/wave/models.py
save_weights(filename='./weights.pt')
¶
Function to save the current weights of the multi layer perceptron to a file.
Parameters:
-
filename
–Filename.
Source code in odak/learn/wave/models.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.
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
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 1157 1158 1159 1160 1161 1162 1163 1164 |
|
__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
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 |
|
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
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 1290 1291 1292 1293 1294 1295 1296 1297 |
|
__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
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 |
|
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
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 |
|
__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
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 |
|
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
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 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 |
|
__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
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 |
|
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
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 |
|
__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
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 |
|
__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
multi_color_hologram_optimizer
¶
A class for optimizing single or multi color holograms. For more details, see Kavaklı et al., SIGGRAPH ASIA 2023, Multi-color Holograms Improve Brightness in HOlographic Displays.
Source code in odak/learn/wave/optimizers.py
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 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 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 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 |
|
direct_phase_constrain(phase, phase_offset)
¶
Internal function to constrain a given phase.
Parameters:
-
phase
–Input phase values to be constrained.
-
phase_offset
–Input phase offset value.
Returns:
-
phase_only
(tensor
) –Constrained output phase.
Source code in odak/learn/wave/optimizers.py
double_phase_constrain(phase, phase_offset)
¶
Internal function to constrain a given phase similarly to double phase encoding.
Parameters:
-
phase
–Input phase values to be constrained.
-
phase_offset
–Input phase offset value.
Returns:
-
phase_only
(tensor
) –Constrained output phase.
Source code in odak/learn/wave/optimizers.py
evaluate(input_image, target_image, plane_id=0, noise_ratio=0.001, inject_noise=False)
¶
Internal function to evaluate the loss.
Source code in odak/learn/wave/optimizers.py
gradient_descent(number_of_iterations=100, weights=[1.0, 1.0, 0.0, 0.0], inject_noise=False, noise_ratio=0.001)
¶
Function to optimize multiplane phase-only holograms using stochastic gradient descent.
Parameters:
-
number_of_iterations
–Number of iterations.
-
weights
–Weights used in the loss function.
-
inject_noise
–When set True, this will inject noise with the given `noise_ratio` to the target images.
-
noise_ratio
–Noise ratio, a multiplier (1e-3 is 0.1 percent).
Returns:
-
hologram
(tensor
) –Optimised hologram.
Source code in odak/learn/wave/optimizers.py
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 |
|
init_amplitude()
¶
Internal function to set the amplitude of the illumination source.
Source code in odak/learn/wave/optimizers.py
init_channel_power()
¶
Internal function to set the starting phase of the phase-only hologram.
Source code in odak/learn/wave/optimizers.py
init_loss_function(loss_function, reduction='sum')
¶
Internal function to set the loss function.
Source code in odak/learn/wave/optimizers.py
init_optimizer()
¶
Internal function to set the optimizer.
Source code in odak/learn/wave/optimizers.py
init_peak_amplitude_scale()
¶
init_phase()
¶
Internal function to set the starting phase of the phase-only hologram.
Source code in odak/learn/wave/optimizers.py
init_phase_scale()
¶
Internal function to set the phase scale.
Source code in odak/learn/wave/optimizers.py
optimize(number_of_iterations=100, weights=[1.0, 1.0, 1.0], bits=8, inject_noise=False, noise_ratio=0.001)
¶
Function to optimize multiplane phase-only holograms.
Parameters:
-
number_of_iterations
–Number of iterations.
-
weights
–Loss weights.
-
bits
–Quantizes the hologram using the given bits and reconstructs.
-
inject_noise
–When set True, this will inject noise with the given `noise_ratio` to the target images.
-
noise_ratio
–Noise ratio, a multiplier (1e-3 is 0.1 percent).
Returns:
-
hologram_phases
(tensor
) –Phases of the optimized phase-only hologram.
-
reconstruction_intensities
(tensor
) –Intensities of the images reconstructed at each plane with the optimized phase-only hologram.
Source code in odak/learn/wave/optimizers.py
propagator
¶
A light propagation model that propagates light to desired image plane with two separate propagations.
We use this class in our various works including Kavaklı et al., Realistic Defocus Blur for Multiplane Computer-Generated Holography
.
Source code in odak/learn/wave/propagators.py
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 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 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 |
|
__call__(input_field, channel_id, depth_id)
¶
Function that represents the forward model in hologram optimization.
Parameters:
-
input_field
–Input complex input field.
-
channel_id
–Identifying the color primary to be used.
-
depth_id
–Identifying the depth layer to be used.
Returns:
-
output_field
(tensor
) –Propagated output complex field.
Source code in odak/learn/wave/propagators.py
__init__(resolution=[1920, 1080], wavelengths=[5.15e-07], pixel_pitch=8e-06, resolution_factor=1, number_of_frames=1, number_of_depth_layers=1, volume_depth=0.01, image_location_offset=0.005, propagation_type='Bandlimited Angular Spectrum', propagator_type='back and forth', back_and_forth_distance=0.3, laser_channel_power=None, aperture=None, aperture_size=None, distances=None, aperture_samples=[20, 20, 5, 5], method='conventional', device=torch.device('cpu'))
¶
Parameters:
-
resolution
–Resolution.
-
wavelengths
–Wavelength of light in meters.
-
pixel_pitch
–Pixel pitch in meters.
-
resolution_factor
–Resolution factor for scaled simulations.
-
number_of_frames
–Number of hologram frames. Typically, there are three frames, each one for a single color primary.
-
number_of_depth_layers
–Equ-distance number of depth layers within the desired volume. If `distances` parameter is passed, this value will be automatically set to the length of the `distances` verson provided.
-
volume_depth
–Width of the volume along the propagation direction.
-
image_location_offset
–Center of the volume along the propagation direction.
-
propagation_type
–Propagation type. See ropagate_beam() and odak.learn.wave.get_propagation_kernel() for more.
-
propagator_type
–Propagator type. The options are `back and forth` and `forward` propagators.
-
back_and_forth_distance
(float
, default:0.3
) –Zero mode distance for `back and forth` propagator type.
-
laser_channel_power
–Laser channel powers for given number of frames and number of wavelengths.
-
aperture
–Aperture at the Fourier plane.
-
aperture_size
–Aperture width for a circular aperture.
-
aperture_samples
–When using `Impulse Response Fresnel` propagation, these sample counts along X and Y will be used to represent a rectangular aperture. First two is for hologram plane pixel and the last two is for image plane pixel.
-
distances
–Propagation distances in meters.
-
method
–Hologram type conventional or multi-color.
-
device
–Device to be used for computation. For more see torch.device().
Source code in odak/learn/wave/propagators.py
get_kernels()
¶
Function to return the kernels used in the light transport.
Returns:
-
kernels
(tensor
) –Kernel amplitudes.
Source code in odak/learn/wave/propagators.py
get_laser_powers()
¶
Internal function to get the laser powers.
Returns:
-
laser_power
(tensor
) –Laser powers.
Source code in odak/learn/wave/propagators.py
init_channel_power(channel_power)
¶
Internal function to set the starting phase of the phase-only hologram.
Source code in odak/learn/wave/propagators.py
init_distances(distances)
¶
Internal function to initialize distances.
Parameters:
-
distances
–Propagation distances.
Source code in odak/learn/wave/propagators.py
init_kernels()
¶
Internal function to initialize kernels.
Source code in odak/learn/wave/propagators.py
init_phase_scale()
¶
Internal function to set the phase scale. In some cases, you may want to modify this init to ratio phases for different color primaries as an SLM is configured for a specific central wavelength.
Source code in odak/learn/wave/propagators.py
reconstruct(hologram_phases, amplitude=None, no_grad=True, get_complex=False)
¶
Internal function to reconstruct a given hologram.
Parameters:
-
hologram_phases
–Hologram phases [ch x m x n].
-
amplitude
–Amplitude profiles for each color primary [ch x m x n]
-
no_grad
–If set True, uses torch.no_grad in reconstruction.
-
get_complex
–If set True, reconstructor returns the complex field but not the intensities.
Returns:
-
reconstructions
(tensor
) –Reconstructed frames.
Source code in odak/learn/wave/propagators.py
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 |
|
set_aperture(aperture=None, aperture_size=None)
¶
Set aperture in the Fourier plane.
Parameters:
-
aperture
–Aperture at the original resolution of a hologram. If aperture is provided as None, it will assign a circular aperture at the size of the short edge (width or height).
-
aperture_size
–If no aperture is provided, this will determine the size of the circular aperture.
Source code in odak/learn/wave/propagators.py
set_laser_powers(laser_power)
¶
Internal function to set the laser powers.
Parameters:
-
laser_power
–Laser powers.
calculate_amplitude(field)
¶
Definition to calculate amplitude of a single or multiple given electric field(s).
Parameters:
-
field
–Electric fields or an electric field.
Returns:
-
amplitude
(float
) –Amplitude or amplitudes of electric field(s).
Source code in odak/learn/wave/util.py
calculate_phase(field, deg=False)
¶
Definition to calculate phase of a single or multiple given electric field(s).
Parameters:
-
field
–Electric fields or an electric field.
-
deg
–If set True, the angles will be returned in degrees.
Returns:
-
phase
(float
) –Phase or phases of electric field(s) in radians.
Source code in odak/learn/wave/util.py
generate_complex_field(amplitude, phase)
¶
Definition to generate a complex field with a given amplitude and phase.
Parameters:
-
amplitude
–Amplitude of the field. The expected size is [m x n] or [1 x m x n].
-
phase
–Phase of the field. The expected size is [m x n] or [1 x m x n].
Returns:
-
field
(ndarray
) –Complex field. Depending on the input, the expected size is [m x n] or [1 x m x n].
Source code in odak/learn/wave/util.py
set_amplitude(field, amplitude)
¶
Definition to keep phase as is and change the amplitude of a given field.
Parameters:
-
field
–Complex field.
-
amplitude
–Amplitudes.
Returns:
-
new_field
(cfloat
) –Complex field.
Source code in odak/learn/wave/util.py
wavenumber(wavelength)
¶
Definition for calculating the wavenumber of a plane wave.
Parameters:
-
wavelength
–Wavelength of a wave in mm.
Returns:
-
k
(float
) –Wave number for a given wavelength.