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
80 const size_t kernelWidth,
81 const size_t kernelHeight,
82 const size_t strideWidth = 1,
83 const size_t strideHeight = 1,
84 const size_t padW = 0,
85 const size_t padH = 0,
86 const size_t inputWidth = 0,
87 const size_t inputHeight = 0,
88 const size_t outputWidth = 0,
89 const size_t outputHeight = 0,
90 const std::string& paddingType =
"None");
121 const size_t outSize,
122 const size_t kernelWidth,
123 const size_t kernelHeight,
124 const size_t strideWidth,
125 const size_t strideHeight,
126 const std::tuple<size_t, size_t>& padW,
127 const std::tuple<size_t, size_t>& padH,
128 const size_t inputWidth = 0,
129 const size_t inputHeight = 0,
130 const size_t outputWidth = 0,
131 const size_t outputHeight = 0,
132 const std::string& paddingType =
"None");
146 template<
typename eT>
147 void Forward(
const arma::Mat<eT>&& input, arma::Mat<eT>&& output);
158 template<
typename eT>
159 void Backward(
const arma::Mat<eT>&& ,
170 template<
typename eT>
171 void Gradient(
const arma::Mat<eT>&& ,
172 arma::Mat<eT>&& error,
173 arma::Mat<eT>&& gradient);
191 OutputDataType
const&
Delta()
const {
return delta; }
193 OutputDataType&
Delta() {
return delta; }
196 OutputDataType
const&
Gradient()
const {
return gradient; }
267 arma::mat&
Bias() {
return bias; }
272 template<
typename Archive>
273 void serialize(Archive& ar,
const unsigned int );
282 template<
typename eT>
283 void Rotate180(
const arma::Cube<eT>& input, arma::Cube<eT>& output)
285 output = arma::Cube<eT>(input.n_rows, input.n_cols, input.n_slices);
288 for (
size_t s = 0; s < output.n_slices; s++)
289 output.slice(s) = arma::fliplr(arma::flipud(input.slice(s)));
295 void InitializeSamePadding();
303 template<
typename eT>
304 void Rotate180(
const arma::Mat<eT>& input, arma::Mat<eT>& output)
307 output = arma::fliplr(arma::flipud(input));
320 template<
typename eT>
321 void InsertZeros(
const arma::Mat<eT>& input,
322 const size_t strideWidth,
323 const size_t strideHeight,
324 arma::Mat<eT>& output)
326 if (output.n_rows != input.n_rows * strideWidth - strideWidth + 1 ||
327 output.n_cols != input.n_cols * strideHeight - strideHeight + 1)
329 output = arma::zeros(input.n_rows * strideWidth - strideWidth + 1,
330 input.n_cols * strideHeight - strideHeight + 1);
333 for (
size_t i = 0; i < output.n_rows; i += strideHeight)
335 for (
size_t j = 0; j < output.n_cols; j += strideWidth)
339 output(i, j) = input(i / strideHeight, j / strideWidth);
353 template<
typename eT>
354 void InsertZeros(
const arma::Cube<eT>& input,
355 const size_t strideWidth,
356 const size_t strideHeight,
357 arma::Cube<eT>& output)
359 output = arma::zeros(input.n_rows * strideWidth - strideWidth + 1,
360 input.n_cols * strideHeight - strideHeight + 1, input.n_slices);
362 for (
size_t i = 0; i < input.n_slices; ++i)
364 InsertZeros<eT>(input.slice(i), strideWidth, strideHeight,
409 OutputDataType weights;
430 arma::cube outputTemp;
433 arma::cube inputTemp;
436 arma::cube inputPaddedTemp;
439 arma::cube inputExpandedTemp;
445 arma::cube gradientTemp;
454 OutputDataType delta;
457 OutputDataType gradient;
460 InputDataType inputParameter;
463 OutputDataType outputParameter;
471 namespace serialization {
474 typename ForwardConvolutionRule,
475 typename BackwardConvolutionRule,
476 typename GradientConvolutionRule,
477 typename InputDataType,
478 typename OutputDataType
481 mlpack::ann::TransposedConvolution<ForwardConvolutionRule,
482 BackwardConvolutionRule, GradientConvolutionRule, InputDataType,
485 BOOST_STATIC_CONSTANT(
int, value = 1);
492 #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...
size_t & PadWLeft()
Modify the left padding width.
OutputDataType const & Gradient() const
Get the gradient.
OutputDataType & Parameters()
Modify the parameters.
Set the serialization version of the adaboost class.
size_t const & OutputHeight() const
Get the output height.
size_t const & InputHeight() const
Get the input height.
Implementation of the Padding module class.
size_t & StrideHeight()
Modify the stride height.
OutputDataType & Delta()
Modify the delta.
The core includes that mlpack expects; standard C++ includes and Armadillo.
size_t & InputHeight()
Modify the input height.
size_t & KernelWidth()
Modify the kernel width.
size_t & PadHTop()
Modify the top padding height.
size_t & PadWRight()
Modify the right padding width.
size_t PadWLeft() const
Get the left padding width.
OutputDataType const & OutputParameter() const
Get the output parameter.
size_t PadHTop() const
Get the top padding height.
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.
size_t & StrideWidth()
Modify the stride width.
TransposedConvolution()
Create the Transposed Convolution object.
size_t KernelHeight() const
Get the kernel height.
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
OutputDataType & Gradient()
Modify the gradient.
size_t & KernelHeight()
Modify the kernel height.
InputDataType const & InputParameter() const
Get the input parameter.
OutputDataType const & Delta() const
Get the delta.
size_t & PadHBottom()
Modify the bottom padding height.
size_t & OutputWidth()
Modify the output width.
size_t OutputSize() const
Get the output size.
size_t & InputWidth()
Modify input the width.
size_t KernelWidth() const
Get the kernel width.
size_t InputSize() const
Get the input size.
size_t PadHBottom() const
Get the bottom padding height.
size_t StrideWidth() const
Get the stride width.
OutputDataType & OutputParameter()
Modify the output parameter.
InputDataType & InputParameter()
Modify the input parameter.
size_t PadWRight() const
Get the right padding width.
size_t StrideHeight() const
Get the stride height.
size_t & OutputHeight()
Modify the output height.