13#ifndef MLPACK_METHODS_ANN_LAYER_TRANSPOSED_CONVOLUTION_HPP
14#define MLPACK_METHODS_ANN_LAYER_TRANSPOSED_CONVOLUTION_HPP
43 typename ForwardConvolutionRule = NaiveConvolution<ValidConvolution>,
44 typename BackwardConvolutionRule = NaiveConvolution<ValidConvolution>,
45 typename GradientConvolutionRule = NaiveConvolution<ValidConvolution>,
46 typename InputDataType = arma::mat,
47 typename OutputDataType = arma::mat
81 const size_t kernelWidth,
82 const size_t kernelHeight,
83 const size_t strideWidth = 1,
84 const size_t strideHeight = 1,
85 const size_t padW = 0,
86 const size_t padH = 0,
87 const size_t inputWidth = 0,
88 const size_t inputHeight = 0,
89 const size_t outputWidth = 0,
90 const size_t outputHeight = 0,
91 const std::string& paddingType =
"None");
122 const size_t outSize,
123 const size_t kernelWidth,
124 const size_t kernelHeight,
125 const size_t strideWidth,
126 const size_t strideHeight,
127 const std::tuple<size_t, size_t>& padW,
128 const std::tuple<size_t, size_t>& padH,
129 const size_t inputWidth = 0,
130 const size_t inputHeight = 0,
131 const size_t outputWidth = 0,
132 const size_t outputHeight = 0,
133 const std::string& paddingType =
"None");
147 template<
typename eT>
148 void Forward(
const arma::Mat<eT>& input, arma::Mat<eT>& output);
159 template<
typename eT>
161 const arma::Mat<eT>& gy,
171 template<
typename eT>
173 const arma::Mat<eT>& error,
174 arma::Mat<eT>& gradient);
182 arma::cube
const&
Weight()
const {
return weight; }
187 arma::mat
const&
Bias()
const {
return bias; }
189 arma::mat&
Bias() {
return bias; }
202 OutputDataType
const&
Delta()
const {
return delta; }
204 OutputDataType&
Delta() {
return delta; }
207 OutputDataType
const&
Gradient()
const {
return gradient; }
280 template<
typename Archive>
290 template<
typename eT>
291 void Rotate180(
const arma::Cube<eT>& input, arma::Cube<eT>& output)
293 output = arma::Cube<eT>(input.n_rows, input.n_cols, input.n_slices);
296 for (
size_t s = 0; s < output.n_slices; s++)
297 output.slice(s) = arma::fliplr(arma::flipud(input.slice(s)));
303 void InitializeSamePadding();
311 template<
typename eT>
312 void Rotate180(
const arma::Mat<eT>& input, arma::Mat<eT>& output)
315 output = arma::fliplr(arma::flipud(input));
328 template<
typename eT>
329 void InsertZeros(
const arma::Mat<eT>& input,
330 const size_t strideWidth,
331 const size_t strideHeight,
332 arma::Mat<eT>& output)
334 if (output.n_rows != input.n_rows * strideWidth - strideWidth + 1 ||
335 output.n_cols != input.n_cols * strideHeight - strideHeight + 1)
337 output = arma::zeros(input.n_rows * strideWidth - strideWidth + 1,
338 input.n_cols * strideHeight - strideHeight + 1);
341 for (
size_t i = 0; i < output.n_rows; i += strideHeight)
343 for (
size_t j = 0; j < output.n_cols; j += strideWidth)
347 output(i, j) = input(i / strideHeight, j / strideWidth);
361 template<
typename eT>
362 void InsertZeros(
const arma::Cube<eT>& input,
363 const size_t strideWidth,
364 const size_t strideHeight,
365 arma::Cube<eT>& output)
367 output = arma::zeros(input.n_rows * strideWidth - strideWidth + 1,
368 input.n_cols * strideHeight - strideHeight + 1, input.n_slices);
370 for (
size_t i = 0; i < input.n_slices; ++i)
372 InsertZeros<eT>(input.slice(i), strideWidth, strideHeight,
417 OutputDataType weights;
438 arma::cube outputTemp;
441 arma::cube inputPaddedTemp;
444 arma::cube inputExpandedTemp;
450 arma::cube gradientTemp;
453 ann::Padding<> paddingForward;
456 ann::Padding<> paddingBackward;
459 OutputDataType delta;
462 OutputDataType gradient;
465 InputDataType inputParameter;
468 OutputDataType outputParameter;
476namespace serialization {
479 typename ForwardConvolutionRule,
480 typename BackwardConvolutionRule,
481 typename GradientConvolutionRule,
482 typename InputDataType,
483 typename OutputDataType
486 mlpack::ann::TransposedConvolution<ForwardConvolutionRule,
487 BackwardConvolutionRule, GradientConvolutionRule, InputDataType,
497#include "transposed_convolution_impl.hpp"
Implementation of the Transposed Convolution class.
arma::cube const & Weight() const
Get the weight of the layer.
OutputDataType const & Delta() const
Get the delta.
size_t StrideHeight() const
Get the stride height.
OutputDataType const & Parameters() const
Get the parameters.
size_t & PadHTop()
Modify the top padding height.
size_t & InputHeight()
Modify the input height.
TransposedConvolution(const size_t inSize, const size_t outSize, const size_t kernelWidth, const size_t kernelHeight, const size_t strideWidth, const size_t strideHeight, const std::tuple< size_t, size_t > &padW, const std::tuple< size_t, size_t > &padH, const size_t inputWidth=0, const size_t inputHeight=0, const size_t outputWidth=0, const size_t outputHeight=0, const std::string &paddingType="None")
Create the Transposed Convolution object using the specified number of input maps,...
size_t PadWLeft() const
Get the left padding width.
TransposedConvolution(const size_t inSize, const size_t outSize, const size_t kernelWidth, const size_t kernelHeight, const size_t strideWidth=1, const size_t strideHeight=1, const size_t padW=0, const size_t padH=0, const size_t inputWidth=0, const size_t inputHeight=0, const size_t outputWidth=0, const size_t outputHeight=0, const std::string &paddingType="None")
Create the Transposed Convolution object using the specified number of input maps,...
size_t InputWidth() const
Get the input width.
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...
arma::cube & Weight()
Modify the weight of the layer.
InputDataType & InputParameter()
Modify the input parameter.
OutputDataType const & OutputParameter() const
Get the output parameter.
size_t & PadHBottom()
Modify the bottom padding height.
size_t InputSize() const
Get the input size.
size_t & InputWidth()
Modify input the width.
size_t KernelWidth() const
Get the kernel width.
TransposedConvolution()
Create the Transposed Convolution object.
size_t KernelHeight() const
Get the kernel height.
size_t & StrideWidth()
Modify the stride width.
size_t PadHBottom() const
Get the bottom padding height.
arma::mat const & Bias() const
Get the bias of the layer.
size_t & KernelWidth()
Modify the kernel width.
size_t PadWRight() const
Get the right padding width.
size_t & OutputHeight()
Modify the output height.
size_t & PadWRight()
Modify the right padding width.
size_t OutputHeight() const
Get the output height.
size_t OutputSize() const
Get the output size.
void Gradient(const arma::Mat< eT > &, const arma::Mat< eT > &error, arma::Mat< eT > &gradient)
size_t OutputWidth() const
Get the output width.
OutputDataType const & Gradient() const
Get the gradient.
InputDataType const & InputParameter() const
Get the input parameter.
size_t InputHeight() const
Get the input height.
OutputDataType & Gradient()
Modify the gradient.
size_t & KernelHeight()
Modify the kernel height.
size_t & PadWLeft()
Modify the left padding width.
size_t StrideWidth() const
Get the stride width.
size_t & StrideHeight()
Modify the stride height.
void Backward(const arma::Mat< eT > &, const 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 & OutputParameter()
Modify the output parameter.
size_t & OutputWidth()
Modify the output width.
size_t PadHTop() const
Get the top padding height.
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
OutputDataType & Parameters()
Modify the parameters.
arma::mat & Bias()
Modify the bias of the layer.
OutputDataType & Delta()
Modify the delta.
Set the serialization version of the adaboost class.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
BOOST_STATIC_CONSTANT(int, value=1)