13 #ifndef MLPACK_METHODS_ANN_LAYER_TRANSPOSED_CONVOLUTION_HPP 14 #define MLPACK_METHODS_ANN_LAYER_TRANSPOSED_CONVOLUTION_HPP 41 typename ForwardConvolutionRule = NaiveConvolution<ValidConvolution>,
42 typename BackwardConvolutionRule = NaiveConvolution<FullConvolution>,
43 typename GradientConvolutionRule = NaiveConvolution<ValidConvolution>,
44 typename InputDataType = arma::mat,
45 typename OutputDataType = arma::mat
47 class TransposedConvolution
74 const size_t padW = 0,
75 const size_t padH = 0,
76 const size_t inputWidth = 0,
77 const size_t inputHeight = 0);
92 void Forward(
const arma::Mat<eT>&& input, arma::Mat<eT>&& output);
103 template<
typename eT>
104 void Backward(
const arma::Mat<eT>&& ,
115 template<
typename eT>
116 void Gradient(
const arma::Mat<eT>&& ,
117 arma::Mat<eT>&& error,
118 arma::Mat<eT>&& gradient);
136 OutputDataType
const&
Delta()
const {
return delta; }
138 OutputDataType&
Delta() {
return delta; }
141 OutputDataType
const&
Gradient()
const {
return gradient; }
168 template<
typename Archive>
169 void serialize(Archive& ar,
const unsigned int );
181 size_t TransposedConvOutSize(
const size_t size,
186 size_t out = std::floor(size - k + 2 * p) / s;
187 return out * s + 2 * (k - p) - 1 + ((((size + 2 * p - k) % s) + s) % s);
196 template<
typename eT>
197 void Rotate180(
const arma::Cube<eT>& input, arma::Cube<eT>& output)
199 output = arma::Cube<eT>(input.n_rows, input.n_cols, input.n_slices);
202 for (
size_t s = 0; s < output.n_slices; s++)
203 output.slice(s) = arma::fliplr(arma::flipud(input.slice(s)));
212 template<
typename eT>
213 void Rotate180(
const arma::Mat<eT>& input, arma::Mat<eT>& output)
216 output = arma::fliplr(arma::flipud(input));
227 template<
typename eT>
228 void Pad(
const arma::Mat<eT>& input,
231 arma::Mat<eT>& output)
233 if (output.n_rows != input.n_rows + wPad * 2 ||
234 output.n_cols != input.n_cols + hPad * 2)
236 output = arma::zeros(input.n_rows + wPad * 2, input.n_cols + hPad * 2);
239 output.submat(wPad, hPad, wPad + input.n_rows - 1,
240 hPad + input.n_cols - 1) = input;
251 template<
typename eT>
252 void Pad(
const arma::Cube<eT>& input,
255 arma::Cube<eT>& output)
257 output = arma::zeros(input.n_rows + wPad * 2,
258 input.n_cols + hPad * 2, input.n_slices);
260 for (
size_t i = 0; i < input.n_slices; ++i)
262 Pad<eT>(input.slice(i), wPad, hPad, output.slice(i));
294 OutputDataType weights;
315 arma::cube outputTemp;
318 arma::cube inputTemp;
321 arma::cube inputPaddedTemp;
327 arma::cube gradientTemp;
330 OutputDataType delta;
333 OutputDataType gradient;
336 InputDataType inputParameter;
339 OutputDataType outputParameter;
346 #include "transposed_convolution_impl.hpp" 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.
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.