Utils
This module provides utility functions for image processing and model optimization.
It includes functions to plot original and preprocessed images along with their tags, ensure the existence of specified directories, set up optimizers based on configuration files, and create circular masks with an inner "spider" circle removed. These utilities facilitate various tasks in image analysis and machine learning model training.
create_circular_mask_with_spider(resolution, bkg_value=0)
Creates a circular mask with an inner "spider" circle removed.
Parameters:
-
resolution
(int
) –The resolution of the square mask.
-
bkg_value
(int
, default:0
) –The background value to set for the masked areas. Defaults to 0.
Returns:
-
torch.Tensor : np.ndarray
–A 2D tensor representing the mask.
Source code in src/speckcn2/utils.py
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 |
|
ensure_directory(data_directory)
Ensure that the directory exists.
Parameters:
-
data_directory
(str
) –The directory to ensure
Source code in src/speckcn2/utils.py
72 73 74 75 76 77 78 79 80 81 82 |
|
plot_preprocessed_image(image_orig, image, tags, counter, datadirectory, mname, file_name, polar=False)
Plots the original and preprocessed image, and the tags.
Parameters:
-
image_orig
(tensor
) –The original image
-
image
(tensor
) –The preprocessed image
-
tags
(tensor
) –The screen tags
-
counter
(int
) –The counter of the image
-
datadirectory
(str
) –The directory containing the data
-
mname
(str
) –The name of the model
-
file_name
(str
) –The name of the original image
-
polar
(bool
, default:False
) –If the image is in polar coordinates, by default False
Source code in src/speckcn2/utils.py
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 |
|
setup_optimizer(config, model)
Returns the optimizer specified in the configuration file.
Parameters:
-
config
(dict
) –Dictionary containing the configuration
-
model
(Module
) –The model to optimize
Returns:
-
optimizer
(Module
) –The optimizer with the loaded state
Source code in src/speckcn2/utils.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|