MoCov2

MoCov2#

class stable_pretraining.methods.MoCov2(encoder_name: str | Module = 'vit_small_patch16_224', projector_dims: Sequence[int] = (2048, 128), queue_length: int = 65536, temperature: float = 0.2, ema_decay_start: float = 0.999, ema_decay_end: float = 0.999, low_resolution: bool = False, pretrained: bool = False)[source]#

Bases: Module

MoCo v2 with a fixed-size FIFO queue of momentum-encoder keys.

Parameters:
  • encoder_name – timm model name or pre-built nn.Module.

  • projector_dims(hidden, output) for the 2-layer head (default (2048, 128); matches MoCo v2’s ResNet50 recipe).

  • queue_length – FIFO key queue size (default 65536).

  • temperature – InfoNCE temperature (default 0.2).

  • ema_decay_start – Initial momentum (default 0.999, paper).

  • ema_decay_end – Final momentum (default 0.999).

  • low_resolution – Adapt first conv for low-res input.

  • pretrained – Load pretrained timm weights.

forward(view1: Tensor, view2: Tensor | None = None) MoCov2Output[source]#

Same as torch.nn.Module.forward().

Parameters:
  • *args – Whatever you decide to pass into the forward method.

  • **kwargs – Keyword arguments are also possible.

Returns:

Your model’s output