class_docstr: This class is intended for the EVAC+ model.
class_docstr_tok: ["This","class","is","intended","for","the","EVAC+","model","."]
docstr: Wrapper function to facilitate prediction of larger dataset.
  
  Parameters
  ----------
  T1 : np.ndarray or list of np.ndarrys
      For a single image, input should be a 3D array.
      If multiple images, it should be a a list or tuple.
  
  affine : np.ndarray (4, 4) or (batch, 4, 4)
      or list of np.ndarrays with len of batch
      Affine matrix for the T1 image. Should have
      batch dimension if T1 has one.
  
  voxsize : np.ndarray or list or tuple, optional
      (3,) or (batch, 3)
      voxel size of the T1 image.
      Default is (1, 1, 1)
  
  batch_size : int, optional
      Number of images per prediction pass. Only available if data
      is provided with a batch dimension.
      Consider lowering it if you get an out of memory error.
      Increase it if you want it to be faster and have a lot of data.
      If None, batch_size will be set to 1 if the provided image
      has a batch dimension.
      Default is None
  
  return_affine : bool, optional
      Whether to return the affine matrix. Useful if the input was a
      file path.
      Default is False
  
  return_prob : bool, optional
      Whether to return the probability map instead of a
      binary mask. Useful for testing.
      Default is False
  
  largest_area : bool, optional
      Whether to exclude only the largest background/foreground.
      Useful for solving minor errors.
      Default is True
  
  Returns
  -------
  pred_output : np.ndarray (...) or (batch, ...)
      Predicted brain mask
  
  affine : np.ndarray (...) or (batch, ...)
      affine matrix of mask
      only if return_affine is True
