# CoLa-DCE – Concept-guided Latent Diffusion Counterfactual Explanations

Franz Motzkus
Continental AI Lab
Continental Automotive Technologies GmbH
<EMAIL_ADDRESS>
&Christian Hellert
Continental Automotive Technologies GmbH
<EMAIL_ADDRESS>
Ute Schmid
University of Bamberg
<EMAIL_ADDRESS>

###### Abstract

Recent advancements in generative AI have introduced novel prospects and
practical implementations. Especially diffusion models show their strength in
generating diverse and, at the same time, realistic features, positioning them
well for generating counterfactual explanations for computer vision models.
Answering “what if” questions of what needs to change to make an image
classifier change its prediction, counterfactual explanations align well with
human understanding and consequently help in making model behavior more
comprehensible. Current methods succeed in generating authentic
counterfactuals, but lack transparency as feature changes are not directly
perceivable. To address this limitation, we introduce Concept-guided Latent
Diffusion Counterfactual Explanations (CoLa-DCE). CoLa-DCE generates concept-
guided counterfactuals for any classifier with a high degree of control
regarding concept selection and spatial conditioning. The counterfactuals
comprise an increased granularity through minimal feature changes. The
reference feature visualization ensures better comprehensibility, while the
feature localization provides increased transparency of “where” changed
“what”. We demonstrate the advantages of our approach in minimality and
comprehensibility across multiple image classification models and datasets and
provide insights into how our CoLa-DCE explanations help comprehend model
errors like misclassification cases.

Figure 1: Example image of a concept-based counterfactual with CoLa-DCE
consisting of a selection of concepts with reference samples, a localization
map per concept indicating the concept regions, and the generated
counterfactual.

##  1 Introduction

In the field of eXplainable Artificial Intelligence (xAI), counterfactual
explanations have gained new interest with recent advances in generative
models [2, 19, 11]. The usage of counterfactual explanations, answering what
would need to change to induce a different outcome, is motivated by research
in psychology and the social sciences [21, 6], connecting counterfactuals with
human reasoning. While current development efforts in xAI often focus on
technical feasibility rather than on the alignment with human understanding of
a Deep Neural Network (DNN) model [23], counterfactuals provide an opportunity
for the user to contemplate alternative model outputs. In the image domain, a
human inspector can directly compare an original image with its counterfactual
to derive which differences induce a prediction change in the model under
test. Key requirements for the counterfactual to be deemed a plausible
alternative are the consistency with the user’s beliefs, as being realistic,
and a minimal effort for changing towards the counterfactual [6]. The
minimality constraint expresses a more likely transition due to a smaller
image alteration, while additionally, the decision boundary between both
classes can be better estimated.

Specifically for image manipulations, diffusion models have proven to be
advantageous. Diffusion models [16, 8, 27, 17] are capable of generating
realistic high-resolution images with diverse features within the data
distribution, which promotes them as an ideal tool for generating
counterfactual images [2, 11, 19]. While previous works for diffusion-based
image counterfactuals find optimizations with regard to all features in an
image or a local area inside an image, it is often unclear which features
precisely change toward the counterfactual and how they relate to the model
prediction. Especially with many slight feature changes in an image, tracking
the changes and comprehending the decision boundary based on these features
becomes unfeasible. Considering the example of the “hen” in Figure 1, every
part of the animal, e.g., head, feathers, and color, as well as background
features like the flooring, could yield significant changes towards the
counterfactual class without being recognizable to the user. Regarding the
desire for minimality in image alteration, we further point out the yet
missing strategy of defining minimality more semantically in the number of
semantic features rather than pixels changed.

With our Concept-guided Latent Diffusion Counterfactual Explanations (CoLa-
DCE), we solve both problems: We guide the counterfactual generation with a
restricted number of semantic concepts, further enabling a high level of
control by concept selection. We additionally include feature visualization
capabilities, allowing for direct comprehensibility of features that represent
the difference between the original and the counterfactual class. Hereby,
CoLa-DCE provides semantic as well as spatial guidance and visualization,
simultaneously enabling control and better transparency. Our contributions
are:

  1. 1.

We introduce CoLa-DCE for the diffusion-based generation of counterfactuals
using a semantic concept-guidance. We show how local counterfactual targets
and concept-guided feature changes derived from the classifier’s perception
increase the quality of the counterfactuals.

  2. 2.

We extend our concept guidance with spatial conditioning and reveal the
semantic and localized image changes with transferring methods for concept
visualization and concept localization maps, resulting in more transparent and
more comprehensible counterfactuals highlighting the image changes.

  3. 3.

We show how our CoLa-DCE samples help in model debugging by making cases of
misclassification more understandable. The semantic concept visualization
provides strategies for feature-based model and/or dataset adaptations.

The source code will be published at github.com/continental/concept-
counterfactuals.

##  2 Background

Diffusion models [16] evolve from the idea of gradually adding small amounts
of Gaussian noise to an image in a forward process, which can then be
gradually reversed by learning the respective backward process. Given scalar
noise scales ${\alpha_{t}}_{t=1}^{T}$ with $T$ denoting the number of time
steps and an input image $x_{0}$, the noisy image representations $x_{t}$ for
the forward diffusion process can be computed with:

