class_docstr: Yields patches from data read from an image dataset.
  Typically used with `PatchIter` or `PatchIterd` so that the patches are chosen in a contiguous grid sampling scheme.
  
   .. code-block:: python
  
      import numpy as np
  
      from monai.data import GridPatchDataset, DataLoader, PatchIter, RandShiftIntensity
  
      # image-level dataset
      images = [np.arange(16, dtype=float).reshape(1, 4, 4),
                np.arange(16, dtype=float).reshape(1, 4, 4)]
      # image-level patch generator, "grid sampling"
      patch_iter = PatchIter(patch_size=(2, 2), start_pos=(0, 0))
      # patch-level intensity shifts
      patch_intensity = RandShiftIntensity(offsets=1.0, prob=1.0)
  
      # construct the dataset
      ds = GridPatchDataset(data=images,
                            patch_iter=patch_iter,
                            transform=patch_intensity)
      # use the grid patch dataset
      for item in DataLoader(ds, batch_size=2, num_workers=2):
          print("patch size:", item[0].shape)
          print("coordinates:", item[1])
  
      # >>> patch size: torch.Size([2, 1, 2, 2])
      #     coordinates: tensor([[[0, 1], [0, 2], [0, 2]],
      #                          [[0, 1], [2, 4], [0, 2]]])
  
  Args:
      data: the data source to read image data from.
      patch_iter: converts an input image (item from dataset) into a iterable of image patches.
          `patch_iter(dataset[idx])` must yield a tuple: (patches, coordinates).
          see also: :py:class:`monai.data.PatchIter` or :py:class:`monai.data.PatchIterd`.
      transform: a callable data transform operates on the patches.
      with_coordinates: whether to yield the coordinates of each patch, default to `True`.
      cache: whether to use cache mache mechanism, default to `False`.
          see also: :py:class:`monai.data.CacheDataset`.
      cache_num: number of items to be cached. Default is `sys.maxsize`.
          will take the minimum of (cache_num, data_length x cache_rate, data_length).
      cache_rate: percentage of cached data in total, default is 1.0 (cache all).
          will take the minimum of (cache_num, data_length x cache_rate, data_length).
      num_workers: the number of worker threads if computing cache in the initialization.
          If num_workers is None then the number returned by os.cpu_count() is used.
          If a value less than 1 is specified, 1 will be used instead.
      progress: whether to display a progress bar.
      copy_cache: whether to `deepcopy` the cache content before applying the random transforms,
          default to `True`. if the random transforms don't modify the cached content
          (for example, randomly crop from the cached image and deepcopy the crop region)
          or if every cache item is only used once in a `multi-processing` environment,
          may set `copy=False` for better performance.
      as_contiguous: whether to convert the cached NumPy array or PyTorch tensor to be contiguous.
          it may help improve the performance of following logic.
      hash_func: a callable to compute hash from data items to be cached.
          defaults to `monai.data.utils.pickle_hashing`.