docstr_tok: ["Wrapper","function","to","facilitate","prediction","of","larger","dataset",".","Parameters","--","--","--","--","--","T1",":","np.ndarray","or","list","of","np.ndarrys","For","a","single","image",",","input","should","be","a","3D","array",".","If","multiple","images",",","it","should","be","a","a","list","or","tuple",".","affine",":","np.ndarray","(","4",",","4",")","or","(","batch",",","4",",","4",")","or","list","of","np.ndarrays","with","len","of","batch","Affine","matrix","for","the","T1","image",".","Should","have","batch","dimension","if","T1","has","one",".","voxsize",":","np.ndarray","or","list","or","tuple",",","optional","(","3",",",")","or","(","batch",",","3",")","voxel","size","of","the","T1","image",".","Default","is","(","1",",","1",",","1",")","batch_size",":","int",",","optional","Number","of","images","per","prediction","pass",".","Only","available","if","data","is","provided","with","a","batch","dimension",".","Consider","lowering","it","if","you","get","an","out","of","memory","error",".","Increase","it","if","you","want","it","to","be","faster","and","have","a","lot","of","data",".","If","None",",","batch_size","will","be","set","to","1","if","the","provided","image","has","a","batch","dimension",".","Default","is","None","return_affine",":","bool",",","optional","Whether","to","return","the","affine","matrix",".","Useful","if","the","input","was","a","file","path",".","Default","is","False","return_prob",":","bool",",","optional","Whether","to","return","the","probability","map","instead","of","a","binary","mask",".","Useful","for","testing",".","Default","is","False","largest_area",":","bool",",","optional","Whether","to","exclude","only","the","largest","background\/foreground",".","Useful","for","solving","minor","errors",".","Default","is","True","Returns","--","--","--","-","pred_output",":","np.ndarray","(","...",")","or","(","batch",",","...",")","Predicted","brain","mask","affine",":","np.ndarray","(","...",")","or","(","batch",",","...",")","affine","matrix","of","mask","only","if","return_affine","is","True"]
code: def predict(
      self,
      T1,
      affine,
      voxsize=(1, 1, 1),
      batch_size=None,
      return_affine=False,
      return_prob=False,
      largest_area=True,
  ):
      r"""
      Wrapper function to facilitate prediction of larger dataset.
  
      Parameters
      ----------
      T1 : np.ndarray or list of np.ndarrys
          For a single image, input should be a 3D array.
          If multiple images, it should be a a list or tuple.
  
      affine : np.ndarray (4, 4) or (batch, 4, 4)
          or list of np.ndarrays with len of batch
          Affine matrix for the T1 image. Should have
          batch dimension if T1 has one.
  
      voxsize : np.ndarray or list or tuple, optional
          (3,) or (batch, 3)
          voxel size of the T1 image.
          Default is (1, 1, 1)
  
      batch_size : int, optional
          Number of images per prediction pass. Only available if data
          is provided with a batch dimension.
          Consider lowering it if you get an out of memory error.
          Increase it if you want it to be faster and have a lot of data.
          If None, batch_size will be set to 1 if the provided image
          has a batch dimension.
          Default is None
  
      return_affine : bool, optional
          Whether to return the affine matrix. Useful if the input was a
          file path.
          Default is False
  
      return_prob : bool, optional
          Whether to return the probability map instead of a
          binary mask. Useful for testing.
          Default is False
  
      largest_area : bool, optional
          Whether to exclude only the largest background/foreground.
          Useful for solving minor errors.
          Default is True
  
      Returns
      -------
      pred_output : np.ndarray (...) or (batch, ...)
          Predicted brain mask
  
      affine : np.ndarray (...) or (batch, ...)
          affine matrix of mask
          only if return_affine is True
  
      """
  
      voxsize = np.array(voxsize)
      affine = np.array(affine)
  
      if isinstance(T1, (list, tuple)):
          dim = 4
          T1 = np.array(T1)
      elif len(T1.shape) == 3:
          dim = 3
          if batch_size is not None:
              logger.warning(
                  "Batch size specified, but not used",
                  "due to the input not having \
                                  a batch dimension",
              )
          batch_size = 1
  
          T1 = np.expand_dims(T1, 0)
          affine = np.expand_dims(affine, 0)
          voxsize = np.expand_dims(voxsize, 0)
      else:
          raise ValueError(
              "T1 data should be a np.ndarray of dimension 3 "
              "or a list/tuple of it"
          )
  
      input_data = np.zeros((128, 128, 128, len(T1)))
      rev_affine = np.zeros((len(T1), 4, 4))
      ori_shapes = np.zeros((len(T1), 3)).astype(int)
  
      # Normalize the data.
      n_T1 = np.zeros(T1.shape)
      for i, T1_img in enumerate(T1):
          n_T1[i] = normalize(T1_img, new_min=0, new_max=1)
          t_img, t_affine, ori_shape = transform_img(
              n_T1[i], affine[i], voxsize[i]
          )
          input_data[..., i] = t_img
          rev_affine[i] = t_affine
          ori_shapes[i] = ori_shape
  
      # Prediction stage
      prediction = np.zeros((len(T1), 128, 128, 128), dtype=np.float32)
      for batch_idx in range(batch_size, len(T1) + 1, batch_size):
          batch = input_data[..., batch_idx - batch_size : batch_idx]
          temp_input = prepare_img(batch)
          temp_pred = self.__predict(temp_input)
          prediction[:batch_idx] = temp_pred
      remainder = np.mod(len(T1), batch_size)
      if remainder != 0:
          temp_input = prepare_img(input_data[..., -remainder:])
          temp_pred = self.__predict(temp_input)
          prediction[-remainder:] = temp_pred
  
      output_mask = []
      for i, T1_img in enumerate(T1):
          output = recover_img(
              prediction[i],
              rev_affine[i],
              voxsize=voxsize[i],
              ori_shape=ori_shapes[i],
              image_shape=T1_img.shape,
          )
          if not return_prob:
              output = np.where(output >= 0.5, 1, 0)
              if largest_area:
                  output = correct_minor_errors(output)
          output_mask.append(output)
  
      if dim == 3:
          output_mask = output_mask[0]
          affine = affine[0]
  
      output_mask = np.array(output_mask)
      affine = np.array(affine)
      if return_affine:
          return output_mask, affine
      else:
          return output_mask
  
imports: import logging
  import numpy
  from dipy.data import get_fnames
  from dipy.testing.decorators import doctest_skip_parser
  from dipy.utils.optpkg import optional_package
  from dipy.align.reslice import reslice
  from dipy.nn.utils import normalize, set_logger_level, transform_img
  from dipy.nn.utils import recover_img, correct_minor_errors
label_desc: Use image node_id 5 for calling the EVACPlus obj's underlying member method code with example usage: obj.predict(T1, affine, voxsize, batch_size, return_affine, return_prob, largest_area) and returns: output_mask,  affine, output_mask