Contrastive Explanations Method (CEM) applied to MNIST
pip install alibi[tensorflow]import tensorflow as tf
tf.get_logger().setLevel(40) # suppress deprecation messages
tf.compat.v1.disable_v2_behavior() # disable TF2 behaviour as alibi code still relies on TF1 constructs
import tensorflow.keras as keras
from tensorflow.keras import backend as K
from tensorflow.keras.layers import Conv2D, Dense, Dropout, Flatten, MaxPooling2D, Input, UpSampling2D
from tensorflow.keras.models import Model, load_model
from tensorflow.keras.utils import to_categorical
import matplotlib
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import os
from alibi.explainers import CEM
print('TF version: ', tf.__version__)
print('Eager execution enabled: ', tf.executing_eagerly()) # FalseLoad and prepare MNIST data

Define and train CNN model
Define and train auto-encoder

Generate contrastive explanation with pertinent negative


Generate pertinent positive

PreviousContrastive Explanations Method (CEM) applied to Iris datasetNextCounterfactual Instances on MNIST
Last updated
Was this helpful?

