sup3r.utilities.loss_metrics.LowResLoss
- class LowResLoss(s_enhance=1, t_enhance=1, t_method='average', tf_loss='MeanSquaredError', ex_loss=None)[source]
Bases:
Loss
Content loss that is calculated by coarsening the synthetic and true high-resolution data pairs and then performing the pointwise content loss on the low-resolution fields
Initialize the loss with given weight
- Parameters:
s_enhance (int) – factor by which to coarsen spatial dimensions. 1 will keep the spatial axes as high-res
t_enhance (int) – factor by which to coarsen temporal dimension. 1 will keep the temporal axes as high-res
t_method (str) – Accepted options: [subsample, average] Subsample will take every t_enhance-th time step, average will average over t_enhance time steps
tf_loss (str) – The tensorflow loss function to operate on the low-res fields. Must be the name of a loss class that can be retrieved from
tf.keras.losses
e.g., “MeanSquaredError” or “MeanAbsoluteError”ex_loss (None | str) – Optional additional loss metric evaluating the spatial or temporal extremes of the high-res data. Can be “SpatialExtremesOnlyLoss” or “TemporalExtremesOnlyLoss” (keys in
EX_LOSS_METRICS
).
Methods
call
(y_true, y_pred)Invokes the Loss instance.
from_config
(config)Instantiates a Loss from its config (output of get_config()).
Returns the config dictionary for a Loss instance.
Attributes
EX_LOSS_METRICS
- __call__(x1, x2)[source]
Custom content loss calculated on re-coarsened low-res fields
- Parameters:
x1 (tf.tensor) – Synthetic high-res generator output, shape is either of these: (n_obs, spatial_1, spatial_2, features) (n_obs, spatial_1, spatial_2, temporal, features)
x2 (tf.tensor) – True high resolution data, shape is either of these: (n_obs, spatial_1, spatial_2, features) (n_obs, spatial_1, spatial_2, temporal, features)
- Returns:
tf.tensor – 0D tensor loss value
- abstract call(y_true, y_pred)
Invokes the Loss instance.
- Args:
- y_true: Ground truth values. shape = [batch_size, d0, .. dN],
except sparse loss functions such as sparse categorical crossentropy where shape = [batch_size, d0, .. dN-1]
y_pred: The predicted values. shape = [batch_size, d0, .. dN]
- Returns:
Loss values with the shape [batch_size, d0, .. dN-1].
- classmethod from_config(config)
Instantiates a Loss from its config (output of get_config()).
- Args:
config: Output of get_config().
- Returns:
A Loss instance.
- get_config()
Returns the config dictionary for a Loss instance.