docstr: Override dataloader to insert custom sampler/dataset
docstr_tok: ["Override","dataloader","to","insert","custom","sampler\/dataset"]
code: def make_dataloader(
      self, dataset, stage, ckpt_prefix="dataloader-", **loader_kwargs
  ):
      "Override dataloader to insert custom sampler/dataset"
      if stage == sb.Stage.TRAIN:
          # Create a new dataset each time, this set grows
          if self.sub_stage == SubStage.HISTORICAL:
              dataset = sb.dataio.dataset.DynamicItemDataset(
                  data=dataset,
                  dynamic_items=[enh_pipeline],
                  output_keys=[
                      "id",
                      "enh_sig",
                      "clean_sig",
                      "score",
                      "clean_wav",
                  ],
              )
              samples = round(
                  len(dataset) * self.hparams.history_portion
              )
              samples = max(
                  samples, 1
              )  # Ensure there's at least one sample
          else:
              samples = self.hparams.number_of_samples
  
          # This sampler should give the same samples for D and G
          epoch = self.hparams.epoch_counter.current
  
          # Equal weights for all samples, we use "Weighted" so we can do
          # both "replacement=False" and a set number of samples, reproducibly
          weights = torch.ones(len(dataset))
          replacement = samples > len(dataset)
          sampler = ReproducibleWeightedRandomSampler(
              weights,
              epoch=epoch,
              replacement=replacement,
              num_samples=samples,
          )
          loader_kwargs["sampler"] = sampler
  
          if self.sub_stage == SubStage.GENERATOR:
              self.train_sampler = sampler
  
      # Make the dataloader as normal
      return super().make_dataloader(
          dataset, stage, ckpt_prefix, **loader_kwargs
      )
  
imports: import os
  import sys
  import shutil
  import pickle
  import torch
  import torchaudio
  import speechbrain
  from pesq import pesq
  from enum import Enum, auto
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.utils.metric_stats import MetricStats
  from speechbrain.processing.features import spectral_magnitude
  from speechbrain.nnet.loss.stoi_loss import stoi_loss
  from speechbrain.utils.distributed import run_on_main
  from speechbrain.dataio.sampler import ReproducibleWeightedRandomSampler
label_desc: Use image node_id 14 for calling the MetricGanBrain obj's underlying member method code with example usage: obj.make_dataloader(dataset, stage, ckpt_prefix) and returns: super