Leí sobre redes neuronales convolucionales desde aquí . Luego comencé a jugar con torch7. Estoy teniendo confusión con la capa convolucional de una CNN.
Desde el tutorial,
The neurons in a layer will only be connected to a small region of the layer before it, instead of all of the neurons in a fully-connected manner.
For example, suppose that the input volume has size [32x32x3], (e.g. an RGB CIFAR-10 image). If the receptive field is of size 5x5, then each neuron in the Conv Layer will have weights to a [5x5x3] region in the input volume, for a total of 5*5*3 = 75 weights.
si la capa de entrada es [32x32x3], CONV layer will compute the output of neurons that are connected to local regions in the input, each computing a dot product between their weights and the region they are connected to in the input volume. This may result in volume such as [32x32x12].
Empecé a jugar con lo que una capa CONV podría hacer con una imagen. Hice eso en antorcha7. Aquí está mi implementación,
require 'image'
require 'nn'
i = image.lena()
model = nn.Sequential()
model:add(nn.SpatialConvolutionMM(3, 10, 5, 5)) --depth = 3, #output layer = 10, filter = 5x5
res = model:forward(i)
itorch.image(res)
print(#i)
print(#res)
3
512
512
[torch.LongStorage of size 3]
10
508
508
[torch.LongStorage of size 3]
Ahora veamos la estructura de una CNN
Entonces, mis preguntas son,
¿Se hace la convolución así? Digamos que tomamos una imagen de 32x32x3. Y hay un filtro de 5x5. Entonces, ¿el filtro de 5x5 pasará por toda la imagen de 32x32 y producirá las imágenes enrevesadas? Bien, deslizando el filtro 5x5 a través de toda la imagen, obtenemos una imagen, si hay 10 capas de salida, obtenemos 10 imágenes (como puede ver en la salida). ¿Cómo los conseguimos? (vea la imagen para una aclaración si es necesario)
¿Cuál es el número de neuronas en la capa conv? ¿Es el número de capas de salida? En el código que he escrito anteriormente, model:add(nn.SpatialConvolutionMM(3, 10, 5, 5))
. ¿Son las 10? (no de capas de salida?)
Si es así, el punto número 2 no tiene ningún sentido. Según eso If the receptive field is of size 5x5, then each neuron in the Conv Layer will have weights to a [5x5x3] region in the input volume, for a total of 5*5*3 = 75 weights.
Entonces, ¿cuál será el peso aquí? Estoy muy confundido en esto. En el modelo definido en antorcha, no hay peso. Entonces, ¿cómo juega el peso aquí?
Can someone explain what is going on?
Is the convolution done like this - lets say we take an image 32x32x3. And there is 5x5 filter. Then the 5x5 filter will pass through the whole 32x32 image and produce the convoluted images?
For a 32x32x3 input image a 5x5 filter would iterate over every single pixel and for each pixel look at the 5x5 neighborhood. That neighborhood contains 5*5*3=75 values. Below is an example image for a 3x3 filter over a single input channel, i.e. one with a neighborhood of 3*3*1 values (source).
For each individual neighbor the filter will have one parameter (aka weight), so 75 parameters. Then to calculate one single output value (value at pixel x, y) it reads those neighbor values, multiplies each one with the respective parameter/weight and adds those up at the end (see discrete convolution). The optimal weights have to be learned during the training.
So one filter will iterate over the image and generate a new output, pixel by pixel. If you have multiple filters (i.e. the second parameter in SpatialConvolutionMM
is >1) you get multiple outputs ("planes" in torch).
Okay, so sliding 5x5 filter across the whole image, we get one image, if there are 10 output layers, we get 10 images(as you see from the output). How do we get these? (see the image for clarification if required)
Each output plane gets generated by its own filter. Each filter has its own parameters (5*5*3 parameters in your example). The process for multiple filters is exactly the same as it is for one.
What is the number of neurons in the conv layer? Is it the number of output layers? In the code I've written above, model:add(nn.SpatialConvolutionMM(3, 10, 5, 5)). Is it 10? (no. of output layers?)
You should call them weights or parameters, "neurons" doesn't really fit for convolutional layers. The number of parameters is, as described, 5*5*3=75 per filter in your example. As you have 10 filters ("output planes") you have 750 parameters total. If you add a second layer to your network with model:add(nn.SpatialConvolutionMM(10, 10, 5, 5))
you would have an additional 5*5*10=250 parameters per filter and 250*10=2500 total. Notice how that number can quickly grow (512 filters/output planes in one layer operating on 256 input planes is nothing uncommon).
Para obtener más información, consulte http://neuralnetworksanddeeplearning.com/chap6.html . Desplácese hacia abajo hasta el capítulo "Introducción a las redes convolucionales". En "Campos receptivos locales" hay visualizaciones que probablemente le ayudarán a comprender lo que hace un filtro (uno se mostró arriba).
Este artículo se recopila de Internet, indique la fuente cuando se vuelva a imprimir.
En caso de infracción, por favor [email protected] Eliminar
Déjame decir algunas palabras