class_docstr_tok: ["Yields","patches","from","data","read","from","an","image","dataset",".","Typically","used","with","`","PatchIter","`","or","`","PatchIterd","`","so","that","the","patches","are","chosen","in","a","contiguous","grid","sampling","scheme",".","..","code-block",":",":","python","import","numpy","as","np","from","monai.data","import","GridPatchDataset",",","DataLoader",",","PatchIter",",","RandShiftIntensity","#","image-level","dataset","images","=","[","np.arange","(","16",",","dtype=float",")",".reshape","(","1",",","4",",","4",")",",","np.arange","(","16",",","dtype=float",")",".reshape","(","1",",","4",",","4",")","]","#","image-level","patch","generator",",","``","grid","sampling","''","patch_iter","=","PatchIter","(","patch_size=","(","2",",","2",")",",","start_pos=","(","0",",","0",")",")","#","patch-level","intensity","shifts","patch_intensity","=","RandShiftIntensity","(","offsets=1.0",",","prob=1.0",")","#","construct","the","dataset","ds","=","GridPatchDataset","(","data=images",",","patch_iter=patch_iter",",","transform=patch_intensity",")","#","use","the","grid","patch","dataset","for","item","in","DataLoader","(","ds",",","batch_size=2",",","num_workers=2",")",":","print","(","``","patch","size",":","''",",","item","[","0","]",".shape",")","print","(","``","coordinates",":","''",",","item","[","1","]",")","#",">",">",">","patch","size",":","torch.Size","(","[","2",",","1",",","2",",","2","]",")","#","coordinates",":","tensor","(","[","[","[","0",",","1","]",",","[","0",",","2","]",",","[","0",",","2","]","]",",","#","[","[","0",",","1","]",",","[","2",",","4","]",",","[","0",",","2","]","]","]",")","Args",":","data",":","the","data","source","to","read","image","data","from",".","patch_iter",":","converts","an","input","image","(","item","from","dataset",")","into","a","iterable","of","image","patches",".","`","patch_iter","(","dataset","[","idx","]",")","`","must","yield","a","tuple",":","(","patches",",","coordinates",")",".","see","also",":",":","py",":","class",":","`","monai.data.PatchIter","`","or",":","py",":","class",":","`","monai.data.PatchIterd","`",".","transform",":","a","callable","data","transform","operates","on","the","patches",".","with_coordinates",":","whether","to","yield","the","coordinates","of","each","patch",",","default","to","`","True","`",".","cache",":","whether","to","use","cache","mache","mechanism",",","default","to","`","False","`",".","see","also",":",":","py",":","class",":","`","monai.data.CacheDataset","`",".","cache_num",":","number","of","items","to","be","cached",".","Default","is","`","sys.maxsize","`",".","will","take","the","minimum","of","(","cache_num",",","data_length","x","cache_rate",",","data_length",")",".","cache_rate",":","percentage","of","cached","data","in","total",",","default","is","1.0","(","cache","all",")",".","will","take","the","minimum","of","(","cache_num",",","data_length","x","cache_rate",",","data_length",")",".","num_workers",":","the","number","of","worker","threads","if","computing","cache","in","the","initialization",".","If","num_workers","is","None","then","the","number","returned","by","os.cpu_count","(",")","is","used",".","If","a","value","less","than","1","is","specified",",","1","will","be","used","instead",".","progress",":","whether","to","display","a","progress","bar",".","copy_cache",":","whether","to","`","deepcopy","`","the","cache","content","before","applying","the","random","transforms",",","default","to","`","True","`",".","if","the","random","transforms","do","n't","modify","the","cached","content","(","for","example",",","randomly","crop","from","the","cached","image","and","deepcopy","the","crop","region",")","or","if","every","cache","item","is","only","used","once","in","a","`","multi-processing","`","environment",",","may","set","`","copy=False","`","for","better","performance",".","as_contiguous",":","whether","to","convert","the","cached","NumPy","array","or","PyTorch","tensor","to","be","contiguous",".","it","may","help","improve","the","performance","of","following","logic",".","hash_func",":","a","callable","to","compute","hash","from","data","items","to","be","cached",".","defaults","to","`","monai.data.utils.pickle_hashing","`","."]
docstr: yield patches optionally post-processed by transform.
  
  Args:
      src: a iterable of image patches.
      apply_args: other args for `self.patch_transform`.
docstr_tok: ["yield","patches","optionally","post-processed","by","transform",".","Args",":","src",":","a","iterable","of","image","patches",".","apply_args",":","other","args","for","`","self.patch_transform","`","."]
code: def _generate_patches(self, src, **apply_args):
      """
      yield patches optionally post-processed by transform.
  
      Args:
          src: a iterable of image patches.
          apply_args: other args for `self.patch_transform`.
  
      """
      for patch, *others in src:
          out_patch = patch
          if self.patch_transform is not None:
              out_patch = self.patch_transform(patch, **apply_args)
          if (
              self.with_coordinates and len(others) > 0
          ):  # patch_iter to yield at least 2 items: patch, coords
              yield out_patch, others[0]
          else:
              yield out_patch
  
imports: from __future__ import annotations
  import sys
  import warnings
  from collections.abc import Callable, Generator, Hashable, Iterable, Iterator, Mapping, Sequence
  from copy import deepcopy
  from multiprocessing.managers import ListProxy
  from multiprocessing.pool import ThreadPool
  from typing import TYPE_CHECKING
  import numpy
  import torch
  from monai.config import KeysCollection
  from monai.config.type_definitions import NdarrayTensor
  from monai.data.iterable_dataset import IterableDataset
  from monai.data.utils import iter_patch, pickle_hashing
  from monai.transforms import Compose, RandomizableTrait, Transform, apply_transform, convert_to_contiguous
  from monai.utils import NumpyPadMode, ensure_tuple, first, min_version, optional_import
label_desc: Use image node_id 5 for calling the GridPatchDataset obj's underlying member method code with example usage: obj._generate_patches(src) without return types