class_docstr: Curated Breast Imaging Subset of DDSM.
class_docstr_tok: ["Curated","Breast","Imaging","Subset","of","DDSM","."]
code: def _generate_examples_patches(
      self,
      patients_data,
      image_size=(1152, 896),
      patch_size=(224, 224),
      num_positive_patches_per_abnormality=10,
      num_background_patches_per_image=10,
  ):
      # Set random seed so that we always get the same patches in each split.
      np.random.seed(0x12345 + len(patients_data))
  
      for _, patient_examples in sorted(patients_data.items()):
          for _, example in sorted(patient_examples.items()):
              # Read the mammography image.
              image = _read_image(
                  example["image"], image_size=image_size
              )
              abnormalities_masks = [
                  _read_image(
                      abnormality["mask"], image_size=image.shape
                  )
                  for abnormality in example["abnormalities"]
              ]
              abnormalities_areas = [
                  np.sum(mask > 0) for mask in abnormalities_masks
              ]
              # Sample positive (abnormal) patches from the given mammography.
              for (
                  abnormality,
                  abnormality_mask,
                  abnormality_area,
              ) in zip(
                  example["abnormalities"],
                  abnormalities_masks,
                  abnormalities_areas,
              ):
                  # Determine label for the given abnormality.
                  if abnormality["pathology"].startswith("MALIGNANT"):
                      benign_or_malignant = "MALIGNANT"
                  else:
                      benign_or_malignant = "BENIGN"
                  if abnormality["type"] == "calc":
                      label = benign_or_malignant + "_CALCIFICATION"
                  elif abnormality["type"] == "mass":
                      label = benign_or_malignant + "_MASS"
                  else:
                      raise ValueError(
                          "Unknown abnormality type: %r"
                          % abnormality["type"]
                      )
                  # Sample positive patches from the given abnormality.
                  for k, patch in enumerate(
                      _sample_positive_patches(
                          image,
                          abnormality["mask"],
                          abnormality_mask,
                          abnormality_area,
                          patch_size,
                          num_positive_patches_per_abnormality,
                      )
                  ):
                      patch_id = "%s/abnorm_%s/patch_%d" % (
                          example["id"],
                          abnormality["id"],
                          k,
                      )
                      record = {
                          "id": patch_id,
                          # Note: TFDS needs the shape to be (?, ?, 1).
                          "image": np.expand_dims(patch, axis=-1),
                          "label": label,
                      }
                      yield patch_id, record
  
              # Sample background patches from the given mammography.
              for k, patch in enumerate(
                  _sample_negative_patches(
                      image,
                      example["image"],
                      abnormalities_masks,
                      abnormalities_areas,
                      patch_size,
                      num_background_patches_per_image,
                  )
              ):
                  id_ = "%s/background_%d" % (example["id"], k)
                  record = {
                      "id": id_,
                      # Note: TFDS needs the shape to be (?, ?, 1).
                      "image": np.expand_dims(patch, axis=-1),
                      "label": "BACKGROUND",
                  }
                  yield id_, record
  
imports: import csv
  import os
  import re
  from absl import logging
  import numpy
  from tensorflow_datasets.core.utils.lazy_imports_utils import tensorflow
  import tensorflow_datasets.public_api
label_desc: Use image node_id 11 for calling the CuratedBreastImagingDDSM obj's underlying member method code with example usage: obj._generate_examples_patches(patients_data, image_size, patch_size, num_positive_patches_per_abnormality, num_background_patches_per_image) without return types