class_docstr: Iterator for alternating between labeled and un-labled dataloaders
  for semi-supervised learning.
  
  Args:
      al_dataset (ActiveLearningDataset): dataset and pool from which to load data.
      batch_size (int):  how many samples per batch to load.
      num_steps (int): number of steps before the end of the iterator.
      p (Optional[float]): probability of selecting a labeled batch.
          If None, the batches alternate.
      shuffle (Optional[bool]): set to ``True`` to have the data reshuffled at every epoch.
      num_workers (Optional[int]): how many subprocesses to use for data loading.
      drop_last (Optional[bool]): set to ``True`` to drop the last incomplete batch.
class_docstr_tok: ["Iterator","for","alternating","between","labeled","and","un-labled","dataloaders","for","semi-supervised","learning",".","Args",":","al_dataset","(","ActiveLearningDataset",")",":","dataset","and","pool","from","which","to","load","data",".","batch_size","(","int",")",":","how","many","samples","per","batch","to","load",".","num_steps","(","int",")",":","number","of","steps","before","the","end","of","the","iterator",".","p","(","Optional","[","float","]",")",":","probability","of","selecting","a","labeled","batch",".","If","None",",","the","batches","alternate",".","shuffle","(","Optional","[","bool","]",")",":","set","to","``","True","``","to","have","the","data","reshuffled","at","every","epoch",".","num_workers","(","Optional","[","int","]",")",":","how","many","subprocesses","to","use","for","data","loading",".","drop_last","(","Optional","[","bool","]",")",":","set","to","``","True","``","to","drop","the","last","incomplete","batch","."]
code: def __init__(
      self,
      al_dataset: ActiveLearningDataset,
      batch_size: int,
      num_steps: Optional[int] = None,
      p: Optional[float] = None,
      shuffle: bool = False,
      num_workers: int = 0,
      drop_last: bool = False,
  ):
      self.al_dataset = al_dataset
      active_dl = DataLoader(
          al_dataset,
          batch_size=batch_size,
          shuffle=shuffle,
          num_workers=num_workers,
          drop_last=drop_last,
      )
      pool_dl: Optional[DataLoader] = None
      if len(al_dataset.pool) > 0:
          pool_dl = DataLoader(
              al_dataset.pool,
              batch_size=batch_size,
              shuffle=shuffle,
              num_workers=num_workers,
              drop_last=drop_last,
          )
  
          if num_steps is None:
              if p is None:
                  # By default num_steps if 2 times the length of active set or less
                  # This allows all the labeled data to be seen during one epoch.
                  num_steps = len(active_dl) + min(
                      len(active_dl), len(pool_dl)
                  )
              else:
                  # Show all labeled data + unlabeled data.
                  num_steps = int(
                      len(active_dl) + len(active_dl) * (1 - p) / p
                  )
      else:
          p = 1
  
      if p == 1:
          # Allows running only supervised training.
          num_steps = len(active_dl)
  
      super().__init__(
          dl_1=active_dl, dl_2=pool_dl, num_steps=num_steps, p=p
      )
  
file_path: baal/baal/utils/ssl_iterator.py
imports: from itertools import cycle
  from typing import Optional, Union, Dict, Sequence, Tuple
  import numpy
  from baal.active import ActiveLearningDataset
  from torch.utils.data import DataLoader
label_desc: Use image node_id 1 to create a new SemiSupervisedIterator object from inherited base classes: AlternateIterator with example: obj = SemiSupervisedIterator(al_dataset, batch_size, num_steps, p, shuffle, num_workers, drop_last)