$x_{t}=\sqrt{\alpha_{t}}x_{0}+\sqrt{1-\alpha_{t}}\epsilon_{t},\quad\text{where}\quad\epsilon_{t}\in\mathcal{N}(0,\mathbf{I}).$
(1)

Based on the current noise sample $x_{t}$ and time step $t$, a modified U-Net
[28] can be used for estimating the noise $\hat{\epsilon}_{t}$, which was
added at that time step:

$\epsilon_{\theta}(x_{t},t)\approx\hat{\epsilon}_{t}=\frac{x_{t}-\sqrt{\alpha_{t}}x_{0}}{\sqrt{1-\alpha_{t}}}.$
(2)

The original image $x_{0}$ can be approximately predicted, when rewriting
Equation 2 as:

$\hat{x}_{0}\approx\frac{x_{t}-\sqrt{1-\alpha_{t}}\epsilon_{\theta}(x_{t},t)}{\sqrt{\alpha_{t}}}.$
(3)

Sampling methods like the DDIM sampling [31] speed up the image generation by
estimating multiple timesteps and can be used to sample the next less-noisy
representation $x_{t-1}$:

$x_{t-1}=\sqrt{\alpha_{t-1}}\frac{x_{t}-\sqrt{1-\alpha_{t}}\hat{\epsilon}_{t}}{\sqrt{\alpha_{t}}}+\sqrt{1-\alpha_{t-1}-\sigma_{t}^{2}}\hat{\epsilon}_{t}+\sigma_{t}\epsilon_{t}.$
(4)

Latent diffusion models [27] decrease the dimensionality of the input by
incorporating an additional encoder-decoder architecture. The encoder derives
a dense representation of the data point so that the diffusion process can be
applied in the dense feature space. The generated output is decoded into an
observable image afterward.

For guiding the image generation with an external classifier, [8] introduces
classifier guidance with a scaling factor influencing the trade-off between
the accuracy and diversity of generated images. Classifier-free diffusion
guidance [17] separates the conditioning into an unconditional part and a
conditional part, where the difference between both parts can be used as an
implicit classifier score:

$\nabla_{x}\log p_{\eta}(x|c)=\nabla_{x}\log p(x)+\eta\nabla_{x}\log p(c|x).$
(5)

This gradient-based scoring for guiding the diffusion process by both external
and implicit classifiers can be utilized to constitute the counterfactual
generation by shaping the gradient.

##  3 Related Work

###  3.1 Counterfactual Generation

A number of methods attempt to transfer counterfactual explanations to the
image domain. Counterfactual Visual Explanations (CVE) [13] replaces feature
regions in an image with matching image patches from a distractor image of the
counterfactual class. Other works [29, 3] directly optimize an input image by
minimizing a loss, shifting the classification towards the counterfactual
class while keeping the image changes minimal. SVCE [5] yields further
improvements to the optimization by combining the L1- and L2-norm to acquire a
balance between non-sparse and too-sparse feature changes. However, directly
optimizing the image requires a robust classification model.

DiME [19] introduces diffusion models for generating counterfactuals, where
the classification model guides the diffusion process. However, DiME is
limited to robust classifiers explicitly trained on noisy images. ACE [18] is
a two-step process consisting of computing pre-explanations and refining them.
A localization mask for the most probable feature change is computed before
repainting the image by combining the generated counterfactual within the mask
with the original image outside.

Diffusion Visual Counterfactual Explanations (DVCE) [2] relaxes the constraint
for the classifier to be robust by including an additional adversarially
robust classifier. Aligning the gradients of both models with a cone
projection robustifies the diffusion guidance. However, generated features
might be induced by the robust classifier rather than the original classifier,
decreasing the validity in explaining the original classifier. Latent
Diffusion Counterfactual Explanations (LDCE) [11] overcomes the requirement of
having a robust classifier by constructing a consensus mechanism for aligning
the gradient of the external classifier with the gradient of the implicit
classifier of the diffusion model directly. However, feature changes are hard
to track due to the optimization on all features.

Although the previous works are able to generate realistic counterfactual
images, the resulting counterfactuals lack transparency regarding which
features have been changed and how the change is reflected in the parameters
of the target model. To our knowledge, the image domain has not considered a
concept-based approach that guides feature changes on a semantic concept level
and enforces minimality by restricting the number of feature changes. Concept-
based counterfactuals yield the opportunity to improve transparency and
comprehensibility for the user while being semantically more similar to the
original image.

###  3.2 Local Concept Attribution

Layer-wise Relevance Propagation (LRP) [4] describes a local attribution
method that backpropagates a modified gradient to assign pixel-wise importance
scores for an input based on a selected target class. Concept-wise Relevance
Propagation (CRP) [1] extends LRP to the concept space by defining the
encoding of every single neuron or channel in the latent space as a concept.
During the attribution backward pass, a concept mask is applied, which filters
the attribution for a single channel so that only the attribution for the
selected channel is retained. When inspecting the channel-constrained
explanations for multiple samples, denoted as Relevance Maximization [1], a
semantic meaning describing a concept can be assigned to the channel. Our
approach utilizes the generalization of the latent space masking for a
gradient manipulation and applies Relevance Maximization to visualize the
determining concepts.

##  4 Concept-guided Latent Diffusion Counterfactual Explanations

