Models
This page acts as the technical reference for the models subpackage.
The models package provides the inverse camera response function model classes, which are built on the torch.nn.module class. The base model provides a guideline for creating a new ICRF model, while the concrete implementations provide different approaches to modelling an ICRF.
ICRFModelBase
Bases: Module
, ABC
Base class for the ICRF model classes. Implements common functionality and acts as a guideline for implementing the model interface.
Attributes
_n_points: int how many datapoints the range [0, 1] is split into in modelling the ICRF. _channels: int how many color channels are managed by the model. One ICRF curve for each channel. interpolation_mode: InterpMode enum determining how the forward call of the model is handled. See InterpMode doc for more. _initial_power: float a guess at the initial form of the ICRF curve, represented by raising the linear range [0, 1] to this power. _fig: Figure a matplotlib Figure used for visualizing the model. _axs: List[Axes] a list of matplotlib axes used for model visualization. _lines_curve: List[Line2D] a list of the matplotlib Line2D objects for the plotted curves used in model visualization. _lines_deriv: List[Line2D] a list of the matplotlib Line2D objects for the plotted curves' derivatives used in model visualization.
Source code in clair_torch/models/base.py
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 |
|
__init__(n_points=256, channels=3, interpolation_mode=InterpMode.LINEAR, initial_power=2.5, icrf=None)
Initializes the ICRF model instance with the given parameters. The icrf argument overrides n_points and channels by its shape if given. Args: n_points: how many datapoints the range [0, 1] is split into in modelling the ICRF. channels: how many datapoints the range [0, 1] is split into in modelling the ICRF. interpolation_mode: enum determining how the forward call of the model is handled. See InterpMode doc for more. initial_power: a guess at the initial form of the ICRF curve, represented by raising the linear range [0, 1] to this power. icrf: an optional initial form of the ICRF curves, overrides n_points and channels.
Source code in clair_torch/models/base.py
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 |
|
channel_params(c)
abstractmethod
Method for getting the model parameters for the channel of the given index. Subclasses implement the logic based on their model parameters. This should be the main method of accessing the optimization parameters for feeding them to a torch.Optimizer. Args: c: channel index.
Returns:
Type | Description |
---|---|
list[Parameter]
|
list of nn.Parameters. |
Source code in clair_torch/models/base.py
108 109 110 111 112 113 114 115 116 117 118 119 |
|
plot_icrf()
Model utility function for live-plotting. The model class manages the state of the plot, while utilizing the general plotting function of the plotting module.
Source code in clair_torch/models/base.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
update_icrf()
abstractmethod
Method for constructing a new ICRF curve from the model parameters and updating the curve to the self._icrf attribute. Subclasses implement the logic based their model parameters.
Source code in clair_torch/models/base.py
121 122 123 124 125 126 |
|
ICRFModelDirect
Bases: ICRFModelBase
An ICRF model class that utilizes the datapoints directly as optimization parameters. Total number of parameters is therefore n_points * channels.
Attributes:
Inherits attributes from ICRFModelBase.
nn.ParameterList
a list of nn parameters, each parameter corresponds to an actual datapoint in the ICRF curve.
Source code in clair_torch/models/icrf_model.py
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 |
|
channel_params(c)
Main method for accessing the optimization parameters of the model. Args: c: channel index.
Returns:
Type | Description |
---|---|
A list of nn.Parameters. |
Source code in clair_torch/models/icrf_model.py
112 113 114 115 116 117 118 119 120 121 |
|
update_icrf()
Directly stack the per-channel parameters to form the ICRF.
Source code in clair_torch/models/icrf_model.py
123 124 125 126 127 |
|
ICRFModelPCA
Bases: ICRFModelBase
ICRF model class that utilizes a set of principal components for the optimization process. For each principal component a single scalar optimization parameter is utilized, e.g. for 5 components there is a total of 5 parameters to optimize in the model. The shape of the given principal components is used to determine the number of datapoints, number of components and number of channels. In addition to these an exponent for the linear range [0, 1] is used as a parameter for each channel.
Attributes:
Inherits attributes from ICRFModelBase
nn.ParameterList
a list of nn parameters representing the exponent of the base curve. One element for each channel.
coefficients: nn.ParameterList a list of nn parameters representing the PCA parameters, for each channel a number equal to the number of components.
Source code in clair_torch/models/icrf_model.py
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 |
|
__init__(pca_basis, interpolation_mode=InterpMode.LINEAR, initial_power=2.5, icrf=None)
Initializes a ICRFModelPCA instance. The pca_basis is used to determine the shape of the actual ICRF. Args: pca_basis: a torch.Tensor representing the principal components. The shape is expected to be (n_points, num_components, channels). interpolation_mode: a InterpMode determining how the ICRF is used in a forward call. initial_power: a guess at the initial form of the ICRF curve, represented by raising the linear range [0, 1] to this power. icrf: an optional initial form of the ICRF curves, overrides n_points and channels.
Source code in clair_torch/models/icrf_model.py
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 |
|
channel_params(c)
Main method for accessing the optimization parameters of the model. Args: c: channel index.
Returns:
Type | Description |
---|---|
list[Parameter]
|
A list of nn.Parameters. |
Source code in clair_torch/models/icrf_model.py
58 59 60 61 62 63 64 65 66 67 |
|
update_icrf()
Builds the full ICRF curve (n_points, channels) from base + PCA.
Source code in clair_torch/models/icrf_model.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|