# Introduction

## autoSSL: A Self-Supervised Learning Library

autoSSL is a versatile and accessible library for Self-Supervised Learning (SSL). This Python-based deep learning library provides you with utilities for data loading, model architectures, evaluation scripts, and numerous experiment notebooks. The design and organization of this project encourage flexible, scalable, and reusable workflows for your SSL tasks.

### Code Structure

```
.
├── autoSSL                      # Main project folder
│   ├── data                     # Data loading utilities
│   │   ├── PipeDataset.py       # Dataset loading pipeline
│   │   └── __init__.py
│   ├── evaluate                 # Evaluation scripts
│   │   ├── eval_KNN.py          # K-Nearest Neighbors evaluation
│   │   ├── eval_KNNplot.py      # K-Nearest Neighbors evaluation plot
│   │   ├── eval_linear.py       # Linear evaluation
│   │   ├── pipe_collate.py      # Pipeline for model collation
│   │   └── __init__.py
│   ├── models                   # SSL model architectures
│   │   ├── Backbone.py          # Backbone for SSL models
│   │   ├── BarlowTwins.py       # Barlow Twins architecture
│   │   ├── BYOL.py              # Bootstrap Your Own Latent (BYOL) architecture
│   │   ├── MoCo.py              # Momentum Contrast (MoCo) architecture
│   │   ├── pipe_model.py        # Model loading pipeline
│   │   ├── SimCLR.py            # SimCLR architecture
│   │   ├── SimSiam.py           # SimSiam architecture
│   │   ├── VICReg.py            # VICReg architecture
│   │   └── __init__.py
│   ├── train                    # Training scripts
│   │   ├── pipe_train.py        # Training pipeline
│   │   └── __init__.py
│   └── utils                    # Utility scripts
│       ├── dict2transformer.py  # Function to transform dictionaries
│       ├── embedding.py         # Embedding functions
│       ├── join_dir.py          # Directory joining function
│       ├── logging.py           # Logging functionalities
│       └── __init__.py
├── experiment                   # Experiment notebooks
│   ├── Experiment1.ipynb
│   ├── Experiment2.ipynb
│   ├── experiment_checkpoints   # Checkpoints for experiments
│   │   └── Experiment1
│   ├── global.yaml              # Global configurations
│   └── Unit_Test.ipynb          # Unit tests
├── experiment_template.ipynb   # Template for creating new experiments
├── README.md                    # This file
├── LICENSE                      # License file
└── Template_Legacy.ipynb        # Legacy template
```

### Quick Start Guide

#### Training

First, set up your own configuration. This example demonstrates a configuration for the BarlowTwins model with a batch size of 512.

```python
config = global_config.copy()
SSL_augmentation = global_SSL_augmentation
config["name"] = "barlow_batch_512"
config["batch"] = 512
config["model"] = "BarlowTwins"

# Load the dataset
pdata = PipeDataset(config=config, augmentation=dict2transformer(SSL_augmentation, view=config["view"]))

# Load the model
pmodel = pipe_model(config=config)

# Initialize a trainer for the model and begin training
trainer = Trainer(config, model_mode="start")
trainer.fit(pmodel, pdata.dataloader)
```

If you wish to continue training from a previous checkpoint

:

```python
# Initialize a trainer in "continue" mode
trainer1 = Trainer(config, model_mode="continue", extra_epoch=0)

# Continue training from the latest checkpoint
trainer1.fit(pmodel, pdata.dataloader, ckpt_path="latest")
```

#### Evaluation

Perform evaluation using the trained models:

```python
collate = pipe_collate(address="experiment_checkpoints/batch VS model/", reg="batch_[0-9]+")
aaa = eval_linear(pdata, models=collate, device=global_config["device"], split=0.8)
```

The `autoSSL.evaluate` module offers a suite of functions for model evaluation, including `eval_KNN` for K-Nearest Neighbors evaluation, `eval_KNNplot` for visualizing K-Nearest Neighbors results, and `eval_linear` for linear evaluation of the model.

Please explore the project and refer to the individual experiment notebooks for more detailed examples and explanations. We look forward to seeing what you will create with autoSSL!

Here is the configuration

1. **Project Configuration**

| Hyperparameter  | Description                   | Example Values                                    | Used in Function              |
| --------------- | ----------------------------- | ------------------------------------------------- | ----------------------------- |
| checkpoint\_dir | Directory to save checkpoints | 'experiment\_checkpoints/'                        | ck\_callback(checkpoint\_dir) |
| experiment      | Name of the experiment        | "batch VS model"                                  | N/A                           |
| name            | Specific configuration name   | "config1"                                         | pipe\_model(name=...)         |
| log\_dir        | Directory to save logs        | 'experiment\_checkpoints/batch VS model/config1/' | N/A                           |

2. **Model Configuration**

| Hyperparameter | Description                      | Example Values                                                                     | Used in Function                |
| -------------- | -------------------------------- | ---------------------------------------------------------------------------------- | ------------------------------- |
| model          | The SSL model to use             | "VICReg", "MoCo", "BYOL", "SimCLR", "SimSiam", "BarlowTwins"                       | pipe\_model(name=...)           |
| backbone       | The backbone model for SSL model | "resnet18", "resnet50", "efficientnet\_b5", "mobilenet\_v3", "vit\_64", "vit\_224" | pipe\_model(backbone=...)       |
| stop\_gradient | Whether to stop gradient or not  | True, False                                                                        | pipe\_model(stop\_gradient=...) |
| prjhead\_dim   | The dimension of projection head | 2048, 1024, 512                                                                    | pipe\_model(prjhead\_dim=...)   |

3. **Training Configuration**

| Hyperparameter | Description                               | Example Values | Used in Function                                                           |
| -------------- | ----------------------------------------- | -------------- | -------------------------------------------------------------------------- |
| max\_epochs    | The maximum number of epochs for training | 5, 10, 50      | Trainer(config, model\_mode, extra\_epoch=...)                             |
| device         | The device for training                   | "cuda", "cpu"  | eval\_linear(device=...), eval\_KNN(device=...), eval\_KNNplot(device=...) |

4. **Dataset Configuration**

| Hyperparameter           | Description                                               | Example Values                  | Used in Function                 |
| ------------------------ | --------------------------------------------------------- | ------------------------------- | -------------------------------- |
| input\_size              | The input size for the model                              | 64, 128, 224                    | N/A                              |
| path\_to\_train\_cifar10 | The path to the training dataset cifar10                  | "../../Datasets/cifar10/train/" | PipeDataset(input\_dir=...)      |
| path\_to\_test\_cifar10  | The path to the testing dataset cifar10                   | "../../Datasets/cifar10/test/"  | PipeDataset(input\_dir=...)      |
| view                     | The number of views for each instance                     | 1, 2                            | dict2transformer(dict, view=...) |
| samples                  | The number of samples to load from the dataset            | 0, 100, 1000                    | PipeDataset(samples=...)         |
| batch\_size              | The size of each batch during training                    | 512, 256, 128                   | PipeDataset(batch\_size=...)     |
| shuffle                  | Whether to shuffle the dataset                            | True, False                     | PipeDataset(shuffle=...)         |
| drop\_last               | Whether to drop the last incomplete batch during training | True, False                     | PipeDataset(drop\_last=...)      |
| num\_workers             | The number of worker threads for data loading             | 4, 8, 16                        | PipeDataset(num\_workers=...)    |

&#x20;


---

# 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/getting-started/introduction.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.
