Skip to content

Commit

Permalink
Merge pull request #113 from PolarizedLightFieldMicroscopy/mbl_2024
Browse files Browse the repository at this point in the history
Azimuth orientation counterclockwise
  • Loading branch information
gschlafly authored Oct 10, 2024
2 parents 4db3910 + 039760b commit f5f850a
Show file tree
Hide file tree
Showing 40 changed files with 1,123 additions and 1,198 deletions.
82 changes: 62 additions & 20 deletions config/iter_config.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,64 @@
{
"num_iterations": 100,
"regularization_weight": 0.1,
"lr": 1e-3,
"lr_birefringence": 1e-3,
"lr_optic_axis": 1e-1,
"optimizer": "Nadam",
"datafidelity": "euler",
"regularization_fcns": [
["birefringence active L2", 0],
["birefringence active negative penalty", 0],
["birefringence mask", 1000]
],
"nerf_mode": false,
"from_simulation": true,
"mla_rays_at_once": true,
"two_optic_axis_components": true,
"free_memory_by_del_large_arrays": false,
"save_freq": 50,
"output_posfix": "",
"notes": ""
"general": {
"num_iterations": 1000,
"save_freq": 100,
"output_directory_postfix": "",
"notes": ""
},
"learning_rates": {
"birefringence": 1e-4,
"optic_axis": 1e-1
},
"regularization": {
"weight": 1.0,
"functions": [
["birefringence active L2", 100],
["birefringence active negative penalty", 0]
]
},
"file_paths": {
"initial_volume": null,
"saved_rays": null,
"vox_indices_by_mla_idx": null,
"ret_image": null,
"azim_image": null,
"radiometry": null
},
"schedulers": {
"birefringence": {
"type": "ReduceLROnPlateau",
"params": {
"mode": "min",
"factor": 0.8,
"patience": 5,
"threshold": 1e-6,
"min_lr": 1e-8
}
},
"optic_axis": {
"type": "CosineAnnealingWarmRestarts",
"params": {
"T_0": 20,
"T_mult": 2,
"eta_min": 1e-4
}
}
},
"visualization": {
"plot_live": true,
"fig_size": [10, 11]
},
"learnables": {
"all_prop_elements": false,
"two_optic_axis_components": true
},
"misc": {
"from_simulation": true,
"save_ray_geometry": true,
"optimizer": "Nadam",
"datafidelity": "euler",
"warmup_iterations": 10,
"mla_rays_at_once": true,
"free_memory_by_del_large_arrays": false
}
}
26 changes: 0 additions & 26 deletions config/iter_config_sphere.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"volume_shape" : [1, 1, 1],
"axial_voxel_size_um" : 1.0,
"cube_voxels" : true,
"pixels_per_ml" : 17,
"n_micro_lenses" : 1,
"pixels_per_ml" : 17,
"n_voxels_per_ml" : 1,
"M_obj" : 60,
"na_obj" : 1.2,
"n_medium" : 1.35,
"wavelength" : 0.550,
"camera_pix_pitch" : 6.5,
"aperture_radius_px": 7.5,
"cube_voxels" : true,
"axial_voxel_size_um" : 1.0,
"polarizer" : [[1, 0], [0, 1]],
"analyzer" : [[1, 0], [0, 1]],
"polarizer_swing" : 0.03
Expand Down
117 changes: 117 additions & 0 deletions docs/Reconstruction Configuration Parameters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Reconstruction Configuration Key Descriptions

This document describes the various keys and their potential values in the JSON reconstruction configuration file.

---

## General Settings

| Key | Description | Possible Values | Default |
|-----------------------------|-----------------------------------------------------------------------------|---------------------------|----------------|
| `general.num_iterations` | Number of iterations for the training or reconstruction process. | Integer (e.g., 200) | 200 |
| `general.save_freq` | Frequency for saving intermediate results (in iterations). | Integer (e.g., 100) | 100 |
| `general.output_directory_postfix` | A string appended to the output directory for easier identification. | String | `""` (empty) |
| `general.notes` | Additional notes for the configuration run. | String | `""` (empty) |

---

## Learning Rates

| Key | Description | Possible Values | Default |
|-----------------------------|-----------------------------------------------------------------------------|---------------------------|----------------|
| `learning_rates.birefringence` | Learning rate for birefringence optimization. | Float (e.g., 1e-4) | 1e-4 |
| `learning_rates.optic_axis` | Learning rate for optic axis optimization. | Float (e.g., 1e-1) | 1e-1 |

