def get_image_and_mask(self, label, positive_only=True, hide_rest=False,
                           num_features=5, min_weight=0.):
        """Init function.

        Args:
            label: label to explain
            positive_only: if True, only take superpixels that contribute to
                the prediction of the label. Otherwise, use the top
                num_features superpixels, which can be positive or negative
                towards the label
            hide_rest: if True, make the non-explanation part of the return
                image gray
            num_features: number of superpixels to include in explanation
            min_weight: TODO

        Returns:
            (image, mask), where image is a 3d numpy array and mask is a 2d
            numpy array that can be used with
            skimage.segmentation.mark_boundaries
        """
        if label not in self.local_exp:
            raise KeyError('Label not in explanation')
        segments = self.segments
        image = self.image
        exp = self.local_exp[label]
        mask = np.zeros(segments.shape, segments.dtype)
        if hide_rest:
            temp = np.zeros(self.image.shape)
        else:
            temp = self.image.copy()
        if positive_only:
            fs = [x[0] for x in exp
                  if x[1] > 0 and x[1] > min_weight][:num_features]
            for f in fs:
                temp[segments == f] = image[segments == f].copy()
                mask[segments == f] = 1
            return temp, mask
        else:
            for f, w in exp[:num_features]:
                if np.abs(w) < min_weight:
                    continue
                c = 0 if w < 0 else 1
                mask[segments == f] = 1 if w < 0 else 2
                temp[segments == f] = image[segments == f].copy()
                temp[segments == f, c] = np.max(image)
                for cp in [0, 1, 2]:
                    if c == cp:
                        continue
                    # temp[segments == f, cp] *= 0.5
            return temp, mask
def get_image_and_mask ( self , label , positive_only = True , hide_rest = False , num_features = 5 , min_weight = 0. ) : if label not in self . local_exp : raise KeyError ( 'Label not in explanation' ) segments = self . segments image = self . image exp = self . local_exp [ label ] mask = np . zeros ( segments . shape , segments . dtype ) if hide_rest : temp = np . zeros ( self . image . shape ) else : temp = self . image . copy ( ) if positive_only : fs = [ x [ 0 ] for x in exp if x [ 1 ] > 0 and x [ 1 ] > min_weight ] [ : num_features ] for f in fs : temp [ segments == f ] = image [ segments == f ] . copy ( ) mask [ segments == f ] = 1 return temp , mask else : for f , w in exp [ : num_features ] : if np . abs ( w ) < min_weight : continue c = 0 if w < 0 else 1 mask [ segments == f ] = 1 if w < 0 else 2 temp [ segments == f ] = image [ segments == f ] . copy ( ) temp [ segments == f , c ] = np . max ( image ) for cp in [ 0 , 1 , 2 ] : if c == cp : continue return temp , mask
Init function.

        Args:
            label: label to explain
            positive_only: if True, only take superpixels that contribute to
                the prediction of the label. Otherwise, use the top
                num_features superpixels, which can be positive or negative
                towards the label
            hide_rest: if True, make the non-explanation part of the return
                image gray
            num_features: number of superpixels to include in explanation
            min_weight: TODO

        Returns:
            (image, mask), where image is a 3d numpy array and mask is a 2d
            numpy array that can be used with
            skimage.segmentation.mark_boundaries