class_docstr: Collator for IJEPA model [0].
  
  Experimental: Support for I-JEPA is experimental, there might be breaking changes
  in the future.
  
  Code inspired by [1].
  
  - [0]: Joint-Embedding Predictive Architecture, 2023, https://arxiv.org/abs/2301.08243
  - [1]: https://github.com/facebookresearch/ijepa
class_docstr_tok: ["Collator","for","IJEPA","model","[","0","]",".","Experimental",":","Support","for","I-JEPA","is","experimental",",","there","might","be","breaking","changes","in","the","future",".","Code","inspired","by","[","1","]",".","-","[","0","]",":","Joint-Embedding","Predictive","Architecture",",","2023",",","https",":","\/\/arxiv.org\/abs\/2301.08243","-","[","1","]",":","https",":","\/\/github.com\/facebookresearch\/ijepa"]
code: def _sample_block_mask(self, b_size, acceptable_regions=None):
      h, w = b_size
  
      def constrain_mask(mask, tries=0):
          """Helper to restrict given mask to a set of acceptable regions"""
          N = max(int(len(acceptable_regions) - tries), 0)
          for k in range(N):
              mask *= acceptable_regions[k]
  
      # --
      # -- Loop to sample masks until we find a valid one
      tries = 0
      timeout = og_timeout = 20
      valid_mask = False
      while not valid_mask:
          # -- Sample block top-left corner
          top = torch.randint(0, self.height - h, (1,))
          left = torch.randint(0, self.width - w, (1,))
          mask = torch.zeros(
              (self.height, self.width), dtype=torch.int32
          )
          mask[top : top + h, left : left + w] = 1
          # -- Constrain mask to a set of acceptable regions
          if acceptable_regions is not None:
              constrain_mask(mask, tries)
          mask = torch.nonzero(mask.flatten())
          # -- If mask too small try again
          valid_mask = len(mask) > self.min_keep
          if not valid_mask:
              timeout -= 1
              if timeout == 0:
                  tries += 1
                  timeout = og_timeout
      mask = mask.squeeze()
      # --
      mask_complement = torch.ones(
          (self.height, self.width), dtype=torch.int32
      )
      mask_complement[top : top + h, left : left + w] = 0
      # --
      return mask, mask_complement
  
imports: import math
  from multiprocessing import Value
  from typing import List, Optional, Tuple, Union
  from warnings import warn
  import torch
  import torch.nn
  import torchvision
  import torchvision.transforms
  from PIL import Image
  from lightly.transforms import GaussianBlur, Jigsaw, RandomSolarization
  from lightly.transforms.random_crop_and_flip_with_grid import RandomResizedCropAndFlip
  from lightly.transforms.rotation import random_rotation_transform
  from lightly.transforms.utils import IMAGENET_NORMALIZE
label_desc: Use image node_id 4 for calling the IJEPAMaskCollator obj's underlying member method code with example usage: obj._sample_block_mask(b_size, acceptable_regions) and returns: mask,  mask_complement