Siamese¶
Base classes¶
- class eztorch.models.siamese.SiameseBaseModel(trunk, optimizer, projector=None, predictor=None, train_transform=None, val_transform=None, test_transform=None, normalize_outputs=True, num_global_crops=2, num_local_crops=0, num_splits=0, num_splits_per_combination=2, mutual_pass=False)[source]¶
Abstract class to represent siamese models.
Subclasses should implement training_step method.
- Parameters:
trunk (
DictConfig
) – Config to build a trunk.optimizer (
DictConfig
) – Config to build optimizers and schedulers.projector (
Optional
[DictConfig
], optional) – Config to build a project.Default:None
predictor (
Optional
[DictConfig
], optional) – Config to build a predictor.Default:None
train_transform (
Optional
[DictConfig
], optional) – Config to perform transformation on train input.Default:None
val_transform (
Optional
[DictConfig
], optional) – Config to perform transformation on val input.Default:None
test_transform (
Optional
[DictConfig
], optional) – Config to perform transformation on test input.Default:None
normalize_outputs (
bool
, optional) – IfTrue
, normalize outputs.Default:True
num_global_crops (
int
, optional) – Number of global crops which are the first elementsDefault:2
batch. (of each)
num_local_crops (
int
, optional) – Number of local crops which are the last elementsDefault:0
batch.
num_splits (
int
, optional) – Number of splits to apply to each crops.Default:0
num_splits_per_combination (
int
, optional) – Number of splits used for combinations of features of each split.Default:2
mutual_pass (
bool
, optional) – IfTrue
, perform one pass per crop resolution.Default:False
- class eztorch.models.siamese.MomentumSiameseBaseModel(trunk, optimizer, projector=None, predictor=None, train_transform=None, val_transform=None, test_transform=None, normalize_outputs=True, num_global_crops=2, num_local_crops=0, num_splits=0, num_splits_per_combination=2, mutual_pass=False, initial_momentum=0.996, scheduler_momentum='cosine')[source]¶
Abstract class to represent siamese models with a momentum branch.
Subclasses should implement training_step method.
- Parameters:
trunk (
DictConfig
) – Config to build a trunk.optimizer (
DictConfig
) – Config to build optimizers and schedulers.projector (
Optional
[DictConfig
], optional) – Config to build a project.Default:None
predictor (
Optional
[DictConfig
], optional) – Config to build a predictor.Default:None
train_transform (
Optional
[DictConfig
], optional) – Config to perform transformation on train input.Default:None
val_transform (
Optional
[DictConfig
], optional) – Config to perform transformation on val input.Default:None
test_transform (
Optional
[DictConfig
], optional) – Config to perform transformation on test input.Default:None
normalize_outputs (
bool
, optional) – IfTrue
, normalize outputs.Default:True
num_global_crops (
int
, optional) – Number of global crops which are the first elements of each batch.Default:2
num_local_crops (
int
, optional) – Number of local crops which are the last elements of each batch.Default:0
num_splits (
int
, optional) – Number of splits to apply to each crops.Default:0
num_splits_per_combination (
int
, optional) – Number of splits used for combinations of features of each split.Default:2
mutual_pass (
bool
, optional) – IfTrue
, perform one pass per branch per crop resolution.Default:False
initial_momentum (
int
, optional) – Initial value for the momentum update.Default:0.996
scheduler_momentum (
str
, optional) – Rule to update the momentum value.Default:'cosine'
- class eztorch.models.siamese.ShuffleMomentumSiameseBaseModel(trunk, optimizer, projector=None, predictor=None, train_transform=None, val_transform=None, test_transform=None, normalize_outputs=True, num_global_crops=2, num_local_crops=0, num_splits=0, num_splits_per_combination=2, mutual_pass=False, initial_momentum=0.996, scheduler_momentum='cosine', shuffle_bn=True, num_devices=1, simulate_n_devices=8)[source]¶
Abstract class to represent siamese models with a momentum branch and possibility to shuffle input elements in momentum branch to apply normalization trick from MoCo.
Subclasses should implement training_step method.
- Parameters:
trunk (
DictConfig
) – Config to build a trunk.optimizer (
DictConfig
) – Config to build optimizers and schedulers.projector (
Optional
[DictConfig
], optional) – Config to build a project.Default:None
predictor (
Optional
[DictConfig
], optional) – Config to build a predictor.Default:None
train_transform (
Optional
[DictConfig
], optional) – Config to perform transformation on train input.Default:None
val_transform (
Optional
[DictConfig
], optional) – Config to perform transformation on val input.Default:None
test_transform (
Optional
[DictConfig
], optional) – Config to perform transformation on test input.Default:None
normalize_outputs (
bool
, optional) – IfTrue
, normalize outputs.Default:True
num_global_crops (
int
, optional) – Number of global crops which are the first elements of each batch.Default:2
num_local_crops (
int
, optional) – Number of local crops which are the last elements of each batch.Default:0
num_splits (
int
, optional) – Number of splits to apply to each crops.Default:0
num_splits_per_combination (
int
, optional) – Number of splits used for combinations of features of each split.Default:2
mutual_pass (
bool
, optional) – IfTrue
, perform one pass per branch per crop resolution.Default:False
initial_momentum (
int
, optional) – Initial value for the momentum update.Default:0.996
scheduler_momentum (
str
, optional) – Rule to update the momentum value.Default:'cosine'
shuffle_bn (
bool
, optional) – IfTrue
, apply shuffle normalization trick from MoCo.Default:True
num_devices (
int
, optional) – Number of devices used to train the model in each node.Default:1
simulate_n_devices (
int
, optional) – Number of devices to simulate to apply shuffle trick. Requiresshuffle_bn
to beTrue
andnum_devices
to be \(1\).Default:8
- class eztorch.models.siamese.ShuffleMomentumQueueBaseModel(trunk, optimizer, projector=None, predictor=None, train_transform=None, val_transform=None, test_transform=None, normalize_outputs=True, num_global_crops=2, num_local_crops=0, num_splits=0, num_splits_per_combination=2, mutual_pass=False, initial_momentum=0.999, scheduler_momentum='constant', shuffle_bn=False, num_devices=1, simulate_n_devices=8, queue=None, sym=False, use_keys=False)[source]¶
SCE model.
- Parameters:
trunk (
DictConfig
) – Config tu build a trunk.optimizer (
DictConfig
) – Config tu build optimizers and schedulers.projector (
Optional
[DictConfig
], optional) – Config to build a project.Default:None
predictor (
Optional
[DictConfig
], optional) – Config to build a predictor.Default:None
train_transform (
Optional
[DictConfig
], optional) – Config to perform transformation on train input.Default:None
val_transform (
Optional
[DictConfig
], optional) – Config to perform transformation on val input.Default:None
test_transform (
Optional
[DictConfig
], optional) – Config to perform transformation on test input.Default:None
normalize_outputs (
bool
, optional) – IfTrue
, normalize outputs.Default:True
num_global_crops (
int
, optional) – Number of global crops which are the first elements of each batch.Default:2
num_local_crops (
int
, optional) – Number of local crops which are the last elements of each batch.Default:0
num_splits (
int
, optional) – Number of splits to apply to each crops.Default:0
num_splits_per_combination (
int
, optional) – Number of splits used for combinations of features of each split.Default:2
mutual_pass (
bool
, optional) – IfTrue
, perform one pass per branch per crop resolution.Default:False
initial_momentum (
int
, optional) – Initial value for the momentum update.Default:0.999
scheduler_momentum (
str
, optional) – Rule to update the momentum value.Default:'constant'
shuffle_bn (
bool
, optional) – IfTrue
, apply shuffle normalization trick from MoCo.Default:False
num_devices (
int
, optional) – Number of devices used to train the model in each node.Default:1
simulate_n_devices (
int
, optional) – Number of devices to simulate to apply shuffle trick. Requiresshuffle_bn
to beTrue
andnum_devices
to be \(1\).Default:8
queue (
Optional
[DictConfig
], optional) – Config to build a queue.Default:None
sym (
bool
, optional) – IfTrue
, symmetrised the loss.Default:False
use_keys (
bool
, optional) – IfTrue
, add keys to negatives.Default:False
Self-Supervised Models¶
SimCLR¶
- class eztorch.models.siamese.SimCLRModel(trunk, optimizer, projector=None, train_transform=None, val_transform=None, test_transform=None, normalize_outputs=True, num_global_crops=2, num_local_crops=0, num_splits=0, num_splits_per_combination=2, mutual_pass=False, temp=0.1)[source]¶
SimCLR model with version 1, 2 that can be configured.
References
SimCLR: https://arxiv.org/abs/2002.05709
SimCLRv2: https://arxiv.org/abs/2006.10029
- Parameters:
trunk (
DictConfig
) – Config tu build a trunk.optimizer (
DictConfig
) – Config tu build optimizers and schedulers.projector (
Optional
[DictConfig
], optional) – Config to build a project.Default:None
train_transform (
Optional
[DictConfig
], optional) – Config to perform transformation on train input.Default:None
val_transform (
Optional
[DictConfig
], optional) – Config to perform transformation on val input.Default:None
test_transform (
Optional
[DictConfig
], optional) – Config to perform transformation on test input.Default:None
normalize_outputs (
bool
, optional) – IfTrue
, normalize outputs.Default:True
num_global_crops (
int
, optional) – Number of global crops which are the first elements of each batch.Default:2
num_local_crops (
int
, optional) – Number of local crops which are the last elements of each batch.Default:0
num_splits (
int
, optional) – Number of splits to apply to each crops.Default:0
num_splits_per_combination (
int
, optional) – Number of splits used for combinations of features of each split.Default:2
mutual_pass (
bool
, optional) – IfTrue
, perform one pass per crop resolution.Default:False
temp (
float
, optional) – Temperature parameter to scale the online similarities.Default:0.1
MoCo¶
- class eztorch.models.siamese.MoCoModel(trunk, optimizer, projector=None, predictor=None, train_transform=None, val_transform=None, test_transform=None, normalize_outputs=True, num_global_crops=2, num_local_crops=0, num_splits=0, num_splits_per_combination=2, mutual_pass=False, initial_momentum=0.999, scheduler_momentum='constant', shuffle_bn=True, num_devices=1, simulate_n_devices=8, queue=None, sym=False, use_keys=False, temp=0.2)[source]¶
MoCo model with version 1, 2, 2+, 3 that can be configured.
References
MoCov2: https://arxiv.org/abs/2003.04297
MoCov2+: https://arxiv.org/abs/2011.10566
MoCov3: https://arxiv.org/abs/2104.02057
- Parameters:
trunk (
DictConfig
) – Config to build a trunk.optimizer (
DictConfig
) – Config to build optimizers and schedulers.projector (
Optional
[DictConfig
], optional) – Config to build a project.Default:None
predictor (
Optional
[DictConfig
], optional) – Config to build a predictor.Default:None
train_transform (
Optional
[DictConfig
], optional) – Config to perform transformation on train input.Default:None
val_transform (
Optional
[DictConfig
], optional) – Config to perform transformation on val input.Default:None
test_transform (
Optional
[DictConfig
], optional) – Config to perform transformation on test input.Default:None
normalize_outputs (
bool
, optional) – IfTrue
, normalize outputs.Default:True
num_global_crops (
int
, optional) – Number of global crops which are the first elements of each batch.Default:2
num_local_crops (
int
, optional) – Number of local crops which are the last elements of each batch.Default:0
num_splits (
int
, optional) – Number of splits to apply to each crops.Default:0
num_splits_per_combination (
int
, optional) – Number of splits used for combinations of features of each split.Default:2
mutual_pass (
bool
, optional) – IfTrue
, perform one pass per branch per crop resolution.Default:False
initial_momentum (
int
, optional) – initial value for the momentum update.Default:0.999
scheduler_momentum (
str
, optional) – rule to update the momentum value.Default:'constant'
shuffle_bn (
bool
, optional) – IfTrue
, apply shuffle normalization trick from MoCo.Default:True
num_devices (
int
, optional) – Number of devices used to train the model in each node.Default:1
simulate_n_devices (
int
, optional) – Number of devices to simulate to apply shuffle trick. Requiresshuffle_bn
to beTrue
andnum_devices
to be \(1\).Default:8
queue (
Optional
[DictConfig
], optional) – Config to build a queue.Default:None
sym (
bool
, optional) – IfTrue
, symmetrised the loss.Default:False
use_keys (
bool
, optional) – IfTrue
, add keys to negatives.Default:False
temp (
float
, optional) – Temperature parameter to scale the online similarities.Default:0.2
MoCo v3¶
- class eztorch.models.siamese.MoCov3Model(trunk, optimizer, projector=None, predictor=None, train_transform=None, val_transform=None, test_transform=None, normalize_outputs=True, num_global_crops=2, num_local_crops=0, num_splits=0, num_splits_per_combination=2, mutual_pass=False, initial_momentum=0.99, scheduler_momentum='cosine', temp=1.0)[source]¶
MoCov3 that can be configured as in the paper.
References
MoCov3: https://arxiv.org/abs/2104.02057
- Parameters:
trunk (
DictConfig
) – Config to build a trunk.optimizer (
DictConfig
) – Config to build optimizers and schedulers.projector (
Optional
[DictConfig
], optional) – Config to build a project.Default:None
predictor (
Optional
[DictConfig
], optional) – Config to build a predictor.Default:None
train_transform (
Optional
[DictConfig
], optional) – Config to perform transformation on train input.Default:None
val_transform (
Optional
[DictConfig
], optional) – Config to perform transformation on val input.Default:None
test_transform (
Optional
[DictConfig
], optional) – Config to perform transformation on test input.Default:None
normalize_outputs (
bool
, optional) – IfTrue
, normalize outputs.Default:True
num_global_crops (
int
, optional) – Number of global crops which are the first elements of each batch.Default:2
num_local_crops (
int
, optional) – Number of local crops which are the last elements of each batch.Default:0
num_splits (
int
, optional) – Number of splits to apply to each crops.Default:0
num_splits_per_combination (
int
, optional) – Number of splits used for combinations of features of each split.Default:2
mutual_pass (
bool
, optional) – IfTrue
, perform one pass per branch per crop resolution.Default:False
initial_momentum (
int
, optional) – Initial value for the momentum update.Default:0.99
scheduler_momentum (
str
, optional) – Rule to update the momentum value.Default:'cosine'
temp (