# VICReg

## Class: VICReg

```python
class VICReg(pytorch_lightning.LightningModule):
    def __init__(
        self, 
        backbone: str = "resnet18",
        stop_gradient: bool = False,
        prjhead_dim: int = 2048
    )
```

### Description

The `VICReg` class is a PyTorch Lightning Module that implements the Variance-Invariance-Covariance Regularization (VICReg) model, a type of self-supervised learning model. This class is derived from the `pytorch_lightning.LightningModule`, hence it inherits all methods of a PyTorch Lightning Module.

### Parameters

* `backbone` (str, default="resnet18"): Specifies the name of the backbone model. This is fed into the `pipe_backbone` function to create the desired backbone model.
* `stop_gradient` (bool, default=False): A boolean flag which when set to `True`, the gradients are not computed in the forward pass, essentially making the model non-trainable. This could be useful during inference or when using the model as a feature extractor.
* `prjhead_dim` (int, default=2048): The dimension of the projection head. The projection head maps the feature vectors produced by the backbone to a space where the self-supervised loss is computed.

### Returns

This class does not have a specific return value. Instead, it's an object that can be trained, evaluated, and used for predictions.

### Examples

To initialize a VICReg model:

```python
model = VICReg(backbone="resnet50", stop_gradient=True, prjhead_dim=2048)
```

### Use Cases

* **Training a VICReg model**: After initializing a `VICReg` model, it can be trained on unlabeled data using PyTorch Lightning's trainer.
* **Feature Extraction**: The `VICReg` model can be used to extract features from images. These features can then be used in other downstream tasks like clustering or classification.
* **Transfer Learning**: The learned representations from the `VICReg` model can be transferred to other tasks. For instance, the backbone network can be used as a pre-trained network for supervised learning tasks.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://autossl.gitbook.io/autossl/api/model/vicreg.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
