# helia_edge.trainers.contrastive

## Contrastive Trainer API

This module provides a trainer for contrastive learning.

**Classes**

| Name | Description |
| --- | --- |
| `ContrastiveTrainer` | Trainer for contrastive learning |

## helia_edge.trainers.contrastive.ContrastiveTrainer

`class` · `python`

```python
ContrastiveTrainer(
    encoder: keras.Model,
    projector: keras.Model | tuple[keras.Model, keras.Model],
    augmenter: keras.Layer | tuple[keras.Layer, keras.Layer] | None = None,
    probe: keras.Layer | keras.Model | None = None,
)
```

Creates a self-supervised contrastive trainer for a model.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| encoder | keras.Model | Required | The encoder model to be trained. |
| projector | keras.Model \| tuple[keras.Model, keras.Model] | Required | The projector model to be trained. |
| augmenter | keras.Layer \| tuple[keras.Layer, keras.Layer] \| None | None | The augmenter to be used for data augmentation. |
| probe | keras.Layer \| keras.Model \| None | None | The probe model to be trained. If None, no probe is used. |

Source: `helia_edge/trainers/contrastive.py:18`

### helia_edge.trainers.contrastive.ContrastiveTrainer.SAMPLES

`constant` · `python`

```python
SAMPLES = 'data'
```

Source: `helia_edge/trainers/contrastive.py:20`

### helia_edge.trainers.contrastive.ContrastiveTrainer.LABELS

`constant` · `python`

```python
LABELS = 'labels'
```

Source: `helia_edge/trainers/contrastive.py:21`

### helia_edge.trainers.contrastive.ContrastiveTrainer.AUG_SAMPLES_0

`constant` · `python`

```python
AUG_SAMPLES_0 = 'augmented_data_0'
```

Source: `helia_edge/trainers/contrastive.py:22`

### helia_edge.trainers.contrastive.ContrastiveTrainer.AUG_SAMPLES_1

`constant` · `python`

```python
AUG_SAMPLES_1 = 'augmented_data_1'
```

Source: `helia_edge/trainers/contrastive.py:23`

### helia_edge.trainers.contrastive.ContrastiveTrainer.augmenters

`attribute` · `python`

```python
augmenters: tuple[keras.Layer, keras.Layer]
```

Source: `helia_edge/trainers/contrastive.py:26`

### helia_edge.trainers.contrastive.ContrastiveTrainer.encoder

`attribute` · `python`

```python
encoder: keras.Model = encoder
```

Source: `helia_edge/trainers/contrastive.py:66`

### helia_edge.trainers.contrastive.ContrastiveTrainer.projectors

`attribute` · `python`

```python
projectors = projector if  else (projector, projector)
```

Source: `helia_edge/trainers/contrastive.py:70`

### helia_edge.trainers.contrastive.ContrastiveTrainer.probe

`attribute` · `python`

```python
probe = probe
```

Source: `helia_edge/trainers/contrastive.py:71`

### helia_edge.trainers.contrastive.ContrastiveTrainer.loss_metric

`attribute` · `python`

```python
loss_metric = keras.metrics.Mean(name='loss')
```

Source: `helia_edge/trainers/contrastive.py:73`

### helia_edge.trainers.contrastive.ContrastiveTrainer.encoder_metrics

`attribute` · `python`

```python
encoder_metrics = []
```

Source: `helia_edge/trainers/contrastive.py:74`

### helia_edge.trainers.contrastive.ContrastiveTrainer.probe_loss_metric

`attribute` · `python`

```python
probe_loss_metric = keras.metrics.Mean(name='probe_loss')
```

Source: `helia_edge/trainers/contrastive.py:76`

### helia_edge.trainers.contrastive.ContrastiveTrainer.probe_metrics

`attribute` · `python`

```python
probe_metrics = []
```

Source: `helia_edge/trainers/contrastive.py:77`

### helia_edge.trainers.contrastive.ContrastiveTrainer.metrics

`attribute` · `python`

```python
metrics
```

Source: `helia_edge/trainers/contrastive.py:128`

### helia_edge.trainers.contrastive.ContrastiveTrainer.compile

`method` · `python`

```python
compile(
    encoder_optimizer: keras.Optimizer,
    encoder_loss: keras.Loss,
    encoder_metrics: list[keras.Metric] | None = None,
    probe_optimizer: keras.Optimizer | None = None,
    probe_loss: keras.Loss | None = None,
    probe_metrics: list[keras.Metric] | None = None,
    **kwargs={},
)
```

Source: `helia_edge/trainers/contrastive.py:79`

### helia_edge.trainers.contrastive.ContrastiveTrainer.fit

`method` · `python`

```python
fit(x=None, y=None, sample_weight=None, batch_size=None, validation_data=None, **kwargs={})
```

Source: `helia_edge/trainers/contrastive.py:137`

### helia_edge.trainers.contrastive.ContrastiveTrainer.run_augmenters

`method` · `python`

```python
run_augmenters(x, y=None)
```

Source: `helia_edge/trainers/contrastive.py:169`

### helia_edge.trainers.contrastive.ContrastiveTrainer.train_step

`method` · `python`

```python
train_step(data)
```

Source: `helia_edge/trainers/contrastive.py:282`

### helia_edge.trainers.contrastive.ContrastiveTrainer.test_step

`method` · `python`

```python
test_step(data)
```

Source: `helia_edge/trainers/contrastive.py:286`

### helia_edge.trainers.contrastive.ContrastiveTrainer.call

`method` · `python`

```python
call(inputs)
```

Source: `helia_edge/trainers/contrastive.py:290`

### helia_edge.trainers.contrastive.ContrastiveTrainer.linear_probe

`method` · `python`

```python
linear_probe(num_classes, **kwargs={})
```

`staticmethod`

Source: `helia_edge/trainers/contrastive.py:293`

### helia_edge.trainers.contrastive.ContrastiveTrainer.save

`method` · `python`

```python
save(filepath, overwrite=True, zipped=True, **kwargs={})
```

We only save the encoder model

Source: `helia_edge/trainers/contrastive.py:297`