Figure 2: A simplified overview of the model architecture for our CoLa-DCE
approach, including the target selection (right) and the concept-conditioning
for guiding the diffusion denoising (middle).

Our CoLa-DCE method consists of three main improvements to current diffusion-
based image counterfactual methods. In step 1, local sample-based targets are
derived based on the model perception. Step 2 consists of concept conditioning
to guide the image adaptation using a selection of concepts, while step 3 adds
spatial conditioning to the selected concepts. Thus, concept and spatial
conditioning selectively modify the classifier gradient before conditioning
the diffusion generation process.

###  4.1 Local Counterfactual Targets

To select the counterfactual target class, we use the model’s perception of
the respective data sample and compare it to the perception of a reference
dataset $X^{\prime}$.The model perception can hereby be derived by either
computing the activation of the model for each sample in a selected layer or
by computing the intermediate attribution using a local xAI method like LRP
[4]. As the model perception of the data shall be represented, the class
predictions of the model are used to determine class affiliation.

$y_{c}=f(argmin_{x^{\prime}\in
X^{\prime}}d(\kappa(x^{\prime}),\kappa(\hat{x}))\quad\text{and}\quad
f(x^{\prime})\neq f(\hat{x}))$ (6)

For a new sample $\hat{x}\in\hat{X}$ that we want to generate a counterfactual
for, we derive the model prediction and feature space encoding
$\kappa(\hat{x})$ and compare it to the encodings of the reference dataset.
Hereby, based on the feature space encodings, the closest reference point with
a differing class prediction is extracted, resembling the near miss approach
[26]. The counterfactual target $y_{c}$ is then defined as the predicted class
of the reference point $x^{\prime}$.

Algorithm 1 CoLa-DCE algorithm for sample $x_{i}$ with $k$ concepts and class
condition $c$

$\hat{y}\leftarrow NearMiss(x_{i})$ # Compute counterfactual target

$grad\leftarrow\nabla_{x}p(x|\hat{y})$ # Compute gradient to counterfactual

$\lambda_{0}$ … $\lambda_{k}\leftarrow topk(grad,k)$ # Extract k most-
important concepts

$\theta_{0}$ … $\theta_{k}\leftarrow get\\_masks(\lambda_{0},...,\lambda_{k})$
# Compute concept (and spatial) constraints

for t=T,…,0 do

$cls\\_score\leftarrow\sqrt{1-\alpha_{t}}\nabla_{z_{t}}L(f(\hat{x}_{0}|\hat{y},\theta_{1}...\theta_{k}),c)$
# Apply LDCE with constraints

$z_{t-1}\leftarrow ApplyLDCE(cls\\_score)$

end for

$x_{i}^{CF}\leftarrow\mathcal{D}(z_{0})$ # Decode reconstruction

###  4.2 Concept Selection

For a selected counterfactual target class $y$, the gradient
$\nabla_{x}p(x|y)$ of a sample $x$ can be extracted in each network layer. For
the selected layer $l$, the intermediate gradient is summed over the spatial
dimensions to obtain a one-dimensional representation over the channels, which
are expected to encode a particular concept each [1]. Taking the absolute
value of the summed gradients, the top-$k$ concepts with
$k\in\mathcal{N}(1,K)$, and $K$ denoting the overall number of channels, are
selected, which are per gradient most likely to induce a change towards the
counterfactual class. The concepts can be visualized using a feature
visualization method like CRP [1].

###  4.3 Concept Conditioning

Based on the LDCE [11] algorithm, we apply an additional concept conditioning
functionality concerning the selected concepts. The conditions require
precomputation and remain fixed during the counterfactual generation, as
adapting the conditions to each single generation step leads to changing
concepts in each step.

Instead of using the complete gradient of the external classifier
$\nabla_{x}p(x|y)$ for target $y$, the conditioned gradient with regards to
the selected concepts $\lambda_{1}$, …,$\lambda_{k}$ with binary constraints
$\theta_{1}$, …, $\theta_{k}$ is computed. With the selected layer $l$
splitting the model into two parts $p(x|y)=h(g(x|y)|y)$, the conditioned
gradient is computed as:

$\displaystyle\nabla_{x}p(x|y,\theta_{1}...\theta_{k})$
$\displaystyle=\nabla_{x}(h(g(x))|y,\theta_{1}...\theta_{k})$ (7)
$\displaystyle=\delta(\nabla_{g(x)}h,\theta_{1}...\theta_{k})\cdot\nabla_{x}g$
$\displaystyle\text{with}\quad\delta(\nabla_{g(x)}h,\theta_{1}...\theta_{k})_{j}$
$\displaystyle=\begin{cases}\nabla_{g(x)}h_{j},&\text{if
}j\in\\{\theta_{1},...,\theta_{k}\\}\\\ 0,&\text{otherwise}\end{cases}$

with $\delta$ indicating binary masking the latent space gradient in the
selected layer. The masked latent gradient can be backpropagated to the input
without further constraints.

###  4.4 Spatial Conditioning

