A Vector for a Picture
Two photographs of the same object may look very different pixel by pixel. A trained network can provide a compact vector of features that gives us a more useful way to compare them.
15 sections · 15 questions · 4 coding challenges
The arrow keys move between sections too.
Could Features Learned for One Image Task Help with Another?
BOTIE
Donahue and colleagues' DeCAF work, released in 2013 and published in 2014, investigated reusing the internal activations of a trained convolutional network for other recognition tasks. It helped demonstrate that an intermediate representation could be valuable beyond the original classifier's output categories.
We pass an image through the network and take a selected internal representation as its vector. Training has shaped what that vector retains, so images sharing useful features may be close despite pixel differences. Which layer we choose and how the network was trained both matter. A vector from a classifier is a useful candidate for comparison, not an automatic guarantee of the similarity our application needs.
Pictures Can Look Alike Without Matching Pixel for Pixel
Two pictures can show the same kind of shape at different positions. Their raw pixel values may differ greatly even when we consider the pictures similar.
A learned image representation can give us a comparison that reflects a training task rather than only pixel-by-pixel agreement.
Keep the object idea separate from pixel alignment
These crosses occupy different locations. A raw pixel comparison treats many cells as disagreements. That may be a poor description of the similarity we wanted.
First picture
Shifted picture
A representation inherits the task that shaped it
The full lesson extracts vectors from a trained shape classifier and compares them with raw pixels.
Layer choice, comparison rule, and training coverage all affect what nearby vectors mean.
Explore the full example
Compare the nearest pictures under pixel distance and embedding similarity. Inspect the actual pictures, including mistakes, rather than judging the representation only by its plotted clusters.
…
Part 1. Pixels Make A Poor Ruler
1. Four kinds of picture, and a question about nearness
Every picture on this page is sixteen pixels on a side, with one brightness per pixel, and holds one of four shapes, a cross, the outline of a square, a filled disc or a diagonal bar. Each shape is drawn at a random position and a random size, against a random background, lifted by a random amount above that background, with a little noise on every pixel, so that no two crosses are alike and no single pixel gives a cross away.
We would like a way of saying that two crosses are near each other and a cross and a disc are not, and that turns out to be much harder to write down than it sounds.
The page asks six questions, in order. When two pictures are compared pixel by pixel, how often is a picture’s nearest neighbour the same kind, and why does it miss? What is the vector a trained network gives a picture, and how is it read off? Where do pictures the network never saw land in that space, and is a picture’s nearest neighbour there its own kind more often than its nearest by pixels?
Is that gathering something training did, or would an untrained network of the same shape do it too? Which layer of the network gives the best position? And where does a ring end up, a fifth kind the network was never shown?
| the collection | on this page |
|---|---|
| side of one picture | 16 pixels, one brightness each |
| kinds the network is taught | cross, square, disc, bar |
| pictures it learns from | 240, 60 of each kind |
| pictures held out | 240, 60 of each kind |
| background brightness | between 0 and 0.3 |
| shape lifted above it by | between 0.4 and 0.7 |
| a fifth kind, never taught | ring, 60 drawn |
The pictures are drawn by arithmetic so the page can say exactly what is in them. The held-out half is where every nearness below is measured.
Keep in mind
2. Nearness by pixels, and how often it is right
The obvious way to compare two pictures is to lay one over the other and add up how differently each pixel is lit. Two pictures that agree everywhere score zero, and the more pixels disagree, and the more they disagree by, the larger the score. It needs no training and no idea of what a shape is, which is its appeal.
distance(a, b) = √( Σₚ (aₚ − bₚ)² ), p running over all 256 pixelsFor each of the 240 held-out pictures, find the picture nearest it by that distance among the other 239, and ask whether it is the same kind. It is for 194 of them, a share of 0.8083, which is far better than the one in four a random choice would manage and is the number everything else on this page has to beat.
The 46 misses are not spread evenly. Of the 60 crosses, 11 have a disc as their nearest picture, and of the 60 squares, 7 have a bar and 6 a cross.
One picture the pixels get wrong
Held-out picture 2 is a disc. Its nearest picture by pixels is a cross, at a distance of 1.9275, and the next is another cross at 2.2680, so the nearest disc only comes third, at 2.3905. The playground at the top of the page opens on this picture, and its button for a picture the pixels get wrong steps through all 46 of them.
Keep in mind
3. What the pixels are actually comparing
A pixel distance gives two pictures credit only for being lit in the same places. A cross and a disc drawn over the same spot share a good many lit pixels and come out close, while two crosses drawn a few pixels apart share almost none and come out far. Every pixel also carries the background, so two pictures with similar backgrounds look alike whatever is drawn on them.
Comparing by angle rather than by distance does not help on its own. Every pixel of every picture sits above zero, so all 240 pictures point in roughly the same direction, and two pictures of one kind have a mean cosine of 0.5937 against 0.5799 for two of different kinds, a difference of 0.0138. The nearest-neighbour count by angle is 196.
Subtracting each picture’s own mean brightness before comparing removes the shared lift, and the count rises to 212 of 240, a share of 0.8833, though the two mean cosines are then 0.1527 and 0.1181 and still barely apart.
cosine(a, b) = (a · b) / (‖a‖ ‖b‖)What we would want is a comparison that ignores where the shape sits, how big it is and how bright, and still notices which shape it is. Nobody can write that comparison down pixel by pixel, which is why the rest of the page lets a network find one.
Keep in mind
Part 2. Reading A Vector Off A Network That Names
4. A network trained only to name four kinds
The network is the one every picture page on the site shares. It convolves the picture with four small filters and keeps the largest value in each two by two block, does the same again with eight filters, lays what is left out in one row of 128 numbers, passes those through a dense layer of 16, and ends in four scores, one per kind. It learns from the 240 training pictures for 40 passes, and the only thing its loss asks is that each picture’s own kind score highest.
…
The network one step at a time. The highlighted row is the layer this page reads a picture’s vector from.
Of its 2,468 learned numbers, 2,064 belong to the dense layer of 16. It names every training picture correctly and 0.9708 of the held-out ones. That second figure moves with the starting weights, and trained from two other weight seeds the same design names 0.9208 and 0.9667 of the held-out pictures, so where a claim below depends on training it is reported over all three. The widgets draw the first seed, the one every picture page calls the network, except where a table lays the three side by side.
Keep in mind
5. Throw away the naming and keep the layer before it
The method is short enough to say in a sentence. Put a picture through the trained network, stop one layer short of the answer, and keep the sixteen numbers found there as the picture’s position. That list is the picture’s vector, or its embedding, and the last layer, which turned those sixteen numbers into four scores, is simply not used.
v = tanh(W f + b) f the 128 flattened numbers, W 16 × 128, b 16
scores = U v + c U 4 × 16, c 4Each of the sixteen numbers is a hyperbolic tangent, so it lies strictly between −1 and 1, and the length of the whole vector can never reach √16, which is 4. The loss the network was trained on is a statement about one picture at a time and its label.
loss for one picture = − log( e^(score of its own kind) / Σₖ e^(scoreₖ) )Nothing in that expression mentions a second picture. Whether two pictures of the same kind end up with nearby vectors is a question about an arrangement nobody specified, and it is the claim on the card that led here, which Part 4 puts to a test.
Keep in mind
6. Four pictures taken all the way through
Here are the first held-out picture of each kind, each with its sixteen numbers drawn as bars above and below zero. The bars of a bar-shaped picture and of a square look nothing alike, and nobody could say from them which bar stands for what, which step 8 comes back to.
…
The four pictures, their vectors, and the two ways of comparing them. The two grids hold the same six pairs, measured once by the angle between vectors and once by the distance between pixels.
Three of the four are named without doubt, the cross at a probability of 0.9968, the square at 0.9842 and the bar at 0.9885. The disc is named a disc by a whisker, 0.5158 against 0.4678 for a cross, and it is the same held-out picture 2 whose nearest picture by pixels was a cross. Its vector is 2.8774 long, where the square’s is 3.6335.
Keep in mind
7. One cosine worked by hand
The angle between two vectors is read from their dot product, the sum of the products of matching numbers, divided by both lengths. For the cross and the square every quantity is on the widget above, so the whole calculation can be checked.
| step | what it is |
|---|---|
| cross · square = 3.2608 | the sixteen products of matching coordinates, added. |
| ‖cross‖ = 3.0017, ‖square‖ = 3.6335 | each the square root of the sum of its own squared coordinates. |
| 3.2608 / (3.0017 × 3.6335) = 0.2990 | dividing by both lengths leaves the cosine of the angle between them, about 73 degrees. |
Among these four the nearest pair by angle is the cross and the disc, at 0.4199, and the nearest pair by pixels is the same two, at a distance of 4.0616. The square and the bar are the farthest apart both ways, at −0.3454 and 6.2299. Four pictures are enough to check the arithmetic and far too few to say anything about kinds, so the next Part asks the question of all 240.
Keep in mind
The table gives the dot product and both vector lengths. Divide the dot product by the product of the lengths.
cosine(cross, square) ≈ 3.2608 / (3.0017 × 3.6335) ≈ 0.29908. No one of the sixteen numbers means anything on its own
It is tempting to ask what the third of the sixteen numbers measures, roundness perhaps, or how many corners there are. The way to test that is to train the same design again from different starting weights and see whether the third number still does the same job. It does not, and neither does any other, while which kind lands near which barely changes.
Training the same network from three starting points…
Each row compares the reference network with one retrained from another weight seed, on the same 240 held-out pictures.
The same picture’s vector under the reference network and under seed 1 has a mean cosine of −0.1387, and under seed 2 of 0.0187, so on average one picture’s two vectors are at right angles. The nearest picture is the same picture under both networks for only 40 and 45 of the 240, yet the nearest picture is the same kind under both for 225 and 230.
This is the finding the word page makes by turning its whole table, met here with the network retrained instead, and it has the same consequence, since only comparisons between vectors from one network carry anything.
Keep in mind
Check yourself
Questions on Parts 1 and 2
Question 1 of 5
Comparing two pictures by the angle between them rather than by the distance between them is enough to stop the shared background dominating.
Part 3. Where The Held-Out Pictures Land
9. Sixteen numbers, drawn as a turning sphere
Sixteen numbers cannot be drawn, so the drawing below takes three liberties and says so. Every vector is first scaled to length one, since the angle is what we are comparing and the length plays no part in it. The 240 directions are then projected onto the three directions along which they spread most, and each projected point is pushed back out onto the sphere.
…
Every held-out picture as a dot, coloured by its kind. The four kinds sit in four separate patches of the sphere, and the drawing keeps 81.1% of the spread of the directions.
The figures under the drawing are measured on all sixteen numbers, not on the three drawn. Two pictures of one kind have a mean cosine of 0.7588, an angle of about 41 degrees, and two pictures of different kinds 0.0022, which is almost exactly a right angle. For raw pixels the same two figures were 0.5937 and 0.5799.
Keep in mind
10. A picture’s nearest neighbour, by vector and by pixels
The question from Part 1 can now be asked of the vectors. For each held-out picture, find the picture whose vector makes the smallest angle with its own, and ask whether it is the same kind. This is a one-neighbour vote in the sense of k-nearest neighbours, scored with each picture left out of its own search.
share = (1/240) Σᵢ [ kind of the nearest other picture to i = kind of i ]Training the same network from three starting points…
The three pixel rows do not depend on any network and so read the same under every seed. The last row is the vector.
By the vector, a picture’s nearest neighbour is its own kind for 233 of 240 under the reference network, and for 230 and 235 under the other two seeds, against 194 by pixel distance and 212 for the best pixel comparison. Of the 46 pictures the pixels get wrong, the vector gets 43 right. Measuring the vectors by straight-line distance rather than by angle gives 233 on the reference network too, so on this network the choice between the two readings of near makes no difference to the count.
Keep in mind
11. The seven the vector still gets wrong
A count hides which pictures go wrong, and the answer is informative. Laid out as a table of each kind against the kind of its nearest neighbour, the pixels spread their mistakes over every pair, and five of the vector’s seven fall between a disc and a cross.
Training the same network from three starting points…
Each row is a kind, and each cell counts the pictures of that kind whose nearest neighbour was of the column’s kind. The diagonal is right and everything tinted is a mistake.
On the reference network all 60 squares find a square, and 59 of 60 bars find a bar. Three discs have a cross as their nearest neighbour and two crosses a disc, and the remaining two mistakes are a cross beside a square and a bar beside a disc. Crosses and discs are the pair both tables mix most, 11 and 9 times by pixels and 2 and 3 times by the vector, and the disc of step 6, which the network itself only just named a disc, is one of the three.
Keep in mind
12. What the vector costs
The vector is shorter than the picture, sixteen numbers where the picture has 256, so holding it and comparing it are cheaper. Making it is not. Every picture has to go through the two convolutions and the dense layer first, and the network has to be trained before the first picture can be given a vector at all.
| by pixels | by the vector | |
|---|---|---|
| numbers kept per picture | 256 | 16 |
| numbers kept for 240 pictures | 61,440 | 3,840 |
| multiplications to compare two pictures | 256 | 16 |
| multiplications to make one picture’s vector | none | 29,696 |
| before the first comparison | nothing | 40 passes over 240 pictures |
| held-out pictures whose nearest is their kind | 194 | 233 |
The multiplications to make a vector are counted from the layer shapes in step 4.
The multiplication count comes from the positions, filters and weights used at each stage. Count one new picture first.
first convolution = 16 × 16 × 4 × 9 = 9,216
second convolution = 8 × 8 × 8 × 36 = 18,432
dense layer = 128 × 16 = 2,048
total = 9,216 + 18,432 + 2,048 = 29,696
two new pictures = 2 × 29,696 = 59,392Producing the two vectors already costs more than the 256 multiplications needed for a pixel comparison. A vector can repay that cost when a picture is compared many times, because it is computed once and kept.
That is the setting in searching a collection of pictures.
Keep in mind
Part 4. Did Anyone Ask For This?
13. What the naming asked for
The card this page sits under says pictures of one kind land near each other without anyone having asked for that. It is worth being exact about what was asked. The loss asked that each picture’s own score come out highest, and the scores are one flat layer on top of the sixteen numbers, so to satisfy it the sixteen numbers had to be arranged so that a flat cut can separate each kind from the others.
That is a demand about the arrangement, though it is weaker than nearness. Kinds can sit on the right sides of flat cuts and still be long and spread out, so that a picture’s nearest neighbour lies across a cut. There is also a second explanation to rule out, which is that convolution and pooling gather pictures of one kind by their construction, whatever the weights, in which case training would deserve little of the credit.
›Why separable does not mean near
Picture two kinds as two long thin clouds lying side by side and a flat cut running between them. Every point of each cloud is on its own side, so a flat layer names them all correctly. Yet a point at the far end of one cloud can be much nearer the facing point of the other cloud than any point of its own, so its nearest neighbour is the wrong kind.
Separability constrains which side of a cut a picture is on, and nearness depends on the whole shape of each kind, which the loss never mentions.
Keep in mind
14. The same network, never trained
The control is the same design with its starting weights, the very numbers training began from, and nothing learned. It is given the same held-out pictures, its sixteen numbers are read off the same layer, and the same questions are asked of them.
…
The untrained network’s vectors, drawn the same way. The kinds are smeared across one region of the sphere, and the switch above the drawing puts the trained network back for comparison.
Untrained, the network names 0.2125 of the held-out pictures correctly, a little under the one in four a guess would get. By its sixteen numbers, a picture’s nearest neighbour is its own kind for 189 of 240, and under the other two seeds for 180 and 186, which is below the 194 the raw pixels managed on every seed. Its pictures all point nearly the same way, at a mean cosine of 0.7394 within a kind and 0.7325 across kinds.
Keep in mind
15. Random convolutions are not nothing
The untrained network is not useless everywhere, though, and the place it is useful is the place Jarrett and Saxe pointed at. Reading the untrained network one layer earlier, at the 128 numbers the convolutions and poolings hand on, gives a nearest neighbour of the right kind more often than the raw pixels do.
Training the same network from three starting points…
The first table counts nearest neighbours of the right kind, and the second puts the mean cosine within a kind beside the mean cosine across kinds.
The untrained 128 find their own kind for 201, 206 and 208 of 240 across the three seeds, above the 194 of pixel distance on every seed and below the 212 of pixels less their mean. A random filter bank followed by keeping the largest value in each block already discards some of where a shape sits. Then the untrained dense layer squeezes those 128 numbers into sixteen through random weights and loses some of what was kept, 201 falling to 189 on the reference seed.
Keep in mind
16. What training added
Setting the two networks side by side answers the question. Training took the sixteen numbers from 189 pictures with a nearest neighbour of their own kind to 233 on the reference seed, from 180 to 230 and from 186 to 235 on the other two. It also opened the gap between the mean cosine within a kind and across kinds from 0.0069 to 0.7566.
So the card’s claim holds, with one qualification. The gathering is the work of training, since the untrained design gathers worse than pixels. Nobody asked for it by name, since the loss never compared two pictures. What the loss did ask for, kinds a flat cut can separate, is close enough to the gathering that on four kinds this distinct the one brought the other along with it, and step 13 is the reason to expect that to fail on kinds that are harder to tell apart.
Keep in mind
Check yourself
Questions on Parts 3 and 4
Question 1 of 5
The mean cosines quoted beneath the sphere drawing, 0.7588 within a kind and 0.0022 across, are measured on all sixteen numbers rather than on the three directions drawn.
Part 5. Which Layer Makes The Best Vector
17. Three places a vector could be read
The method reads the layer before the answer, but the network offers two other rows of numbers a picture could be given. One is the 128 numbers the convolutions hand on before the dense layer, and the other is the four scores themselves. The usual advice is that the layer before the answer is the right one, and the way to check that is to measure all three with the same question.
Training the same network from three starting points…
The same trained network read at three depths, over three weight seeds.
By nearest neighbour the flattened 128 find their own kind for 231, 234 and 237 of 240, the sixteen for 233, 230 and 235, and the four scores for 229, 219 and 230. The flattened layer beats the sixteen on two seeds of the three and loses on the reference seed, so the preference for the layer before the answer did not show up here as a clear win on this count. The four scores come last on every seed.
Keep in mind
18. By margin, the layer of sixteen is the clearest
A nearest-neighbour count only asks whether the single closest picture is right. The mean cosine within a kind against across kinds asks how far apart the kinds sit as a whole, and on that question the three layers separate cleanly.
| layer, reference seed | within a kind | across kinds | gap |
|---|---|---|---|
| flattened, 128 numbers | 0.5143 | 0.4062 | 0.1081 |
| hidden layer, 16 numbers | 0.7588 | 0.0022 | 0.7566 |
| scores, 4 numbers | 0.8757 | −0.1755 | 1.0512 |
Mean cosines over the 240 held-out pictures. The table above gives the same figures for all three seeds.
The flattened layer barely separates the kinds on average, since its gap is 0.1081, and it wins on nearest neighbour only because the single nearest picture is still usually right. The sixteen open a gap seven times as wide with an eighth as many numbers. The four scores open the widest gap of all and still have the worst count, because four numbers leave room only for four directions, and within a kind there is little left to rank pictures by, so a picture between two kinds finds its nearest neighbour almost by chance.
Four scores also have no room for a kind they were not trained to score, which is the next Part’s subject.
Keep in mind
Part 6. A Kind The Network Was Never Shown
19. What the network calls a ring
A ring is a round outline, drawn the same way as the four other kinds, and no training picture was ever a ring. Put through the network, a ring still has to be named one of the four kinds, because four scores are all the network has, and it names most of them squares, the other outline.
Of 60 rings, the reference network names 48 squares, 9 crosses and 3 discs. The seed 1 network names 38 squares and 19 crosses, and seed 2 names 37 squares, 13 crosses, 7 discs and 3 bars. Nothing in the answer marks it as a guess. Ring 0 is named a square at a probability of 0.9371, close to the 0.9842 the network gave the real square of step 6, and switching the playground to rings shows the same for most of the others.
Keep in mind
20. Do rings gather?
The more interesting question is about positions rather than names. If the vector describes pictures and not only which label to give them, rings ought to land near each other even though nothing ever called them anything. To test that, the 60 rings are added to the 240 held-out pictures, and each ring’s nearest neighbour among the other 299 is found.
…
The rings are the hollow dots, placed with the same projection as the four kinds, which was fitted without them. Most of them sit together, beside and partly inside the squares.
They mostly do. On the reference network 44 of the 60 rings have another ring as their nearest neighbour, and 45 and 43 under the other two seeds. On the reference network 15 of the other 16 find a square. The mean cosine from a ring to another ring is 0.7388 and from a ring to a square 0.7294, so a ring is nearly as close to the squares as to other rings. Under seed 2 it is the other way round, 0.5088 to other rings against 0.5527 to squares.
Keep in mind
21. Here the pixels do better, and the earlier layer best of all
This is the place where the method loses to the obvious alternative, and it is worth stating plainly. Comparing rings by their raw pixels, 46 of 60 have another ring as nearest neighbour, more than the vector manages on any of the three seeds. The reason shows up when every layer is asked the same question.
Training the same network from three starting points…
How many of 60 rings find another ring, read at each layer and from the pixels, then what the network names them and how near they sit to each kind.
The flattened 128 gather 50, 55 and 55 rings across the seeds, the sixteen 44, 45 and 43, and the four scores 41, 32 and 29. Pixels less their own mean gather 50. So the deeper the layer, the fewer rings find each other, and the layer this page reads the vector from sits in the middle.
The reading I take from that is that everything after the convolutions was trained to keep what helps name four kinds and to drop the rest, and what tells a ring from a square was never any help in naming four kinds, so each later layer holds less of it.
Keep in mind
Part 7. Where A Picture’s Vector Stops Being Meaningful
22. What a length is, and what the angle throws away
Comparing by angle divides each vector by its length, so whatever the length carried plays no part in any nearness on this page. On this network the length has a ceiling, since sixteen numbers each below 1 in size cannot make a vector as long as 4, and many of the numbers sit close to that ceiling.
…
Lengths of the 240 held-out vectors, and how often a nearest neighbour is the right kind under each reading of near.
Held-out vectors run from 1.4867 to 3.9429 in length with a mean of 2.9769, and 0.2437 of all their coordinates are beyond 0.95 in size. The length correlates with the probability the network gives its top kind at 0.4355, so it carries some of the network’s confidence, and dividing it out discards that. Here nothing turns on it, since the count is 233 of 240 by angle and by distance alike.
The angle has one gap of its own, which is that a vector of length zero has no direction. With a hyperbolic tangent layer that needs all sixteen inputs to be exactly zero, which essentially never happens, but a layer of rectified units puts every picture that lights none of its units exactly at zero, and there the angle does not exist.
Keep in mind
23. A picture holding nothing
A picture with no shape in it still gets a vector, because the network always answers. The question is what that vector means, and the measurement says it means very little.
…
Four pictures with nothing drawn in them, at four flat brightnesses, and where each lands.
An all-black picture and a flat one at 0.15 light none of the first convolution’s 1,024 numbers, so nothing of either picture gets past the first layer, and the two receive exactly the same vector, at a cosine of 1.0000. That vector depends on nothing but the network’s own biases carried through its weights, and it is named a bar at a probability of 0.8921, with a mean cosine of 0.7629 to the held-out bars.
A flat picture at 0.3, the brightest background training ever drew, lights 464 of the 1,024 and is still named a bar, at 0.9324. So an empty picture has a position and a name, and both come from the biases rather than from anything in the picture.
Keep in mind
24. A brightness training never showed
Training drew every shape between 0.4 and 0.7 above its background, so a picture made much dimmer or much brighter is outside anything the network was shown. Multiplying a whole picture by a constant changes nothing about its shape, and a description of shape would not move. The vector moves a long way.
…
Each line is one of the four pictures of step 6, multiplied through, with its cosine to its own vector at full brightness. The dashed line is the picture as it was drawn.
At a quarter of its brightness every one of the four is named a bar, and the cross’s vector has a cosine of −0.1928 to where it started. At half brightness the cross is still named a cross but its cosine has fallen to 0.5697, and the disc is named a bar. Brighter pictures hold up better, the cross at 0.9084 at twice its brightness and the square at 0.9554 at three times. Dim pictures drift towards the position the blank picture was given, which is why the name they fall into is bar.
Keep in mind
25. Where the method stops being defined
Reading a vector off a classifier asks three things of a picture and a collection. The picture has to be something the network can read, the vector has to have a direction, and the kinds a question asks about have to be distinctions the training gave the network a reason to keep. Where one of those fails the vector does not become approximate, it becomes either undefined or defined and empty of meaning, and the table says which.
| the case | what the method says |
|---|---|
| a vector of length zero | it has no direction, so the cosine is a zero over a zero. Whether this can happen depends on the layer read, since a hyperbolic tangent layer reaches zero only if all its inputs are exactly zero and a rectified layer reaches it whenever a picture lights none of its units. The choices are to refuse the comparison, or to fall back to straight-line distance, which calls every such picture identical to every other. |
| a picture holding nothing | defined and empty. The network always answers, so the picture gets a position, and that position is made by the biases rather than by the picture. Measured here, every dark blank picture is given one vector, named a bar at 0.8921. |
| a picture of another size | undefined for this network. The dense layer reads exactly 128 numbers, which is 8 channels of 4 by 4 after two poolings of a 16 by 16 picture, and a 20 by 20 picture would hand on 8 by 5 by 5, which is 200, so there is no vector at all. The usual choice is to summarise each channel over the whole picture, which gives 8 numbers whatever the size and gives up where in the picture anything was. |
| a kind the network was never taught | the nearness is defined and its meaning is not what it was. The sixteen numbers were shaped to separate four other kinds, so what distinguishes the new kind is kept only by accident. Measured here, 43 to 45 of 60 rings gather where raw pixels gather 46, and the four scores have to name every ring one of four kinds. |
| vectors from two different trainings | undefined as a comparison. The two sets of axes have nothing to do with each other, so one picture’s two vectors are at a mean cosine of −0.1387 and 0.0187 across two retrainings. Comparisons are only meaningful inside one network. |
| a collection holding one picture | the nearest other picture names a set with nothing in it, so the question has no answer rather than a bad one. |
| two pictures exactly as near | the nearest neighbour is not unique, so a rule has to choose, and any rule is arbitrary. Choosing the earlier picture keeps the answer repeatable, which is the most a rule can offer here. |
| a picture brighter or dimmer than any trained on | defined, and not comparable with the pictures training drew. Nothing in the loss asked the vector to ignore brightness, so at a quarter of its brightness every one of the four pictures of step 6 is named a bar. |
| a question the labels never asked | whether two crosses are the same size, say. The loss rewarded only telling kinds apart, so whether size survives into the sixteen numbers is an accident of one training, and the answer can differ from one weight seed to the next. |
Keep in mind
Check yourself
Questions on Parts 5 to 7
Question 1 of 5
Among the three layers measured, the sixteen numbers separate the four kinds by the widest mean-cosine gap.
Try it with Botie
Build with Botie
Write and run Python