-
-
Save Dobiasd/966334bb867d170b334c8374e635cb9b to your computer and use it in GitHub Desktop.
Copy values from Eigen::Matrix to fdeep::tensor3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copy values from Eigen::Matrix to fdeep::tensor5 | |
#include <iostream> | |
#include <eigen3/Eigen/Dense> | |
#include <fdeep/fdeep.hpp> | |
int main() | |
{ | |
// dimensions of the eigen matrix | |
const int rows = 640; | |
const int cols = 480; | |
// matrix having its own memory | |
Eigen::MatrixXf mat(rows, cols); | |
// populate mapped_matrix some way | |
mat(0, 0) = 4.0f; | |
mat(1, 1) = 5.0f; | |
mat(4, 2) = 6.0f; | |
// create fdeep::tensor5 with its own memory | |
const int tensor5_channels = 1; | |
const int tensor5_rows = rows; | |
const int tensor5_cols = cols; | |
fdeep::shape5 tensor5_shape(1, 1, tensor5_rows, tensor5_cols, tensor5_channels); | |
fdeep::tensor5 t(tensor5_shape, 0.0f); | |
// copy the values into tensor5 | |
for (int y = 0; y < tensor5_rows; ++y) | |
{ | |
for (int x = 0; x < tensor5_cols; ++x) | |
{ | |
for (int c = 0; c < tensor5_channels; ++c) | |
{ | |
t.set(0, 0, y, x, c, mat(y, x)); | |
} | |
} | |
} | |
// print some values to make sure the mapping is correct | |
std::cout << t.get(0, 0, 0, 0, 0) << std::endl; | |
std::cout << t.get(0, 0, 0, 1, 1) << std::endl; | |
std::cout << t.get(0, 0, 0, 4, 2) << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment