Convolution playgroundLaboratorio della convoluzione

What the layers of a convolutional network compute on the image of a digit. A layer applies one small filter at every position of its input, with the same weights everywhere, and therefore its map records where the pattern of the filter occurs; max-pooling keeps the strongest response of every 2×2 block, and the second layer looks for patterns among the pooled maps of the first, over a larger part of the image. The network is trained in the page on digits written in a few fonts: draw one yourself, and hover a cell of a map to see the part of the input it depends on.

Che cosa calcolano gli strati di una rete convoluzionale sull'immagine di una cifra. Uno strato applica un piccolo filtro in ogni posizione del suo ingresso, con gli stessi pesi ovunque, e quindi la sua mappa registra dove compare il motivo del filtro; il max-pooling conserva la risposta più forte di ogni blocco 2×2, e il secondo strato cerca motivi fra le mappe ridotte del primo, su una parte più ampia dell'immagine. La rete è addestrata nella pagina su cifre scritte in alcuni font: puoi disegnarne una tu, e passare col puntatore su una cella di una mappa per vedere la parte dell'ingresso da cui dipende.

The input, 20×20 intensities in \([0, 1]\): draw a digit with the mouse or a finger. Below, the probabilities that the network gives to the 10 classes; the outline is the receptive field of the hovered cell.L'ingresso, 20×20 intensità in \([0, 1]\): disegna una cifra col mouse o con un dito. Sotto, le probabilità che la rete assegna alle 10 classi; il contorno è il campo recettivo della cella sotto il puntatore.

One filter of layer 1 sliding over the input: at every position \((i, j)\) the map takes \(y_{ij} = \mathrm{ReLU}\big(b + \sum_{u,v} w_{uv}\, x_{i+u,\,j+v}\big)\), with \(u, v \in \{-1, 0, 1\}\) and zeros outside the grid. Click a filter below to choose it, or the input to move the window.Un filtro dello strato 1 che scorre sull'ingresso: in ogni posizione \((i, j)\) la mappa vale \(y_{ij} = \mathrm{ReLU}\big(b + \sum_{u,v} w_{uv}\, x_{i+u,\,j+v}\big)\), con \(u, v \in \{-1, 0, 1\}\) e zeri fuori dalla griglia. Clicca un filtro qui sotto per sceglierlo, o l'ingresso per spostare la finestra.

Layer 1: the filters \(w\) (violet positive, gold negative), then their maps for the current input after the ReLU, then the maps after max-pooling 2×2, one column per filter; every map is scaled to its own maximum.Strato 1: i filtri \(w\) (viola positivo, oro negativo), poi le loro mappe per l'ingresso corrente dopo la ReLU, poi le mappe dopo il max-pooling 2×2, una colonna per filtro; ogni mappa è scalata sul proprio massimo.

filters 3×3filtri 3×3

maps 20×20mappe 20×20

pooled 10×10ridotte 10×10

Layer 2: each filter reads all the pooled maps of layer 1, so its cells depend on 8×8 pixels and those of its pooled maps on 10×10. Last, the input that drives each channel highest, found by gradient ascent from noise, after Feature Visualization.Strato 2: ogni filtro legge tutte le mappe ridotte dello strato 1, così le sue celle dipendono da 8×8 pixel e quelle delle sue mappe ridotte da 10×10. Infine, l'ingresso che porta più in alto ciascun canale, trovato per ascesa del gradiente a partire dal rumore, come in Feature Visualization.

maps 10×10mappe 10×10

pooled 5×5ridotte 5×5

input maximizing the channelingresso che massimizza il canale

What the network looks atChe cosa guarda la rete

The saliency of a class \(c\): the gradient \(\partial s_c / \partial x\) of its score \(s_c\) (the logit, before the softmax) with respect to every pixel of the input, violet where more ink would raise the score, gold where it would lower it, scaled to its largest magnitude. With × input the map is the gradient times the pixel, which keeps only the inked pixels and shows which of them push the score up. Of course, the gradient is local: it measures the effect of a small change of the input, and therefore it is at most a rough indication of how the network reaches its answer.La salienza di una classe \(c\): il gradiente \(\partial s_c / \partial x\) del suo punteggio \(s_c\) (il logit, prima della softmax) rispetto a ogni pixel dell'ingresso, viola dove più inchiostro alzerebbe il punteggio, oro dove lo abbasserebbe, scalato sul suo valore assoluto più grande. Con × ingresso la mappa è il gradiente per il pixel, che tiene solo i pixel inchiostrati e mostra quali di essi spingono in alto il punteggio. Il gradiente, beninteso, è locale: misura l'effetto di una piccola variazione dell'ingresso, e quindi dà al più un'indicazione approssimativa di come la rete arrivi alla sua risposta.

An adversarial example: a few steps of the fast gradient sign method, \(x' = \mathrm{clip}(x + \epsilon\, \mathrm{sign}(\nabla_x \ell))\), with \(\ell\) the loss of the current answer (to move away from it) or minus the loss of a target class; every step has size \(2.5\,\epsilon/\text{steps}\), and the iterate is kept within \(\epsilon\) of \(x\) in every pixel and in \([0, 1]\). The change is small in pixels and yet it changes the answer; on a network this small, trained on a few thousand digits, the perturbation is often visible as faint strokes, unlike those of large networks on photographs.Un esempio avversario: alcuni passi del fast gradient sign method, \(x' = \mathrm{clip}(x + \epsilon\, \mathrm{sign}(\nabla_x \ell))\), con \(\ell\) la loss della risposta corrente (per allontanarsene) o l'opposto della loss di una classe bersaglio; ogni passo ha ampiezza \(2.5\,\epsilon/\text{passi}\), e l'iterato resta entro \(\epsilon\) da \(x\) in ogni pixel e in \([0, 1]\). La variazione è piccola nei pixel e tuttavia cambia la risposta; su una rete così piccola, addestrata su qualche migliaio di cifre, la perturbazione è spesso visibile come tratti tenui, a differenza di quelle delle reti grandi sulle fotografie.