Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

spatialToDepth custom layer problems

1 visualización (últimos 30 días)
michael kaster
michael kaster el 31 de Ag. de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hi all,
I tried to make a custom layer, following interesting article arXiv:1909.03205v2.
The layer re-arrange the input image such that all pixels remain, reducing the spatial dimensions and enlarging the number of feature maps, rather than use the distructive maxPooling.
The code for the layer is given below. Unfortunatelly, I got errors related to wrong output class from the layer and/or dimensions mismatch to the next layer which will be conv2D.
Please help, what should I do to make this layer passing checkLayer/analyzeNetwork?
BTW, running the predict function lines at the command window shows that the function is working well and do its job.
Kind regards,
Michael.
classdef spaceToDepthLayer < nnet.layer.Layer
properties
Stride;
Padding;
end
methods
function layer = spaceToDepthLayer(stride, padding, name)
layer.Name = name;
layer.Description = sprintf('Rearrangement spatial to depth: stride = [%d,%d]', stride(1), stride(2));
layer.Stride = stride; %2 element vector
layer.Padding = padding; %4 element vector [t b l r]
end
function Z = predict(layer, X)
X = padarray(X, layer.Padding([1 3]), 'pre');
X = padarray(X, layer.Padding([2 4]), 'post');
[H, W, C] = size(X);
Z = reshape(X, H, W*C);
Z = Z';
Z = reshape(Z, layer.Stride(2), W/layer.Stride(2), H);
Z = permute(Z, [1 3 2]);
Z = reshape(Z, layer.Stride(1)*layer.Stride(2), []);
Z = reshape(Z', H/layer.Stride(1), W/layer.Stride(2), []);
end
end
end
  1 comentario
michael kaster
michael kaster el 16 de Sept. de 2020
Hi all,
It works very well in Python.

Respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by