[mlpack-git] master: Add convolution batch mode. (c122d05)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Sun Apr 26 06:55:53 EDT 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/fbd6b1f878ec3b2fa365254a22daf3add743ee51...2eb28bcc2ada2fe09a7ad7073c0bbcbb96aac0c5
>---------------------------------------------------------------
commit c122d05a46301d17ed4721f5e76829c86ba23a15
Author: Marcus Edel <marcus.edel at fu-berlin.de>
Date: Sat Apr 25 16:34:36 2015 +0200
Add convolution batch mode.
>---------------------------------------------------------------
c122d05a46301d17ed4721f5e76829c86ba23a15
.../ann/convolution_rules/fft_convolution.hpp | 34 +++++++++++++++++++++-
.../ann/convolution_rules/naive_convolution.hpp | 28 ++++++++++++++++++
.../ann/convolution_rules/svd_convolution.hpp | 29 ++++++++++++++++++
3 files changed, 90 insertions(+), 1 deletion(-)
diff --git a/src/mlpack/methods/ann/convolution_rules/fft_convolution.hpp b/src/mlpack/methods/ann/convolution_rules/fft_convolution.hpp
index a7cd366..d247e33 100644
--- a/src/mlpack/methods/ann/convolution_rules/fft_convolution.hpp
+++ b/src/mlpack/methods/ann/convolution_rules/fft_convolution.hpp
@@ -116,7 +116,7 @@ class FFTConvolution
}
/*
- * Perform a convolution through using fft 3rd order tensors. This method only
+ * Perform a convolution through fft using 3rd order tensors. This method only
* supports input which is even on the last dimension. In case of an odd input
* width, a user can manually pad the imput or specify the padLastDim
* parameter which takes care of the padding. The filter instead can have any
@@ -146,6 +146,38 @@ class FFTConvolution
output.slice(i) = convOutput;
}
}
+
+ /*
+ * Perform a convolution through fft using dense matrix as input and a 3rd
+ * order tensors as filter and output. This method only supports input which
+ * is even on the last dimension. In case of an odd input width, a user can
+ * manually pad the imput or specify the padLastDim parameter which takes care
+ * of the padding. The filter instead can have any size.
+ *
+ * @param input Input used to perform the convolution.
+ * @param filter Filter used to perform the conolution.
+ * @param output Output data that contains the results of the convolution.
+ */
+ template<typename eT>
+ static void Convolution(const arma::Mat<eT>& input,
+ const arma::Cube<eT>& filter,
+ arma::Cube<eT>& output)
+ {
+ arma::Mat<eT> convOutput;
+ FFTConvolution<BorderMode>::Convolution(input, filter.slice(0),
+ convOutput);
+
+ output = arma::Cube<eT>(convOutput.n_rows, convOutput.n_cols,
+ filter.n_slices);
+ output.slice(0) = convOutput;
+
+ for (size_t i = 1; i < filter.n_slices; i++)
+ {
+ FFTConvolution<BorderMode>::Convolution(input, filter.slice(i),
+ convOutput);
+ output.slice(i) = convOutput;
+ }
+ }
}; // class FFTConvolution
}; // namespace ann
diff --git a/src/mlpack/methods/ann/convolution_rules/naive_convolution.hpp b/src/mlpack/methods/ann/convolution_rules/naive_convolution.hpp
index 5934131..45c75fd 100644
--- a/src/mlpack/methods/ann/convolution_rules/naive_convolution.hpp
+++ b/src/mlpack/methods/ann/convolution_rules/naive_convolution.hpp
@@ -120,6 +120,34 @@ class NaiveConvolution
output.slice(i));
}
}
+
+ /*
+ * Perform a convolution using dense matrix as input and a 3rd order tensors
+ * as filter and output.
+ *
+ * @param input Input used to perform the convolution.
+ * @param filter Filter used to perform the conolution.
+ * @param output Output data that contains the results of the convolution.
+ */
+ template<typename eT>
+ static void Convolution(const arma::Mat<eT>& input,
+ const arma::Cube<eT>& filter,
+ arma::Cube<eT>& output)
+ {
+ arma::Mat<eT> convOutput;
+ NaiveConvolution<BorderMode>::Convolution(input, filter.slice(0),
+ convOutput);
+
+ output = arma::Cube<eT>(convOutput.n_rows, convOutput.n_cols,
+ filter.n_slices);
+ output.slice(0) = convOutput;
+
+ for (size_t i = 1; i < filter.n_slices; i++)
+ {
+ NaiveConvolution<BorderMode>::Convolution(input, filter.slice(i),
+ output.slice(i));
+ }
+ }
}; // class NaiveConvolution
}; // namespace ann
diff --git a/src/mlpack/methods/ann/convolution_rules/svd_convolution.hpp b/src/mlpack/methods/ann/convolution_rules/svd_convolution.hpp
index 3a49684..95d7997 100644
--- a/src/mlpack/methods/ann/convolution_rules/svd_convolution.hpp
+++ b/src/mlpack/methods/ann/convolution_rules/svd_convolution.hpp
@@ -129,6 +129,35 @@ class SVDConvolution
output.slice(i) = convOutput;
}
}
+
+ /*
+ * Perform a convolution using dense matrix as input and a 3rd order tensors
+ * as filter and output.
+ *
+ * @param input Input used to perform the convolution.
+ * @param filter Filter used to perform the conolution.
+ * @param output Output data that contains the results of the convolution.
+ */
+ template<typename eT>
+ static void Convolution(const arma::Mat<eT>& input,
+ const arma::Cube<eT>& filter,
+ arma::Cube<eT>& output)
+ {
+ arma::Mat<eT> convOutput;
+ SVDConvolution<BorderMode>::Convolution(input, filter.slice(0),
+ convOutput);
+
+ output = arma::Cube<eT>(convOutput.n_rows, convOutput.n_cols,
+ filter.n_slices);
+ output.slice(0) = convOutput;
+
+ for (size_t i = 1; i < filter.n_slices; i++)
+ {
+ SVDConvolution<BorderMode>::Convolution(input, filter.slice(i),
+ convOutput);
+ output.slice(i) = convOutput;
+ }
+ }
}; // class SVDConvolution
}; // namespace ann
More information about the mlpack-git
mailing list