LARGE_NUM
PythonLARGE_NUM = 1000000000.0This 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. |
LARGE_NUMconstantl2_normalizefunctionPerforms L2 normalization on a tensor along a given axis.SimCLRLossclassImplements SimCLR Cosine Similarity loss.LARGE_NUM = 1000000000.0Performs L2 normalization on a tensor along a given axis.
l2_normalize(x: keras.KerasTensor, axis: int | tuple[int, ...] | None = None) -> keras.KerasTensorPerforms L2 normalization on a tensor along a given axis.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | tf.Tensor | Required | Input tensor |
axis | int | tuple[int] | None | Axis. Defaults to None. |
Returns
| Type | Description |
|---|---|
keras.KerasTensor | tf.Tensor: Normalized tensor |
Implements SimCLR Cosine Similarity loss.
SimCLRLoss(temperature: float, **kwargs={})Implements SimCLR Cosine Similarity loss.
SimCLR loss is used for contrastive self-supervised learning.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
temperature | float | Required | A scaling factor for cosine similarity b/w [0, 1]. |
temperature = temperatureComputes SimCLR loss for a pair of projections in a contrastive learning trainer.
call(projections_1: keras.KerasTensor, projections_2: keras.KerasTensor) -> keras.KerasTensorComputes 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
| Name | Type | Default | Description |
|---|---|---|---|
projections_1 | keras.KerasTensor | Required | a tensor with the output of the first projection model in a contrastive learning trainer |
projections_2 | keras.KerasTensor | Required | a tensor with the output of the second projection model in a contrastive learning trainer |
Returns
| Type | Description |
|---|---|
keras.KerasTensor | keras.KerasTensor: A tensor with the SimCLR loss computed from the input projections |
get_config()