Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

stough 202-

Preview: PCA scattering of ORL Faces

A look at PCA to scatter the ORL faces database

The ORL (or AT&T) database has 400 grayscale photos of faces: 40 people, 10 photos each, with varied lighting, expression, glasses, and slight changes of pose. Each image is 112×92=10304112 \times 92 = 10304 pixels, so each face is a single point in a 10304-dimensional space. We obviously can’t look at that space directly, but with PCA we can find the handful of directions in it along which faces vary the most, and look at the faces along those. This is the classic eigenfaces approach (Turk and Pentland, 1991). See data_paths and the README for where the dataset needs to be.

The first 10 components together explain about 60% of the variation among the 400 faces, with the first two about 18% and 13%.

Each principal component is itself a 10304-dimensional vector, so we can display it as an image: these are the “eigenfaces”. Gray here doesn’t mean gray. The images are displayed with values scaled to fill the colormap, and what matters is where the component is strongly positive (bright) or negative (dark), because that’s how adding it changes the average face. The first components tend to capture the largest, broadest differences in these photos, like overall lighting and how bright the face is against the background, more than fine facial features. We’ll look at what each one does more directly in Component Spans.

Expected output (what the cell above should show, if you can’t run it)
expected output

Here each face is placed at its first two PCA coefficients. Faces near each other in this plot are faces that look alike in the two ways faces vary most: similar overall brightness and lighting, similar head shape and hair. Run the cell again to scatter a different random set.

Expected output (what the cell above should show, if you can’t run it)
expected output

Now we show all ten photos of each of three randomly chosen people. Each person’s photos tend to clump together, even though PCA was never told who is who. Faces of the same person really are near each other in face space, which is the basis for eigenface recognition: project a new photo into the PCA space and find the nearest known faces. Run this cell a few times. Some people’s clusters overlap, and in just 2 of the 10 dimensions some separation is lost.

 

Let’s add a t-sne visualization.

PCA is linear: its 2D view is a flat projection, like a shadow of the 10-dimensional points on a wall. t-SNE is a non-linear method that instead tries to place points in 2D so that points that are near each other in the high-dimensional space stay near each other in the plot. It distorts large distances freely in order to preserve neighborhoods. Below, we run t-SNE on the 10 PCA coefficients of every face, and color each face by who it is.

Expected output (what the cell above should show, if you can’t run it)
expected output

With t-SNE, most of the 40 people form their own tight clumps of color, much more cleanly than in the PCA scatter. Some people split into two or three clumps, perhaps photos with and without glasses, or under different lighting. With 40 random colors it can be hard to tell similar ones apart, so try re-running for a different coloring. The information to separate the people was in the 10 PCA dimensions all along; it just couldn’t be seen in a flat 2D projection. Keep in mind that t-SNE plots are for looking, not measuring: the distances between clusters, and the cluster sizes, don’t mean much, and the layout changes from run to run.