Skip to content

"This looks like that": prototype networks

ProtoPNet classifies an image by how closely its parts match learned prototype patches, so the evidence is part of the computation. Learn the similarity score, the projection step, and why a readable prototype can still be a shortcut.

Advanced ~11 min8 steps

What runs in CodeSplash

You will be able to

  • Describe ProtoPNet's patch distances, similarity scores and evidence layer
  • Explain prototype projection and why it makes prototypes viewable
  • Contrast interpretable-by-design models with post hoc explanations
  • Name the checks a prototype explanation still needs

Read first

01

Explanation as part of the model

Read

Every explainer so far looks at a finished model from outside. ProtoPNetProtoPNetAn image classifier that scores how closely parts of an image match learned prototype patches, then adds up that evidence. (prototypical part network) builds the explanation into the classifier: it learns a set of prototypes, small patches in the network's feature space, and classifies an image by how strongly parts of it resemble each prototype. Its answer comes with its reasons: "this region looks like that prototype, which counts toward this class".

It is a trained architecture, not a tool you can apply to an existing model.

Reference · EXP012 · Explained hereProtoPNet: prototypical part networkClassify an image using similarities between its latent patches and learned prototypes, making part-based evidence an explicit part of the computation.
02

How it scores an image

Read

A convolutional encoder turns the image into a grid of latent patches. For each prototype pjp_j, take the closest patch and turn its distance into a similarity:

dj(x)=min⁡z∈patches(hθ(x))∥z−pj∥22,sj(x)=log⁡dj(x)+1dj(x)+ϵ,logits=W s(x).d_j(x)=\min_{z\in\text{patches}(h_\theta(x))}\lVert z-p_j\rVert_2^2,\qquad s_j(x)=\log\frac{d_j(x)+1}{d_j(x)+\epsilon},\qquad \text{logits}=W\,s(x).

A small distance gives a large similarity, and a final layer WW adds up the evidence per class. In the reference's example two prototypes match patches at squared distances 0.02 and 0.04, giving similarities 3.93 and 3.26.

03

Projection makes prototypes visible

Read

After training, each prototype is projected onto the nearest latent patch of an actual training image of its class. From then on, "prototype 7" is a piece of a real image you can show. Training also uses terms that pull prototypes toward patches of their own class and away from others.

That is what makes ProtoPNet readable: each piece of evidence points at a training-image patch. But the picture you see is the image region behind a latent patch, and the receptive field of that patch can be far larger than the highlighted box.

04

Predict: a readable shortcut

Predict

Predict first

A bird classifier's most-used prototype for "waterbird" projects onto a patch of a real waterbird photo. Does that show the model recognizes waterbirds?

Yes: a prototype from a real bird image must be about birdsNo: the prototype may match the background those birds were photographed on
Reveal

No. The patch may be mostly water. If waterbirds were photographed over water, a background prototype classifies them well and fails on a waterbird on land. A readable prototype makes such a shortcut easier to spot, not impossible. Test on counterexamples.

05

Checks a prototype model still needs

Read
  • Report accuracy and prototype quality separately. A model can be accurate with unhelpful prototypes, or interpretable and less accurate.
  • Inspect what each prototype matches across many images, not only its projected patch.
  • Watch negative weights. Evidence against a class, and prototypes reused across classes, complicate the "this looks like that" story.
  • Test localization and counterexamples, as with any saliency map.
06

Where it stands in CodeSplash

Read
07

Check your understanding

Checkpoint

Check yourself

How does ProtoPNet decide a class?

Show the answer

Answer: b

The evidence is part of the forward pass: distances to prototypes, similarities, then a linear evidence layer.

Check yourself

A colleague wants to use ProtoPNet to explain their already-trained ResNet. What's the issue?

Show the answer

Answer: b

Interpretable-by-design models explain themselves. For an existing model, use post hoc tools (Grad-CAM, attributions) and their checks.

Check yourself

Which check best tests whether a prototype is a background shortcut?

Show the answer

Answer: b

Counterexamples separate object evidence from context. One projected patch can't.

08

Recap

Recap
  • ProtoPNet classifies by similarity to learned prototype patches; the evidence is the computation.
  • Projection ties each prototype to a real training patch you can view.
  • It is trained, not post hoc, and a readable prototype can still be a shortcut.
  • Explained here; CodeSplash's image classifier uses Grad-CAM instead.

Concepts in this lesson