GAPI_GPU_KERNEL(GGPUGaussBlur, cv::gapi::imgproc::GGaussBlur) { static void run(const cv::UMat& in, const cv::Size& ksize, double sigmaX, double sigmaY, int borderType, const cv::Scalar& bordVal, cv::UMat &out) { if( borderType == cv::BORDER_CONSTANT ) { cv::UMat temp_in; int width_add = (ksize.width - 1) / 2; int height_add = (ksize.height - 1) / 2; cv::copyMakeBorder(in, temp_in, height_add, height_add, width_add, width_add, borderType, bordVal ); cv::Rect rect = cv::Rect(height_add, width_add, in.cols, in.rows); cv::GaussianBlur(temp_in(rect), out, ksize, sigmaX, sigmaY, borderType); } else cv::GaussianBlur(in, out, ksize, sigmaX, sigmaY, borderType); } };
GAPI_GPU_KERNEL(GGPUBoxFilter, cv::gapi::imgproc::GBoxFilter) { static void run(const cv::UMat& in, int ddepth, const cv::Size& ksize, const cv::Point& anchor, bool normalize, int borderType, const cv::Scalar& bordVal, cv::UMat &out) { if( borderType == cv::BORDER_CONSTANT ) { cv::UMat temp_in; int width_add = (ksize.width - 1) / 2; int height_add = (ksize.height - 1) / 2; cv::copyMakeBorder(in, temp_in, height_add, height_add, width_add, width_add, borderType, bordVal); cv::Rect rect = cv::Rect(height_add, width_add, in.cols, in.rows); cv::boxFilter(temp_in(rect), out, ddepth, ksize, anchor, normalize, borderType); } else cv::boxFilter(in, out, ddepth, ksize, anchor, normalize, borderType); } };
GAPI_OCV_KERNEL(GCPUBlur, cv::gapi::imgproc::GBlur) { static void run(const cv::Mat& in, const cv::Size& ksize, const cv::Point& anchor, int borderType, const cv::Scalar& bordVal, cv::Mat &out) { if( borderType == cv::BORDER_CONSTANT ) { cv::Mat temp_in; int width_add = (ksize.width - 1) / 2; int height_add = (ksize.height - 1) / 2; cv::copyMakeBorder(in, temp_in, height_add, height_add, width_add, width_add, borderType, bordVal); cv::Rect rect = cv::Rect(height_add, width_add, in.cols, in.rows); cv::blur(temp_in(rect), out, ksize, anchor, borderType); } else cv::blur(in, out, ksize, anchor, borderType); } };
GAPI_GPU_KERNEL(GGPUFilter2D, cv::gapi::imgproc::GFilter2D) { static void run(const cv::UMat& in, int ddepth, const cv::Mat& k, const cv::Point& anchor, const cv::Scalar& delta, int border, const cv::Scalar& bordVal, cv::UMat &out) { if( border == cv::BORDER_CONSTANT ) { cv::UMat temp_in; int width_add = (k.cols - 1) / 2; int height_add = (k.rows - 1) / 2; cv::copyMakeBorder(in, temp_in, height_add, height_add, width_add, width_add, border, bordVal ); cv::Rect rect = cv::Rect(height_add, width_add, in.cols, in.rows); cv::filter2D(temp_in(rect), out, ddepth, k, anchor, delta.val[0], border); } else cv::filter2D(in, out, ddepth, k, anchor, delta.val[0], border); } };
void MLP::GetOutput(const std::vector<double> &input, std::vector<double> * output, std::vector<std::vector<double>> * all_layers_activations) const { assert(input.size() == m_num_inputs); int temp_size; if (m_num_hidden_layers == 0) temp_size = m_num_outputs; else temp_size = m_layers_nodes[1]; std::vector<double> temp_in(m_num_inputs, 0.0); std::vector<double> temp_out(temp_size, 0.0); temp_in = input; for (int i = 0; i < m_layers.size(); ++i) { if (i > 0) { //Store this layer activation if (all_layers_activations != nullptr) all_layers_activations->emplace_back(std::move(temp_in)); temp_in.clear(); temp_in = temp_out; temp_out.clear(); temp_out.resize(m_layers[i].GetOutputSize()); } m_layers[i].GetOutputAfterActivationFunction(temp_in, &temp_out); } if (temp_out.size() > 1) utils::Softmax(&temp_out); *output = temp_out; //Add last layer activation if (all_layers_activations != nullptr) all_layers_activations->emplace_back(std::move(temp_in)); }