13 #ifndef MLPACK_METHODS_ANN_LAYER_TRANSPOSED_CONVOLUTION_HPP 14 #define MLPACK_METHODS_ANN_LAYER_TRANSPOSED_CONVOLUTION_HPP 42 typename ForwardConvolutionRule = NaiveConvolution<ValidConvolution>,
43 typename BackwardConvolutionRule = NaiveConvolution<ValidConvolution>,
44 typename GradientConvolutionRule = NaiveConvolution<ValidConvolution>,
45 typename InputDataType = arma::mat,
46 typename OutputDataType = arma::mat
48 class TransposedConvolution
83 const size_t padW = 0,
84 const size_t padH = 0,
85 const size_t inputWidth = 0,
86 const size_t inputHeight = 0,
87 const size_t outputWidth = 0,
88 const size_t outputHeight = 0);
102 template<
typename eT>
103 void Forward(
const arma::Mat<eT>&& input, arma::Mat<eT>&& output);
114 template<
typename eT>
115 void Backward(
const arma::Mat<eT>&& ,
126 template<
typename eT>
127 void Gradient(
const arma::Mat<eT>&& ,
128 arma::Mat<eT>&& error,
129 arma::Mat<eT>&& gradient);
147 OutputDataType
const&
Delta()
const {
return delta; }
149 OutputDataType&
Delta() {
return delta; }
152 OutputDataType
const&
Gradient()
const {
return gradient; }
177 arma::mat&
Bias() {
return bias; }
182 template<
typename Archive>
183 void serialize(Archive& ar,
const unsigned int );
192 template<
typename eT>
193 void Rotate180(
const arma::Cube<eT>& input, arma::Cube<eT>& output)
195 output = arma::Cube<eT>(input.n_rows, input.n_cols, input.n_slices);
198 for (
size_t s = 0; s < output.n_slices; s++)
199 output.slice(s) = arma::fliplr(arma::flipud(input.slice(s)));
208 template<
typename eT>
209 void Rotate180(
const arma::Mat<eT>& input, arma::Mat<eT>& output)
212 output = arma::fliplr(arma::flipud(input));
225 template<
typename eT>
226 void Pad(
const arma::Mat<eT>& input,
231 arma::Mat<eT>& output)
233 if (output.n_rows != input.n_rows + wPad * 2 + wExtra ||
234 output.n_cols != input.n_cols + hPad * 2 + hExtra)
236 output = arma::zeros(input.n_rows + wPad * 2 + wExtra,
237 input.n_cols + hPad * 2 + hExtra);
240 output.submat(wPad, hPad, wPad + input.n_rows - 1,
241 hPad + input.n_cols - 1) = input;
254 template<
typename eT>
255 void Pad(
const arma::Cube<eT>& input,
260 arma::Cube<eT>& output)
262 output = arma::zeros(input.n_rows + wPad * 2 + wExtra,
263 input.n_cols + hPad * 2 + hExtra, input.n_slices);
265 for (
size_t i = 0; i < input.n_slices; ++i)
267 Pad<eT>(input.slice(i), wPad, hPad, wExtra, hExtra, output.slice(i));
280 template<
typename eT>
281 void InsertZeros(
const arma::Mat<eT>& input,
284 arma::Mat<eT>& output)
286 if (output.n_rows != input.n_rows * dW - dW + 1 ||
287 output.n_cols != input.n_cols * dH - dH + 1)
289 output = arma::zeros(input.n_rows * dW - dW + 1,
290 input.n_cols * dH - dH + 1);
293 for (
size_t i = 0; i < output.n_rows; i += dH)
295 for (
size_t j = 0; j < output.n_cols; j += dW)
299 output(i, j) = input(i / dH, j / dW);
313 template<
typename eT>
314 void InsertZeros(
const arma::Cube<eT>& input,
317 arma::Cube<eT>& output)
319 output = arma::zeros(input.n_rows * dW - dW + 1,
320 input.n_cols * dH - dH + 1, input.n_slices);
322 for (
size_t i = 0; i < input.n_slices; ++i)
324 InsertZeros<eT>(input.slice(i), dW, dH, output.slice(i));
362 OutputDataType weights;
383 arma::cube outputTemp;
386 arma::cube inputTemp;
389 arma::cube inputPaddedTemp;
392 arma::cube inputExpandedTemp;
398 arma::cube gradientTemp;
404 OutputDataType delta;
407 OutputDataType gradient;
410 InputDataType inputParameter;
413 OutputDataType outputParameter;
420 #include "transposed_convolution_impl.hpp" arma::mat & Bias()
Modify the bias weights of the layer.
void Forward(const arma::Mat< eT > &&input, arma::Mat< eT > &&output)
Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activ...
OutputDataType const & Gradient() const
Get the gradient.
OutputDataType & Parameters()
Modify the parameters.
size_t const & OutputHeight() const
Get the output height.
size_t const & InputHeight() const
Get the input height.
Implementation of the Padding module class.
OutputDataType & Delta()
Modify the delta.
The core includes that mlpack expects; standard C++ includes and Armadillo.
size_t & InputHeight()
Modify the input height.
OutputDataType const & OutputParameter() const
Get the output parameter.
void Backward(const arma::Mat< eT > &&, arma::Mat< eT > &&gy, arma::Mat< eT > &&g)
Ordinary feed backward pass of a neural network, calculating the function f(x) by propagating x backw...
OutputDataType const & Parameters() const
Get the parameters.
size_t const & InputWidth() const
Get the input width.
size_t const & OutputWidth() const
Get the output width.
TransposedConvolution()
Create the Transposed Convolution object.
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
OutputDataType & Gradient()
Modify the gradient.
InputDataType const & InputParameter() const
Get the input parameter.
OutputDataType const & Delta() const
Get the delta.
size_t & OutputWidth()
Modify the output width.
size_t & InputWidth()
Modify input the width.
OutputDataType & OutputParameter()
Modify the output parameter.
InputDataType & InputParameter()
Modify the input parameter.
size_t & OutputHeight()
Modify the output height.