---

## Regularization

| Key | Description | Possible Values | Default |
|-----------------------------|-----------------------------------------------------------------------------|---------------------------|----------------|
| `regularization.weight` | Weight of the regularization term in the loss function. | Float (e.g., 0.5) | 0.5 |
| `regularization.functions` | List of regularization functions and their associated weights. | List (e.g., `["function_name", weight]`) | N/A |

---

## File Paths

| Key | Description | Possible Values | Default |
|-----------------------------|-----------------------------------------------------------------------------|---------------------------|----------------|
| `file_paths.initial_volume` | Filepath for the initial volume, if any. | Filepath (string) | `null` |
| `file_paths.saved_rays` | Filepath for saved rays, if any. | Filepath (string) | `null` |
| `file_paths.vox_indices_by_mla_idx` | Filepath for voxel indices mapped by MLA index. | Filepath (string) | `null` |
| `file_paths.ret_image` | Filepath for the measured retardance image. | Filepath (string) | `null` |
| `file_paths.azim_image` | Filepath for the measured azimuth image. | Filepath (string) | `null` |
| `file_paths.radiometry` | Filepath for the radiometry data. | Filepath (string) | `null` |

---

## Schedulers

| Key | Description | Possible Values | Default |
|-----------------------------|-----------------------------------------------------------------------------|---------------------------|----------------|
| `schedulers.birefringence.type` | Scheduler type for birefringence learning rate. | String (e.g., "ReduceLROnPlateau") | "ReduceLROnPlateau" |
| `schedulers.birefringence.params.mode` | Mode for scheduler, controls if the scheduler is reducing learning rates based on min/max of the loss. | `"min"`, `"max"` | `"min"` |
| `schedulers.birefringence.params.factor` | Factor by which the learning rate is reduced. | Float (e.g., 0.8) | 0.8 |
| `schedulers.birefringence.params.patience` | Number of epochs with no improvement before reducing learning rate. | Integer (e.g., 5) | 5 |
| `schedulers.birefringence.params.threshold` | Threshold for measuring new optimal value. | Float (e.g., 1e-6) | 1e-6 |
| `schedulers.birefringence.params.min_lr` | Minimum learning rate after reductions. | Float (e.g., 1e-8) | 1e-8 |
| `schedulers.optic_axis.type` | Scheduler type for optic axis learning rate. | String (e.g., "CosineAnnealingWarmRestarts") | "ReduceLROnPlateau" |
| `schedulers.optic_axis.params.T_0` | Number of iterations for the first restart cycle. | Integer (e.g., 20) | N/A |
| `schedulers.optic_axis.params.T_mult` | Multiplication factor to increase the length of each cycle. | Integer (e.g., 2) | N/A |
| `schedulers.optic_axis.params.eta_min` | Minimum learning rate during annealing. | Float (e.g., 1e-4) | N/A |

---

## NeRF Settings

| Key | Description | Possible Values | Default |
|-----------------------------|-----------------------------------------------------------------------------|---------------------------|----------------|
| `nerf.enabled` | Boolean flag to enable or disable NeRF mode. | `true`, `false` | `false` |
| `nerf.learning_rates.fc1` | Learning rate for the first NeRF fully-connected layer (fc1). | Float (e.g., 1e-2) | 1e-2 |
| `nerf.learning_rates.fc2` | Learning rate for the second NeRF fully-connected layer (fc2). | Float (e.g., 1e-4) | 1e-4 |
| `nerf.learning_rates.fc3` | Learning rate for the third NeRF fully-connected layer (fc3). | Float (e.g., 1e-4) | 1e-4 |
| `nerf.learning_rates.output` | Learning rate for the NeRF output layer. | Float (e.g., 1e-4) | 1e-4 |
| `nerf.optimizer.type` | Type of optimizer used in NeRF mode. | String (e.g., "NAdam") | `"NAdam"` |
| `nerf.optimizer.betas` | Betas for momentum terms in the NeRF optimizer. | List (e.g., `[0.9, 0.999]`) | `[0.9, 0.999]`|
| `nerf.optimizer.eps` | Epsilon value for numerical stability in NeRF optimizer. | Float (e.g., 1e-7) | 1e-7 |
| `nerf.optimizer.weight_decay` | Weight decay (L2 regularization) for the NeRF optimizer. | Float (e.g., 1e-4) | 1e-4 |
| `nerf.scheduler.type` | Scheduler type for NeRF learning rates. | String (e.g., "CosineAnnealingLR") | N/A |
| `nerf.scheduler.params` | Parameters for the NeRF scheduler. | Dictionary | N/A |
| `nerf.MLP.hidden_layers` | Hidden layers for the NeRF MLP. | List (e.g., `[256, 256, 256]`) | `[256, 256, 256]` |
| `nerf.MLP.num_frequencies` | Number of frequencies for the NeRF MLP. | Integer (e.g., 10) | 10 |
| `nerf.MLP.final_layer_bias_birefringence` | Bias for the final layer of the NeRF MLP for birefringence. | Float (e.g., -0.05) | -0.05 |
| `nerf.MLP.final_layer_weight_range` | Weight range for the final layer of the NeRF MLP for birefringence. | List (e.g., `[-0.01, 0.01]`) | `[-0.01, 0.01]` |

