5

Sto leggendo Convolutional Neural Networks tutorial. Voglio visualizzare l'output di ogni livello dopo che il modello è stato addestrato. Ad esempio, nella funzione "evaluate_lenet5" voglio passare un'istanza (che è un'immagine) alla rete e vedere l'output di ogni livello e la classe che ha addestrato la rete neurale per l'input. Ho pensato che potrebbe essere facile come fare un prodotto punto su un'immagine e un vettore di peso di ogni livello, ma non ha funzionato affatto.Visualizza l'output di ogni livello in theano Convolutional MLP

devo oggetti di ogni livello come:

# Reshape matrix of rasterized images of shape (batch_size, 28 * 28) 
# to a 4D tensor, compatible with our LeNetConvPoolLayer 
# (28, 28) is the size of MNIST images. 
layer0_input = x.reshape((batch_size, 1, 28, 28)) 

# Construct the first convolutional pooling layer: 
# filtering reduces the image size to (28-5+1 , 28-5+1) = (24, 24) 
# maxpooling reduces this further to (24/2, 24/2) = (12, 12) 
# 4D output tensor is thus of shape (batch_size, nkerns[0], 12, 12) 
layer0 = LeNetConvPoolLayer(
    rng, 
    input=layer0_input, 
    image_shape=(batch_size, 1, 28, 28), 
    filter_shape=(nkerns[0], 1, 5, 5), 
    poolsize=(2, 2) 
) 

# Construct the second convolutional pooling layer 
# filtering reduces the image size to (12-5+1, 12-5+1) = (8, 8) 
# maxpooling reduces this further to (8/2, 8/2) = (4, 4) 
# 4D output tensor is thus of shape (batch_size, nkerns[1], 4, 4) 
layer1 = LeNetConvPoolLayer(
    rng, 
    input=layer0.output, 
    image_shape=(batch_size, nkerns[0], 12, 12), 
    filter_shape=(nkerns[1], nkerns[0], 5, 5), 
    poolsize=(2, 2) 
) 

# the HiddenLayer being fully-connected, it operates on 2D matrices of 
# shape (batch_size, num_pixels) (i.e matrix of rasterized images). 
# This will generate a matrix of shape (batch_size, nkerns[1] * 4 * 4), 
# or (500, 50 * 4 * 4) = (500, 800) with the default values. 
layer2_input = layer1.output.flatten(2) 

# construct a fully-connected sigmoidal layer 
layer2 = HiddenLayer(
    rng, 
    input=layer2_input, 
    n_in=nkerns[1] * 4 * 4, 
    n_out=500, 
    activation=T.tanh 
) 

# classify the values of the fully-connected sigmoidal layer 
layer3 = LogisticRegression(input=layer2.output, n_in=500, n_out=10) 

Così si può suggerire un modo per visualizzare un campione di elaborazione di un passo per passo un'immagine dopo che la rete neurale è addestrato?

risposta

6

Questo non è così difficile. Se si utilizza la stessa definizione della classe di LeNetConvPoolLayer dal Theano profondo-learning tutorial, poi solo bisogno di compilare una funzione con x come input e [LayerObject].output come uscita (dove LayerObject può essere qualsiasi oggetto strato come Layer0, layer1 ecc a seconda di quale livello si desidera visualizzare.

vis_layer1 = function ([x], [layer1.output])

Passa un (o più) campione (esattamente come hai alimentato il tensore di ingresso durante l'allenamento) e otterrai l'output di quel particolare layer per il quale è stata compilata la tua funzione.

Nota: In questo modo si ottengono i risultati nella stessa identica forma il modello è utilizzato nel calcolo. Comunque puoi rimodellare come vuoi ridisegnando la variabile di uscita come layer1.output.flatten(n).

Problemi correlati