class_docstr: Custom converter.
class_docstr_tok: ["Custom","converter","."]
docstr: Convert a given batch.
  
  Args:
      batch (list): List of ndarrays.
      device (torch.device): The device to be send.
  
  Returns:
      dict: Dict of converted tensors.
  
  Examples:
      >>> batch = [([np.arange(5), np.arange(3)],
                    [np.random.randn(8, 2), np.random.randn(4, 2)],
                    None, None)]
      >>> conveter = CustomConverter()
      >>> conveter(batch, torch.device("cpu"))
      {'xs': tensor([[0, 1, 2, 3, 4],
                     [0, 1, 2, 0, 0]]),
       'ilens': tensor([5, 3]),
       'ys': tensor([[[-0.4197, -1.1157],
                      [-1.5837, -0.4299],
                      [-2.0491,  0.9215],
                      [-2.4326,  0.8891],
                      [ 1.2323,  1.7388],
                      [-0.3228,  0.6656],
                      [-0.6025,  1.3693],
                      [-1.0778,  1.3447]],
                     [[ 0.1768, -0.3119],
                      [ 0.4386,  2.5354],
                      [-1.2181, -0.5918],
                      [-0.6858, -0.8843],
                      [ 0.0000,  0.0000],
                      [ 0.0000,  0.0000],
                      [ 0.0000,  0.0000],
                      [ 0.0000,  0.0000]]]),
       'labels': tensor([[0., 0., 0., 0., 0., 0., 0., 1.],
                         [0., 0., 0., 1., 1., 1., 1., 1.]]),
       'olens': tensor([8, 4])}