While the introduced concept conditioning focuses on semantic features that
need to change, the spatial dimensions in the feature layer of choice state
where the selected features are most likely to change. We assume that each
feature should be only changed at a single location or that the gradient
towards these features is approximately equal in equivalent locations.
Therefore, we add binary masking to the spatial dimensions similar to Equation
7 based on the gradient for the selected features, which sets gradients below
a threshold $\eta$ to zero. The binary mask can additionally be upscaled to
the input scale like in Net2Vec [12], yielding additional information about
where a specific concept is expected to change towards the counterfactual. The
spatial conditioning minimizes the feature change by restricting it locally
while contributing to comprehensibility by providing feature localization.

##  5 Results

We test our approach on the ImageNet [7] validation dataset using multiple
pre-trained models provided by Torchvision: a VGG16 [30] with and without
batch normalization, a ResNet18 [14], and a ViT model [9]. For deriving
appropriate targets, 90% of the validation data is used as a reference
dataset, while counterfactuals for the evaluation are generated on the
remaining 1000 samples, including all ImageNet classes. We inherit the
parametrization parameters from LDCE [11]. Showing the applicability to
different datasets, additional counterfactuals for Oxford Pets [25] and
Flowers [24] can be found in Appendix A.3.

As there exists no ground truth for counterfactual examples, a rough estimate
regarding the quality can only be assessed via quantifying desired properties
as the minimality and the accuracy. We align our evaluation with [11] and
compute the FID score [15] as well as the L1 and L2 norm between the original
and counterfactual image to measure their semantic and pixel-based distance,
denoting the minimality. The flip ratio (FR) determines the accuracy by
measuring how often the classifier predicts the counterfactual class for the
generated sample.

As an additional optimization measure, we suspend the concept conditioning for
the last 50 generation steps of the diffusion process. While coarse semantic
features are expected to be generated within the first steps of the diffusion
process, the last steps incorporate an image refinement, e.g., by completing
and connecting edges. When suspending the conditioning towards the end of the
generation, visible semantic changes are not perceivable, but the image is
classified more accurately. This can also be seen in a consistent FID score
and an improved flip ratio.

###  5.1 Selecting a local target results in improved counterfactuals

Table 1: Quantitative comparison showing the effect of the target selection on the generated counterfactuals using the LDCE method in comparison to our CoLa-DCE method ($k$=20). Model Setting |  |  |  |
---|---|---|---|---
Model | Method | Target | Layer | FID $\downarrow$ | L1 $\downarrow$ | Flip Ratio $\uparrow$ | Confidence $\uparrow$
VGG16bn | LDCE | Base | - | 55.46 | 12458 | 0.851 | 0.81
VGG16bn | LDCE | Act | feat.37 | 59.12 | 12456 | 0.936 | 0.89
VGG16bn | LDCE | Attr | feat.37 | 45.56 | 12443 | 0.956 | 0.92
VGG16bn | CoLa-DCE | Attr | feat.37 | 44.43 | 13915 | 0.821 | 0.81
ResNet18 | LDCE | Base | - | 55.86 | 12518 | 0.846 | 0.79
ResNet18 | LDCE | Act | 4.1.c1 | 57.46 | 12502 | 0.96 | 0.91
ResNet18 | LDCE | Attr | 4.1.c1 | 46.28 | 12465 | 0.957 | 0.91
ResNet18 | CoLa-DCE | Attr | 4.1.c1 | 44.86 | 13933 | 0.846 | 0.84
ViT | LDCE | Base | - | 59.48 | 12533 | 0.833 | 0.81
ViT | LDCE | Act | encoder | 53.75 | 14024 | 0.913 | 0.88
ViT | LDCE | Attr | encoder | 53.24 | 14028 | 0.917 | 0.89
ViT | CoLa-DCE | Attr | encoder | 53.21 | 14003 | 0.847 | 0.83

While LDCE [11] uses WordNet [22] to derive counterfactual targets based on
the semantic similarity between labels, we suggest using the classifier’s
perception of the local input. Selecting a target layer, the classifier-
internal representation of a data point can be extracted via the activation or
the attribution using a local xAI method. Based on the encodings of a
reference dataset, the sample with minimal distance and differing class
prediction to the encoded target sample is extracted. It’s prediction is
chosen as counterfactual target. The approach is related to the concept of
near misses [26].

Table 1 shows the influence of the target selection on the generated samples’
quantitative performance metrics. Choosing a local (sample-based)
counterfactual target on a near-miss basis leads to an improved flip ratio and
confidence in all settings, demonstrating a nearer decision boundary and more
superficial change between the original and target class. However, retrieving
the target via the activation may lead to a slightly increased FID compared to
the baseline, as some counterfactual targets have no semantic connection to
the original class. Thus, a more substantial semantic change is required.
Using the intermediate LRP [4] attribution yields substantial improvements in
the minimal change needed while simultaneously achieving high flip ratios.
This indicates semantically similar counterfactuals close to the original
images. Including the model’s classification in the intermediate attribution
rather than only considering the activation up to the selected layer may
better represent how the features in the layer are connected toward the
output, comprising top-level semantics between classes. Thus, fewer feature
changes are necessary. Including the results of our CoLa-DCE method, even
closer counterfactuals are generated with flip ratios on par with the LDCE
baseline. Reconsidering the hard constraint on the number of concepts, damping
the gradient signal, CoLa-DCE yields much more transparent counterfactuals
while still being competitive to the baseline.

###  5.2 The number of concepts is a tradeoff between accuracy and
comprehensibility

