NeuralEngine A Game Engine with embeded Machine Learning algorithms based on Gaussian Processes. |

FgArrayFireSerialization.h
1#pragma once
2
3#undef min
4#undef max
5
6#include <MachineLearning/FgOpenCVSerialization.h>
7#include <MachineLearning/FgAfCv.h>
8
9 namespace boost
10{
11 namespace serialization
12 {
13 template<class Archive>
14 void serialize(Archive &ar, af::array& mat, const unsigned int)
15 {
16 cv::Mat ser;
17 std::vector<cv::Mat> vec;
18
19 if (Archive::is_saving::value)
20 {
21 if (mat.type() == af::dtype::f64)
22 {
23 for (int i = 0; i < mat.dims(2); i++)
24 vec.push_back(NeuralEngine::MachineLearning::AfCv::ArrayToMat(mat(af::span, af::span, i), CV_64F));
25 }
26 else
27 {
28 for (int i = 0; i < mat.dims(2); i++)
29 vec.push_back(NeuralEngine::MachineLearning::AfCv::ArrayToMat(mat(af::span, af::span, i)));
30 }
31 }
32
33
34 ar& BOOST_SERIALIZATION_NVP(vec);
35
36 if (Archive::is_loading::value) NeuralEngine::MachineLearning::AfCv::MatToArray(vec, mat);
37 }
38 }
39}
NeuralEngine::MachineLearning::AfCv::ArrayToMat
static void ArrayToMat(const af::array &input_, cv::Mat &output, int type=CV_32F)
Array to matrix.
NeuralEngine::MachineLearning::AfCv::MatToArray
static void MatToArray(const std::vector< cv::Mat > &input, af::array &output)
Matrix to array.