docstr_tok: ["Convert","a","given","batch",".","Args",":","batch","(","list",")",":","List","of","ndarrays",".","device","(","torch.device",")",":","The","device","to","be","send",".","Returns",":","dict",":","Dict","of","converted","tensors",".","Examples",":",">",">",">","batch","=","[","(","[","np.arange","(","5",")",",","np.arange","(","3",")","]",",","[","np.random.randn","(","8",",","2",")",",","np.random.randn","(","4",",","2",")","]",",","None",",","None",")","]",">",">",">","conveter","=","CustomConverter","(",")",">",">",">","conveter","(","batch",",","torch.device","(","``","cpu","''",")",")","{","'xs","'",":","tensor","(","[","[","0",",","1",",","2",",","3",",","4","]",",","[","0",",","1",",","2",",","0",",","0","]","]",")",",","'ilens","'",":","tensor","(","[","5",",","3","]",")",",","'ys","'",":","tensor","(","[","[","[","-0.4197",",","-1.1157","]",",","[","-1.5837",",","-0.4299","]",",","[","-2.0491",",","0.9215","]",",","[","-2.4326",",","0.8891","]",",","[","1.2323",",","1.7388","]",",","[","-0.3228",",","0.6656","]",",","[","-0.6025",",","1.3693","]",",","[","-1.0778",",","1.3447","]","]",",","[","[","0.1768",",","-0.3119","]",",","[","0.4386",",","2.5354","]",",","[","-1.2181",",","-0.5918","]",",","[","-0.6858",",","-0.8843","]",",","[","0.0000",",","0.0000","]",",","[","0.0000",",","0.0000","]",",","[","0.0000",",","0.0000","]",",","[","0.0000",",","0.0000","]","]","]",")",",","'labels","'",":","tensor","(","[","[","0.",",","0.",",","0.",",","0.",",","0.",",","0.",",","0.",",","1",".","]",",","[","0.",",","0.",",","0.",",","1.",",","1.",",","1.",",","1.",",","1",".","]","]",")",",","'olens","'",":","tensor","(","[","8",",","4","]",")","}"]
code: def __call__(self, batch, device=torch.device("cpu")):
      """Convert a given batch.
  
      Args:
          batch (list): List of ndarrays.
          device (torch.device): The device to be send.
  
      Returns:
          dict: Dict of converted tensors.
  
      Examples:
          >>> batch = [([np.arange(5), np.arange(3)],
                        [np.random.randn(8, 2), np.random.randn(4, 2)],
                        None, None)]
          >>> conveter = CustomConverter()
          >>> conveter(batch, torch.device("cpu"))
          {'xs': tensor([[0, 1, 2, 3, 4],
                         [0, 1, 2, 0, 0]]),
           'ilens': tensor([5, 3]),
           'ys': tensor([[[-0.4197, -1.1157],
                          [-1.5837, -0.4299],
                          [-2.0491,  0.9215],
                          [-2.4326,  0.8891],
                          [ 1.2323,  1.7388],
                          [-0.3228,  0.6656],
                          [-0.6025,  1.3693],
                          [-1.0778,  1.3447]],
                         [[ 0.1768, -0.3119],
                          [ 0.4386,  2.5354],
                          [-1.2181, -0.5918],
                          [-0.6858, -0.8843],
                          [ 0.0000,  0.0000],
                          [ 0.0000,  0.0000],
                          [ 0.0000,  0.0000],
                          [ 0.0000,  0.0000]]]),
           'labels': tensor([[0., 0., 0., 0., 0., 0., 0., 1.],
                             [0., 0., 0., 1., 1., 1., 1., 1.]]),
           'olens': tensor([8, 4])}
  
      """
      # batch should be located in list
      assert len(batch) == 1
      xs, ys, spembs, extras = batch[0]
  
      # get list of lengths (must be tensor for DataParallel)
      ilens = (
          torch.from_numpy(np.array([x.shape[0] for x in xs]))
          .long()
          .to(device)
      )
      olens = (
          torch.from_numpy(np.array([y.shape[0] for y in ys]))
          .long()
          .to(device)
      )
  
      # perform padding and conversion to tensor
      xs = pad_list([torch.from_numpy(x).long() for x in xs], 0).to(
          device
      )
      ys = pad_list([torch.from_numpy(y).float() for y in ys], 0).to(
          device
      )
  
      # make labels for stop prediction
      labels = ys.new_zeros(ys.size(0), ys.size(1))
      for i, l in enumerate(olens):
          labels[i, l - 1 :] = 1.0
  
      # prepare dict
      new_batch = {
          "xs": xs,
          "ilens": ilens,
          "ys": ys,
          "labels": labels,
          "olens": olens,
      }
  
      # load speaker embedding
      if spembs is not None:
          spembs = torch.from_numpy(np.array(spembs)).float()
          new_batch["spembs"] = spembs.to(device)
  
      # load second target
      if extras is not None:
          extras = pad_list(
              [torch.from_numpy(extra).float() for extra in extras], 0
          )
          new_batch["extras"] = extras.to(device)
  
      return new_batch
  
imports: import copy
  import json
  import logging
  import math
  import os
  import time
  import chainer
  import kaldiio
  import numpy
  import torch
  from chainer import training
  from chainer.training import extensions
  from espnet.asr.asr_utils import get_model_conf, snapshot_object, torch_load, torch_resume, torch_snapshot
  from espnet.asr.pytorch_backend.asr_init import load_trained_modules
  from espnet.nets.pytorch_backend.nets_utils import pad_list
  from espnet.nets.tts_interface import TTSInterface
  from espnet.utils.dataset import ChainerDataLoader, TransformDataset
  from espnet.utils.deterministic_utils import set_deterministic_pytorch
  from espnet.utils.dynamic_import import dynamic_import
  from espnet.utils.io_utils import LoadInputsAndTargets
  from espnet.utils.training.batchfy import make_batchset
  from espnet.utils.training.evaluator import BaseEvaluator
  from espnet.utils.training.iterators import ShufflingEnabler
  from espnet.utils.training.tensorboard_logger import TensorboardLogger
  from espnet.utils.training.train_utils import check_early_stop, set_early_stop
label_desc: Use image node_id 2 for calling the CustomConverter obj's underlying member method code with example usage: obj.__call__(batch, device) and returns: new_batch