Since a counterfactual explanation should depict the minimal semantic change
in an image that causes a classifier to change its prediction, we assume that
the minimal semantic change can be expressed by the number of changed features
or concepts. While generally concept-based approaches in xAI mostly use a
handful of concepts for best comprehensibility [32, 1, 10, 20], restricting
the latent space gradient in our case from multiple hundred to very few
channels significantly reduces the gradient for guiding the diffusion process.
We perform a quantitative study to assess how the number of concepts
influences the performance in obtaining reliable results regarding accuracy
and minimality.

(a) Tradeoff between FID and Flip Ratio

(b) CoLa-DCE Model Comparison

Figure 3: Quantitative evaluation for specifying the tradeoff between the
number of concepts and the quantitative measures as flip ratio and FID. The
results in 3(a) are derived for the VGG16bn with target layer feat.40.

Figure 4: CoLa-DCE explanations (“water ouzel” to “red-backed sandpiper”) with
a differing number of concepts $k$ and and the VGG16bn with concept layer 40.
Limiting the concept number induces more fine-grained feature perturbations
than the baseline LDCE, flipping the shown bird completely.

Figure 3 depicts the relationship between the number of concepts, the FID
similarity, and the flip ratio. Restricting the number of concepts leads to an
improved FID (minor change) while the flip ratio decreases. The restriction of
the gradient causes the image to change in fewer features, but the force
pushing the sample towards the counterfactual class is also attenuated.
However, a good performance >75% regarding the flip ratio can already be
achieved with only ten concepts, while the FID score outperforms the baseline.
Thus, CoLa-DCE offers concept-based transparency and control without losing
much detail or accuracy. Figure 3(b) depicts the tradeoff between minimality
and accuracy for multiple model architectures and settings. Adding spatial
constraints per concept results in slightly degraded flip ratios, compensated
by an improved FID. Figure 4 shows an example of how the number of concepts
influences the counterfactual generation. Restricting the concepts leads to
minor changes that alter the target object semantically. In contrast, multiple
hundred concepts and the LDCE baseline induce an alteration of the image
composition by, e.g., generating new objects like the vertically flipped bird
evolving from the upper part of the original bird.

###  5.3 Spatial constraints per concept improve the focus

Figure 5: Comparison of the counterfactual images and their explanations for
LDCE and our proposed method CoLa-DCE w/o and with spatial constraints.

Assuming each feature is locally restricted and may only be modified in the
most probable region(s), we add spatial constraints per concept by
thresholding the gradient. Considering the example of Figure 1, image
modifications towards the cockscomb are only reasonable near the head of the
hen so that the concept-based gradient can be set to zero in all other
regions. Figure 5 shows the difference in the generated counterfactuals for
the spatial conditioning and basic CoLa-DCE compared to the LDCE baseline.
Compared to LDCE, CoLa-DCE yields much more sparse explanations, highlighting
fewer and more concentrated feature changes in the image. With added spatial
constraints, a stronger focus in the explanation becomes apparent, either
having more sparse explanations or reflecting a stronger focus on single
semantic features. Performance-wise, the spatial conditioning further
decreases the FID for the better, while only slight drawbacks regarding the
flip ratio occur.

###  5.4 How can concept-based counterfactuals help in explaining model
failures?

Counterfactuals are especially useful when explaining samples at the
classifier’s decision boundary between two classes. When misclassified samples
and their correctly classified counterfactuals are inspected using our CoLa-
DCE approach, the root cause of the misclassification in terms of identified
or missing features becomes apparent. Figure 6 describes a misclassification
case where the original image lacks specific evidence of belonging to the
label “brambling”. The sample seems to represent a rare case of the class
where the classifier is missing essential concepts shown in the CoLa-DCE
explanation for a correct classification. Hence, a dataset or model adaptation
is required.

Figure 6: A CoLa-DCE explanation for a misclassified sample, which the VGG16bn
classifies as “Junco, Snowbird”. To classify the input correctly as
“Brambling”, the orange chest color, a slightly different feather pattern, and
a gray-blueish head color are missing. Besides, the head and beacon shall look
less similar to the class “Junco, Snowbird”.

###  5.5 Validity: Do the concepts align with the image modifications towards
the counterfactual?

Testing the validity of our approach considering the selected concepts, we
review whether the change from the original to the counterfactual image
targets the selected concepts. The difference in the intermediate attributions
of both original and counterfactual images signifies the difference in the
importance of the concepts for the respective predictions. We assume the
channels with the highest difference to align with the $k$ selected concepts.
For estimating the relative alignment, we compute the ratio of the difference
$|attr_{counterfactual}-attr_{original}|$ for the selected concepts to the
top-$k$ values. The same ratio with $k$ randomly selected concepts is computed
for comparison. The results in Figure 7 clearly validate the concept-based
approach, as the meaningful change towards the counterfactual can evidently be
assigned to the selected concepts for both the VGG16bn and the ResNet18. Due
to the redundancy of similar feature encodings in computer vision models, a
change in one feature is expected to influence multiple channels in the latent
space. Thus, it is reasonable that the selected features do not perfectly
align with the top-$k$ concepts with the highest attribution difference.

(a) VGG16bn

(b) ResNet18

