code: def generate_patch_data(self, input_data, model=None):
      if self.pad_borders:
          # TODO -- Clean up this border-padding code and make it more readable.
          input_pad_dimensions = [(0, 0)] * input_data.ndim
          repatched_shape = self.output_shape
          new_input_shape = list(input_data.shape)
          for idx, dim in enumerate(self.patch_dimensions):
              # Might not work for odd-shaped patches; check.
              input_pad_dimensions[dim] = (
                  int(self.input_patch_shape[dim] // 2),
                  int(self.input_patch_shape[dim] // 2),
              )
              new_input_shape[dim] += self.input_patch_shape[dim]
          for idx, dim in enumerate(self.output_patch_dimensions):
              repatched_shape[dim] += self.input_patch_shape[dim]
  
          padded_input_data = np.zeros(new_input_shape)
          if self.channels_first:
              input_slice = [slice(None)] * 2 + [
                  slice(
                      self.input_patch_shape[dim] // 2,
                      -self.input_patch_shape[dim] // 2,
                      None,
                  )
                  for dim in self.patch_dimensions
              ]
          else:
              input_slice = (
                  [slice(None)]
                  + [
                      slice(
                          self.input_patch_shape[dim] // 2,
                          -self.input_patch_shape[dim] // 2,
                          None,
                      )
                      for dim in self.patch_dimensions
                  ]
                  + [slice(None)]
              )
          padded_input_data[tuple(input_slice)] = input_data
          input_data = padded_input_data
  
      corner_data_dims = [
          input_data.shape[axis] for axis in self.patch_dimensions
      ]
  
      if self.patch_method == "random":
          if self.check_empty_patch:
              all_corners = np.array(np.nonzero(input_data))[1:-1]
          else:
              all_corners = np.indices(corner_data_dims)
              # There must be a better way to round up to an integer..
              possible_corners_slice = [slice(None)] + [
                  slice(
                      self.input_patch_shape[dim] // 2,
                      -self.input_patch_shape[dim] // 2,
                      None,
                  )
                  for dim in self.patch_dimensions
              ]
              all_corners = all_corners[tuple(possible_corners_slice)]
  
          all_corners = np.reshape(
              all_corners, (all_corners.shape[0], -1)
          ).T
          corner_selection = all_corners[
              np.random.choice(
                  all_corners.shape[0],
                  size=self.patch_num,
                  replace=False,
              ),
              :,
          ]
  
          if self.current_layer is not None:
              output_operation = self.model.get_layer_output_function(
                  self.current_layer
              )
  
          for corner_list_idx in range(
              0, corner_selection.shape[0], self.batch_size
          ):
              print(corner_list_idx, "/", corner_selection.shape[0])
  
              corner_batch = corner_selection[
                  corner_list_idx : corner_list_idx + self.batch_size
              ]
              input_patches = self.grab_patch(input_data, corner_batch)
  
              if self.baseline_mean_intensity:
                  prediction = input_patches
              elif self.current_layer is None:
                  prediction = self.model.predict(input_patches)
              else:
                  prediction = output_operation([input_patches])[0]
  
              prediction = np.mean(
                  prediction, axis=(1, 2, 3), keepdims=True
              )
  
              depadded_corner_batch = np.zeros_like(corner_batch)
              for corner_idx, corner in enumerate(corner_batch):
                  depadded_corner_batch[corner_idx] = [
                      corner[dim] - self.input_patch_shape[dim + 1] // 2
                      for dim in range(corner_batch.shape[1])
                  ]
              # prediction = self.model.predict(input_patches)
  
              self.write_patches_to_hdf5(
                  prediction, depadded_corner_batch
              )
  
          pass
  
      elif self.patch_method == "grid":
          repetition_offsets = [
              np.linspace(
                  0,
                  self.input_patch_shape[axis] - 1,
                  self.patch_overlaps,
                  dtype=int,
              )
              for axis in self.patch_dimensions
          ]
          repatched_image = np.zeros(repatched_shape)
  
          corner_patch_dims = [
              self.output_patch_shape[axis]
              for axis in self.patch_dimensions
          ]
  
          for rep_idx in range(self.patch_overlaps):
              if self.verbose:
                  docker_print(
                      "Predicting patch set",
                      str(rep_idx + 1)
                      + "/"
                      + str(self.patch_overlaps)
                      + "...",
                  )
  
              corners_grid_shape = [slice(None)]
              for dim in range(all_corners.ndim - 1):
                  corners_grid_shape += [
                      slice(
                          repetition_offsets[dim][rep_idx],
                          corner_data_dims[dim],
                          corner_patch_dims[dim],
                      )
                  ]
  
              corners_list = all_corners[tuple(corners_grid_shape)]
              corners_list = np.reshape(
                  corners_list, (corners_list.shape[0], -1)
              ).T
  
              if self.check_empty_patch:
                  corners_list = self.remove_empty_patches(
                      input_data, corners_list
                  )
  
              for corner_list_idx in range(
                  0, corners_list.shape[0], self.batch_size
              ):
                  corner_batch = corners_list[
                      corner_list_idx : corner_list_idx
                      + self.batch_size
                  ]
                  input_patches = self.grab_patch(
                      input_data, corner_batch
                  )
  
                  prediction = self.model.predict(input_patches)
  
                  print(prediction.shape)
                  print(corner_batch)
  
              if rep_idx == 0:
                  output_data = np.copy(repatched_image)
              else:
                  output_data = output_data + (1.0 / (rep_idx)) * (
                      repatched_image - output_data
                  )  # Running Average
  
      # if self.pad_borders:
  
      #     output_slice = [slice(None)] * output_data.ndim  # Weird
      #     for idx, dim in enumerate(self.output_patch_dimensions):
      #         # Might not work for odd-shaped patches; check.
      #         output_slice[dim] = slice(self.input_patch_shape[dim] // 2, -self.input_patch_shape[dim] // 2, 1)
      #     output_data = output_data[tuple(output_slice)]
  
      return
  
imports: import numpy
  import tables
  import os
  import umap
  import matplotlib.pyplot
  import matplotlib
  import scipy.ndimage
  from sklearn.cluster import KMeans
  from deepneuro.outputs.output import Output
  from deepneuro.utilities.util import add_parameter, docker_print, replace_suffix
  from deepneuro.utilities.conversion import save_data
label_desc: Use image node_id 7 for calling the PatchInterpretability obj's underlying member method code with example usage: obj.generate_patch_data(input_data, model) without return types