---

## Visualization

| Key | Description | Possible Values | Default |
|-----------------------------|-----------------------------------------------------------------------------|---------------------------|----------------|
| `visualization.plot_live` | Boolean flag to determine whether to plot the reconstruction live. | `true`, `false` | `true` |

---

## Learnables

| Key | Description | Possible Values | Default |
|-----------------------------|-----------------------------------------------------------------------------|---------------------------|----------------|
| `learnables.all_prop_elements` | Boolean flag to indicate if all properties are learned. | `true`, `false` | `false` |
| `learnables.two_optic_axis_components` | Boolean flag to indicate if two components are used for optic axis. | `true`, `false` | `true` |

---

## Miscellaneous Settings

| Key | Description | Possible Values | Default |
|-----------------------------|-----------------------------------------------------------------------------|---------------------------|----------------|
| `misc.from_simulation` | Boolean flag to indicate if data comes from simulation or real-world measurements. | `true`, `false` | `false` |
| `misc.save_ray_geometry` | Boolean flag to determine whether to save the ray geometry. | `true`, `false` | `false` |
| `misc.optimizer` | Type of optimizer used for training or reconstruction. | String (e.g., "Nadam") | `"Nadam"` |
| `misc.datafidelity` | Term used in the loss function for data fidelity. | String (e.g., "euler") | `"euler"` |
| `misc.mla_rays_at_once` | Boolean flag to process MLA rays in batches. | `true`, `false` | `true` |
| `misc.free_memory_by_del_large_arrays` | Boolean flag to free memory by deleting large arrays when possible. | `true`, `false` | `false` |
| `misc.save_to_logfile` | Boolean flag to determine whether to save the output to a logfile. | `true`, `false` | `true` |

---
10 changes: 5 additions & 5 deletions examples/reconstruction_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@

# Path to the directory where the reconstruction will be saved
recon_output_dir = os.path.join("..", "reconstructions", "voxel")
recon_output_dir_postfix = "postfix"
recon_directory = create_unique_directory(recon_output_dir, postfix=recon_output_dir_postfix)

# Whether to continue a previous reconstruction
continue_recon = False
recon_file_path = r"to be alterned.h5"
recon_init_file_path = r"to be alterned.h5"

# For loading forward images that were saved in a previous reconstruction folder
measurement_dir = os.path.join(recon_output_dir, "to be altered")
Expand Down Expand Up @@ -66,8 +64,10 @@
# %% Run reconstruction
recon_optical_info = optical_info.copy()
iteration_params = setup_iteration_parameters(iter_config_file)
recon_dir_postfix = iteration_params["general"]["output_directory_postfix"]
recon_directory = create_unique_directory(recon_output_dir, postfix=recon_dir_postfix)
if continue_recon:
initial_volume = BirefringentVolume.init_from_file(recon_file_path, BACKEND, recon_optical_info)
initial_volume = BirefringentVolume.init_from_file(recon_init_file_path, BACKEND, recon_optical_info)
else:
initial_volume = BirefringentVolume(
backend=BACKEND,
Expand All @@ -88,7 +88,7 @@
output_dir=recon_directory,
device=DEVICE
)
reconstructor.reconstruct(plot_live=True)
reconstructor.reconstruct()
print("Reconstruction complete")

# %%
Loading

0 comments on commit f5f850a

Please sign in to comment.