Figure 7: The validity evaluation computes the ratio of attribution difference
between counterfactual and original image for the selected concepts concerning
the concepts with strongest attribution difference. A $1.0$ ratio describes
the optimal fit of selected concepts. Our CoLa-DCE method shows a strong
connection between selected concepts and modified concept attribution.

##  6 Limitations

The main limitation of our CoLa-DCE approach is its reliance on a well-trained
diffusion model that can accurately reconstruct an image and match the concept
information derived by the external classifier. Like in LDCE, multiple
parameters adjusting the influence of the external gradient to the
reconstruction accuracy require fine-tuning for an optimal result. They
optimize between a minimal image deviation and a maximal flip ratio. It
provides an opportunity for individual optimization but requires an exhaustive
parameter search.

##  7 Conclusion

Our CoLa-DCE method generating concept-guided counterfactuals successfully
tackles the lack of transparency and fine-grained control in current
diffusion-based counterfactual generation methods. Starting from an improved
target selection incorporating the models’ perception, we show how our
concept-based approach yields semantically smaller image changes qualitatively
and quantitatively, enforcing the minimality requirement. With the additional
level of control by selecting concepts and adding spatial constraints per
concept, the counterfactual generation is more focused on small, localized
feature perturbations in the image. At the same time, the image alterations
are more locally confined and comprehensible due to the concept grounding.
From our CoLa-DCE explanations, it is directly deducible which feature changes
at which location cause the prediction change of the classifier, strongly
improving the transparency and understandability to a human user. With the
high degree of control in generating images with CoLa-DCE, we are confident to
induce further work using fine-grained concept guidance for image alteration
tasks.

## Acknowledgement

We thank Simon Schrodi for helpful discussions. Further, we thank Marius
Kaestingschaefer, Kostadin Cholakov and Andreas Gilson for their valuable
feedback.

