Skip to content
heliaEDGE
Reference
HELIA

simclr

This module implements the SimCLR loss function for contrastive self-supervised learning.

Classes

Name Description
SimCLRLoss Implements SimCLR Cosine Similarity loss.

Functions

Name Description
l2_normalize Normalizes a tensor along a given axis.

Machine-readable model

function

Performs L2 normalization on a tensor along a given axis.

helia_edge/losses/simclr.py:21

l2_normalize(x: keras.KerasTensor, axis: int | tuple[int, ...] | None = None) -> keras.KerasTensor

Performs L2 normalization on a tensor along a given axis.

Parameters of l2_normalize
NameTypeDefaultDescription
xtf.TensorRequiredInput tensor
axisint | tuple[int]NoneAxis. Defaults to None.
Returns of l2_normalize
TypeDescription
keras.KerasTensortf.Tensor: Normalized tensor
class

Implements SimCLR Cosine Similarity loss.

helia_edge/losses/simclr.py:37

SimCLRLoss(temperature: float, **kwargs={})

Implements SimCLR Cosine Similarity loss.

SimCLR loss is used for contrastive self-supervised learning.

Parameters of SimCLRLoss
NameTypeDefaultDescription
temperaturefloatRequiredA scaling factor for cosine similarity b/w [0, 1].
method

call

Python

Computes SimCLR loss for a pair of projections in a contrastive learning trainer.

helia_edge/losses/simclr.py:54

call(projections_1: keras.KerasTensor, projections_2: keras.KerasTensor) -> keras.KerasTensor

Computes SimCLR loss for a pair of projections in a contrastive learning trainer.

Note that unlike most loss functions, this should not be called with y_true and y_pred, but with two unlabeled projections. It can otherwise be treated as a normal loss function.

Parameters of call
NameTypeDefaultDescription
projections_1keras.KerasTensorRequireda tensor with the output of the first projection model in a contrastive learning trainer
projections_2keras.KerasTensorRequireda tensor with the output of the second projection model in a contrastive learning trainer
Returns of call
TypeDescription
keras.KerasTensorkeras.KerasTensor: A tensor with the SimCLR loss computed from the input projections