class_docstr: bla
code: def get_sample_fn(self, image, classifier_fn, lime=False):
      import copy
  
      # segments = slic(image, n_segments=100, compactness=20)
      segments = self.segmentation(image)
      fudged_image = image.copy()
      for x in np.unique(segments):
          fudged_image[segments == x] = (
              np.mean(image[segments == x][:, 0]),
              np.mean(image[segments == x][:, 1]),
              np.mean(image[segments == x][:, 2]),
          )
      if self.white is not None:
          fudged_image[:] = self.white
      features = list(np.unique(segments))
      n_features = len(features)
  
      true_label = np.argmax(classifier_fn(np.expand_dims(image, 0))[0])
      print("True pred", true_label)
  
      def lime_sample_fn(num_samples, batch_size=50):
          # data = np.random.randint(0, 2, num_samples * n_features).reshape(
          #     (num_samples, n_features))
          data = np.zeros((num_samples, n_features))
          labels = []
          imgs = []
          sizes = np.random.randint(0, n_features, num_samples)
          all_features = range(n_features)
          # for row in data:
          for i, size in enumerate(sizes):
              row = np.ones(n_features)
              chosen = np.random.choice(all_features, size)
              # print chosen, size,
              row[chosen] = 0
              data[i] = row
              # print row
              temp = copy.deepcopy(image)
              zeros = np.where(row == 0)[0]
              mask = np.zeros(segments.shape).astype(bool)
              for z in zeros:
                  mask[segments == z] = True
              temp[mask] = fudged_image[mask]
              imgs.append(temp)
              if len(imgs) == batch_size:
                  preds = classifier_fn(np.array(imgs))
                  labels.extend(preds)
                  imgs = []
          if len(imgs) > 0:
              preds = classifier_fn(np.array(imgs))
              labels.extend(preds)
          # return imgs, np.array(labels)
          return data, np.array(labels)
  
      if lime:
          return segments, lime_sample_fn
  
      def sample_fn_dummy(present, num_samples, compute_labels=True):
          if not compute_labels:
              data = np.random.randint(
                  0, 2, num_samples * n_features
              ).reshape((num_samples, n_features))
              data[:, present] = 1
              return [], data, []
          data = np.zeros((num_samples, n_features))
          # data = np.random.randint(0, 2, num_samples * n_features).reshape(
          #     (num_samples, n_features))
          if len(present) < 5:
              data = np.random.choice(
                  [0, 1], num_samples * n_features, p=[0.8, 0.2]
              ).reshape((num_samples, n_features))
          data[:, present] = 1
          chosen = np.random.choice(
              range(len(self.dummys)), data.shape[0], replace=True
          )
          labels = []
          imgs = []
          for d, r in zip(data, chosen):
              temp = copy.deepcopy(image)
              zeros = np.where(d == 0)[0]
              mask = np.zeros(segments.shape).astype(bool)
              for z in zeros:
                  mask[segments == z] = True
              if self.white:
                  temp[mask] = 1
              else:
                  temp[mask] = self.dummys[r][mask]
              imgs.append(temp)
              # pred = np.argmax(classifier_fn(temp.to_nn())[0])
              # print self.class_names[pred]
              # labels.append(int(pred == true_label))
          # import time
          # a = time.time()
          imgs = np.array(imgs)
          preds = classifier_fn(imgs)
          # print (time.time() - a) / preds.shape[0]
          imgs = []
          preds_max = np.argmax(preds, axis=1)
          labels = (preds_max == true_label).astype(int)
          raw_data = np.hstack((data, chosen.reshape(-1, 1)))
          return raw_data, data, np.array(labels)
  
      def sample_fn(present, num_samples, compute_labels=True):
          # TODO: I'm sampling in this different way because the way we were
          # sampling confounds size of the document with feature presence
          # (larger documents are more likely to have features present)
          data = np.random.randint(
              0, 2, num_samples * n_features
          ).reshape((num_samples, n_features))
          data[:, present] = 1
          if not compute_labels:
              return [], data, []
          imgs = []
          for row in data:
              temp = copy.deepcopy(image)
              zeros = np.where(row == 0)[0]
              mask = np.zeros(segments.shape).astype(bool)
              for z in zeros:
                  mask[segments == z] = True
              temp[mask] = fudged_image[mask]
              imgs.append(temp)
          preds = classifier_fn(np.array(imgs))
          preds_max = np.argmax(preds, axis=1)
          labels = (preds_max == true_label).astype(int)
          # raw_data = imgs
          raw_data = data
          return raw_data, data, labels
  
      sample = sample_fn if self.hide else sample_fn_dummy
      return segments, sample
  
file_path: anchor/anchor/anchor_image.py
imports: from .None import anchor_base
  import numpy
  import sklearn
label_desc: Use image node_id 2 for calling the AnchorImage obj's underlying member method code with example usage: obj.get_sample_fn(image, classifier_fn, lime) and returns: segments,  sample, data,  np, segments,  lime_sample_fn, raw_data,  data,  np, raw_data,  data,  labels, list,  data,  list, list,  data,  list