## References

  * [1] Achtibat, R., Dreyer, M., Eisenbraun, I., Bosse, S., Wiegand, T., Samek, W., and Lapuschkin, S. From attribution maps to human-understandable explanations through concept relevance propagation.  Nat. Mac. Intell. 5, 9 (2023), 1006–1019.
  * [2] Augustin, M., Boreiko, V., Croce, F., and Hein, M. Diffusion visual counterfactual explanations.  In Advances in Neural Information Processing Systems (2022), S. Koyejo, S. Mohamed, A. Agarwal, D. Belgrave, K. Cho, and A. Oh, Eds., vol. 35, Curran Associates, Inc., pp. 364–377.
  * [3] Augustin, M., Meinke, A., and Hein, M. Adversarial robustness on in- and out-distribution improves explainability.  In Computer Vision – ECCV 2020 (Cham, 2020), A. Vedaldi, H. Bischof, T. Brox, and J.-M. Frahm, Eds., Springer International Publishing, pp. 228–245.
  * [4] Bach, S., Binder, A., Montavon, G., Klauschen, F., Müller, K.-R., and Samek, W. On pixel-wise explanations for non-linear classifier decisions by layer-wise relevance propagation.  PLOS ONE 10, 7 (07 2015), 1–46.
  * [5] Boreiko, V., Augustin, M., Croce, F., Berens, P., and Hein, M. Sparse visual counterfactual explanations in image space.  In Pattern Recognition (Cham, 2022), B. Andres, F. Bernard, D. Cremers, S. Frintrop, B. Goldlücke, and I. Ihrke, Eds., Springer International Publishing, pp. 133–148.
  * [6] Byrne, R. M. J. Précis of the rational imagination: How people create alternatives to reality.  Behavioral and Brain Sciences 30, 5–6 (2007), 439–453.
  * [7] Deng, J., Dong, W., Socher, R., Li, L.-J., Li, K., and Fei-Fei, L. ImageNet: A Large-Scale Hierarchical Image Database.  In CVPR09 (2009).
  * [8] Dhariwal, P., and Nichol, A. Diffusion models beat gans on image synthesis.  In Advances in Neural Information Processing Systems (2021), M. Ranzato, A. Beygelzimer, Y. Dauphin, P. Liang, and J. W. Vaughan, Eds., vol. 34, Curran Associates, Inc., pp. 8780–8794.
  * [9] Dosovitskiy, A., Beyer, L., Kolesnikov, A., Weissenborn, D., Zhai, X., Unterthiner, T., Dehghani, M., Minderer, M., Heigold, G., Gelly, S., Uszkoreit, J., and Houlsby, N. An image is worth 16x16 words: Transformers for image recognition at scale.  In International Conference on Learning Representations (2021).
  * [10] Dreyer, M., Achtibat, R., Wiegand, T., Samek, W., and Lapuschkin, S. Revealing hidden context bias in segmentation and object detection through concept-specific explanations.  In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) Workshops (June 2023), pp. 3829–3839.
  * [11] Farid, K., Schrodi, S., Argus, M., and Brox, T. Latent diffusion counterfactual explanations, 2023.
  * [12] Fong, R., and Vedaldi, A. Net2vec: Quantifying and explaining how concepts are encoded by filters in deep neural networks.  In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR) (June 2018).
  * [13] Goyal, Y., Wu, Z., Ernst, J., Batra, D., Parikh, D., and Lee, S. Counterfactual visual explanations.  In Proceedings of the 36th International Conference on Machine Learning (09–15 Jun 2019), K. Chaudhuri and R. Salakhutdinov, Eds., vol. 97 of Proceedings of Machine Learning Research, PMLR, pp. 2376–2384.
  * [14] He, K., Zhang, X., Ren, S., and Sun, J. Deep residual learning for image recognition.  In 2016 IEEE Conference on Computer Vision and Pattern Recognition (CVPR) (2016), pp. 770–778.
  * [15] Heusel, M., Ramsauer, H., Unterthiner, T., Nessler, B., and Hochreiter, S. Gans trained by a two time-scale update rule converge to a local nash equilibrium.  In Advances in Neural Information Processing Systems (2017), I. Guyon, U. V. Luxburg, S. Bengio, H. Wallach, R. Fergus, S. Vishwanathan, and R. Garnett, Eds., vol. 30, Curran Associates, Inc.
  * [16] Ho, J., Jain, A., and Abbeel, P. Denoising diffusion probabilistic models.  In Advances in Neural Information Processing Systems (2020), H. Larochelle, M. Ranzato, R. Hadsell, M. Balcan, and H. Lin, Eds., vol. 33, Curran Associates, Inc., pp. 6840–6851.
  * [17] Ho, J., and Salimans, T. Classifier-free diffusion guidance, 2022.
  * [18] Jeanneret, G., Simon, L., and Jurie, F. Adversarial counterfactual visual explanations.  In 2023 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) (2023), pp. 16425–16435.
  * [19] Jeanneret, G., Simon, L., and Jurie, F. Diffusion models for counterfactual explanations.  In Computer Vision – ACCV 2022 (Cham, 2023), L. Wang, J. Gall, T.-J. Chin, I. Sato, and R. Chellappa, Eds., Springer Nature Switzerland, pp. 219–237.
  * [20] Kim, S. S. Y., Watkins, E. A., Russakovsky, O., Fong, R., and Monroy-Hernández, A. "help me help the ai": Understanding how explainability can support human-ai interaction.  In Proceedings of the 2023 CHI Conference on Human Factors in Computing Systems (New York, NY, USA, 2023), CHI ’23, Association for Computing Machinery.
  * [21] Lewis, D. Counterfactuals and comparative possibility.  Journal of Philosophical Logic 2 (1973), 418–446.
  * [22] Miller, G. A. Wordnet: a lexical database for english.  Commun. ACM 38, 11 (nov 1995), 39–41.
  * [23] Miller, T., Howe, P., and Sonenberg, L. Explainable AI: beware of inmates running the asylum or: How I learnt to stop worrying and love the social and behavioural sciences.  CoRR abs/1712.00547 (2017).
  * [24] Nilsback, M.-E., and Zisserman, A. Automated flower classification over a large number of classes.  In Indian Conference on Computer Vision, Graphics and Image Processing (Dec 2008).
  * [25] Parkhi, O. M., Vedaldi, A., Zisserman, A., and Jawahar, C. V. Cats and dogs.  In IEEE Conference on Computer Vision and Pattern Recognition (2012).
  * [26] Rabold, J., Siebers, M., and Schmid, U. Generating contrastive explanations for inductive logic programming based on a near miss approach.  Machine Learning 111, 5 (May 2022), 1799–1820.
  * [27] Rombach, R., Blattmann, A., Lorenz, D., Esser, P., and Ommer, B. High-resolution image synthesis with latent diffusion models.  In 2022 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) (2022), pp. 10674–10685.
  * [28] Ronneberger, O., Fischer, P., and Brox, T. U-net: Convolutional networks for biomedical image segmentation.  In Medical Image Computing and Computer-Assisted Intervention – MICCAI 2015 (Cham, 2015), N. Navab, J. Hornegger, W. M. Wells, and A. F. Frangi, Eds., Springer International Publishing, pp. 234–241.
  * [29] Santurkar, S., Ilyas, A., Tsipras, D., Engstrom, L., Tran, B., and Madry, A. Image synthesis with a single (robust) classifier.  In Advances in Neural Information Processing Systems (2019), H. Wallach, H. Larochelle, A. Beygelzimer, F. d'Alché-Buc, E. Fox, and R. Garnett, Eds., vol. 32, Curran Associates, Inc.
  * [30] Simonyan, K., and Zisserman, A. Very deep convolutional networks for large-scale image recognition.  In 3rd International Conference on Learning Representations, ICLR 2015, San Diego, CA, USA, May 7-9, 2015, Conference Track Proceedings (2015), Y. Bengio and Y. LeCun, Eds.
  * [31] Song, J., Meng, C., and Ermon, S. Denoising diffusion implicit models.  In International Conference on Learning Representations (2021).
  * [32] Zhang, R., Madumal, P., Miller, T., Ehinger, K. A., and Rubinstein, B. I. P. Invertible concept-based explanations for cnn models with non-negative concept activation vectors.  Proceedings of the AAAI Conference on Artificial Intelligence 35, 13 (May 2021), 11682–11690.

##  Appendix A Appendix / supplemental material

###  A.1 Implementation Details

