class_docstr: To run: "python -m saliency.core.xrai_test" from the top-level directory.
class_docstr_tok: ["To","run",":","``","python","-m","saliency.core.xrai_test","''","from","the","top-level","directory","."]
code: def testCustomSegments(self):
      # Create the first segment.
      rec_1 = sk_draw.rectangle(
          start=(10, 10), end=(30, 30), shape=(IMAGE_SIZE, IMAGE_SIZE)
      )
      seg_1 = np.zeros(shape=(IMAGE_SIZE, IMAGE_SIZE), dtype=bool)
      seg_1[tuple(rec_1)] = True
  
      # Create the second segment.
      rec_2 = sk_draw.rectangle(
          start=(60, 60), end=(100, 100), shape=(IMAGE_SIZE, IMAGE_SIZE)
      )
      seg_2 = np.zeros(shape=(IMAGE_SIZE, IMAGE_SIZE), dtype=bool)
      seg_2[tuple(rec_2)] = True
  
      # Calculate the XRAI attribution.
      xrai_params = XRAIParameters(
          return_xrai_segments=True,
          flatten_xrai_segments=False,
          area_threshold=1.0,
          return_ig_attributions=True,
      )
      xrai_out = self.xrai.GetMaskWithDetails(
          x_value=self.input_image,
          call_model_function=self.call_model_function,
          extra_parameters=xrai_params,
          segments=[seg_1, seg_2],
      )
  
      # Verify correctness of the attribution.
      self._assert_xrai_correctness(xrai_out, is_flatten_segments=False)
  
      # Verify that the segments are ordered correctly, i.e. the segment with
      # higher attribution comes first.
      seg1_attr = self.ig_mask[seg_1].max(axis=1).mean()
      seg2_attr = self.ig_mask[seg_2].max(axis=1).mean()
      if seg1_attr >= seg2_attr:
          self.assertTrue(
              np.array_equal(seg_1, xrai_out.segments[0]),
              msg="The segments might be ordered incorrectly.",
          )
      else:
          self.assertTrue(
              np.array_equal(seg_2, xrai_out.segments[0]),
              msg="The segments might be ordered incorrectly.",
          )
  
      # Three segments are expected. The last segment should include all pixels
      # that weren't included in the first two segments.
      self.assertEqual(
          3,
          len(xrai_out.segments),
          "Unexpected the number of returned segments.",
      )
  
imports: import unittest
  import unittest.mock
  import numpy
  import skimage.draw
  from .None import xrai
  from .xrai import XRAI
  from .xrai import XRAIParameters
label_desc: Use image node_id 7 for calling the XraiTest obj's underlying member method code with example usage: obj.testCustomSegments() without return types