A PyTorch implementation of SimSiam (arXiv:2011.10566) for self-supervised learning, with comprehensive evaluation on MiniImageNet and CIFAR-10 datasets.
- Clone the repository
- Set up the environment
- Download the dataset
- Train the model
- Run evaluation
# Create and activate virtual environment
python -m venv env
source env/bin/activate # On Windows use: env\Scripts\activate
# Install dependencies
pip install -r requirements.txt
- Download the dataset from Kaggle
- Extract the contents into
Dataset/CLEAR
folder - Run the dataset splitting script:
python3 split_dataset.py
Train the model using the following command:
python3 main.py [OPTIONS]
Parameter | Default Value | Description |
---|---|---|
--key |
'' | CometML Api Key |
--train_dir |
'Dataset/Splitted/Train' | Training dataset directory |
--val_dir |
'Dataset/Splitted/Test' | Validation dataset directory |
--batch_size |
96 | Training batch size |
--num_workers |
12 | Number of data loading workers |
--base_lr |
0.05 | Base learning rate |
--momentum |
0.9 | SGD momentum |
--weight_decay |
0.0001 | Weight decay |
--epochs |
200 | Number of training epochs |
--val_step |
1 | Validation frequency (epochs) |
--knn_k |
200 | Number of nearest neighbors for KNN |
--knn_t |
0.1 | KNN temperature parameter |
--projector_dim |
512 | Projector dimensionality |
--predictor_dim |
128 | Predictor dimensionality |
--stop_grad |
True | Stop gradient backpropagation |
--type_loss |
'Cosine Similarity' | Loss function type |
--symmetric |
True | Use symmetric loss |
- "Cosine Similarity"
- "Cross Entropy Similarity"
The model saves checkpoints every 10 epochs in the Models/SimSiam
directory.
Evaluate the trained model using:
python3 LinearEvaluation.py [OPTIONS]
Parameter | Default Value | Description |
---|---|---|
--key |
'' | CometML Api Key |
--path |
'Models/SimSiam/Symmetric Loss/model_200_96_Final.pth' | Pretrained model path |
--batch_size |
128 | Evaluation batch size |
--epochs |
100 | Evaluation epochs |
--lr |
0.3 | Learning rate |
--momentum |
0.9 | Optimizer momentum |
--weight_decay |
0.0 | Weight decay |
--num_workers |
12 | Data loading workers |
--dataset |
'MiniImageNet' | Evaluation dataset |
--projector_dim |
512 | Projector dimensionality |
--predictor_dim |
128 | Predictor dimensionality |
- MiniImageNet (default)
- CIFAR-10
- CIFAR-10: 0.025
- MiniImageNet: 0.3
Available model variants:
Models/SimSiam/Symmetric Loss/model_200_96_Final.pth
Models/SimSiam/Asymmetric Loss/model_200_96_Final.pth
Models/SimSiam/Cross Entropy Similarity/model_200_96_Final.pth
Models/SimSiam/Symmetric Loss without stopgrad/model_200_96_Final.pth
All experimental results are tracked and available on Comet.ml: View Results Dashboard
- When using pretrained models, ensure
projector_dim
andpredictor_dim
match the training values - Checkpoints are saved every 10 epochs
- Different loss function implementations are available in separate directories