The implementation of CoLa-DCE is based on the LDCE [11] implementation, which
is available on GitHub https://github.com/lmb-freiburg/ldce. Adaptations have
mainly been made to the scoring function, deriving the gradient-based guidance
for the diffusion model. For computing concept patches to visualize the
concepts, the CRP [1] implementation from https://github.com/rachtibat/zennit-
crp has been used. For optimization, the concept conditioning is relaxed in
the last 50 steps of the diffusion generation to use the complete gradient for
image refinement. To our knowledge, no semantic change in the image can be
perceived, while mainly low-level features such as edges are refined. The
parametrization in our experiments is not model-specific. It is based on the
proposed parametrization in LDCE [11] with only the lp-dist parameter changed
to 0.01, as a high value might result in significant features being removed
again during the diffusion process. Optimizing the parameters based on the
used model is expected to affect the generated counterfactuals positively. Our
implementation for CoLa-DCE is accessible at github.com/continental/concept-
counterfactuals.

On ImageNet, one run of the CoLa-DCE code for a single set of parameters and
1000 images on a NVIDIA RTX A5000 takes approximately 16 hours with a batch
size of 4. A single generation step takes slightly less than 3 minutes on the
same hardware. The code should be similarly efficient as the LDCE code from
their GitHub.

###  A.2 Models and Datasets

The following datasets and models have been used in this paper. Images in the
main paper originate from the ImageNet dataset.

Dataset | License | URL
---|---|---
ImageNet [7] | Custom | https://www.image-net.org/index.php
Oxford Flowers 102 [24] | GNU | https://www.robots.ox.ac.uk/vgg/data/flowers/102/
Oxford-IIIT Pet [25] | CC BY-SA 4.0 | https://www.robots.ox.ac.uk/vgg/data/pets/
Table 2: Dataset Specification

Model License URL VGG16 BSD 3
https://pytorch.org/vision/stable/models/vgg.html VGG16bn BSD 3
https://pytorch.org/vision/stable/models/vgg.html ResNet18 BSD 3
https://pytorch.org/vision/stable/models/resnet.html ViT-B-16 BSD 3
https://pytorch.org/vision/stable/models/vision_transformer.html class-
conditional LDM [27] MIT https://github.com/CompVis/latent-diffusion miniSD
(Pinkney, 2023) Open RAIL-M https://huggingface.co/justinpinkney/miniSD

Table 3: Model Specification

###  A.3 Further CoLa-DCE Examples

For the Flowers and Pets datasets, a VGG16bn has been finetuned on a few
epochs until decent accuracy of over 85%.

Figure 8: CoLa-DCE example for an ImageNet sample and the VGG16bn model. The
counterfactual with class “Great White Shark” is modified in the head
structure with more forward-facing eyes and a sharper, pointed nose. Also, the
mouth section is adapted to the counterfactual class. Figure 9: CoLa-DCE
example on the ImageNet dataset from “Bullfrog, Rana Catesbelana” to “Tailed
Frog, Bell Toad”.

####  A.3.1 Oxford Pets dataset:

Figure 10: CoLa-DCE example on the Pets dataset from “Abyssinian” to “Maine
Coon”. Figure 11: CoLa-DCE example on the Pets dataset from “American Bulldog”
to “Boxer”.

####  A.3.2 Oxford Flowers dataset:

Figure 12: CoLa-DCE example on the Flowers dataset from “Pink Primrose” to
“Peruvian Lily”. Figure 13: CoLa-DCE example on the Flowers dataset from
“Hard-leaved Pocket Orchid” to “Carnation”.

###  A.4 A Discussion on Adversarial Examples

While counterfactuals are supposed to be semantic changes in an input image,
there is always the possibility that single pixel changes in an image trigger
the classifier to predict a different targeted class. These changes are named
adversarial examples. While there is no guarantee that a generated image does
not include adversarial pixel changes, we highlight the functionality of CoLa-
DCE and LDCE as an ensemble of models that makes the appearance of
adversarials unlikely. For the counterfactual generation on ImageNet data, the
class-conditioned diffusion model and the external classifier are trained on
the same data so that similar shortcuts can potentially be learned. However,
the classifier is trained to discriminate between classes, while the diffusion
model is trained to generate semantic class features and to represent the data
distribution in a semantic encoding. A potential adversarial signal would need
to be encoded in the gradients of both models to be included into the gradient
alignment, which is used for guiding the diffusion process. As additionally
latent diffusion is used, the encoded representation needs to be decoded to a
human-observable image in input space by the trained decoder, which would be
required to preserve the adversarial signal and reconstruct it into the
respective image pixels. We argue that the probability of such a signal
fitting a possible adversarial trigger in the external classifier is
relatively low. With the usage of concept-based conditioning, the concept-
gradient of the external classifier is used, directly pointing out which
features should be changed in which areas of the input image. This level of
control and semantic guidance is another factor diminishing the probability of
adversarial patterns. While the dataset might induce semantically wrong class
patterns in all related models, we argue that these patterns represent valid
dataset features requiring a dataset adaptation. They can be easily found by
inspecting the concept patches given in our CoLa-DCE explanations.

###  A.5 Comparison of LDCE and CoLA-DCE counterfactuals

Figure 14: Comparison of generated samples between LDCE and our CoLa-DCE. The
CoLa-DCE samples include fewer feature changes and even look more realistic
for some examples.

Figure 15: Comparison of generated samples between LDCE and our CoLa-DCE.