CNN convolution fast implementation

Below is my implementation of the CNN convolution. "in" is a 3D matrix, there are also a 4D matrix "weights" and a 1D matrix "bias". "Out" is a 3D matrix. I am wondering if there is a better fast implementation.
function out = spConvLayerForward(in, layer, weights, bias)
[row, col, planeIn] = size(in);
planeOut = size(layer.weights, 4);
out = single(zeros(row, col, planeOut));
for i = 1 : planeOut
bias = layer.bias(i);
tmp = out(:, :, i);
tmp(:) = 0;
for j = 1 : planeIn
tmp = tmp + conv2(in(:, :, j), weight, 'same');
end
tmp = tmp + bias;
end

1 comentario

Walter Roberson
Walter Roberson el 14 de Sept. de 2016
You can reshape in() to 2d and use a single conv2() call, but the boundary conditions become a nuisance.
Where is the variable "weight" coming from, and why did you make it so similar to the unused parameter "weights"?

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Deep Learning Toolbox en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 14 de Sept. de 2016

Comentada:

el 14 de Sept. de 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by