Of course one can use fdeep::tensor5
as the primary data structure and fill it with values like so:
#include <fdeep/fdeep.hpp>
int main()
{
fdeep::tensor5 t(fdeep::shape5(1, 1, 3, 1, 1), 0);
t.set(0, 0, 0, 0, 0, 1);
t.set(0, 0, 1, 0, 0, 2);
t.set(0, 0, 2, 0, 0, 3);
}
But in case one already has an std::vector<float>
with values, one might want to re-use it.
So the std::vector<float>
needs to be converted to fplus::shared_ref<std::vector<float>>
for fdeep::tensor
to accept it in its constructor.
T
can be converted to fplus::shared_ref<T>
by using fplus::make_shared_ref<T>
:
#include <fdeep/fdeep.hpp>
int main()
{
const std::vector<float> v = {1, 2, 3};
const fdeep::shared_float_vec sv(fplus::make_shared_ref<fdeep::float_vec>(v));
fdeep::tensor5 t(fdeep::shape5(1, 1, 3, 1, 1), sv);
}
In case the original vector is no longer needed, the copy of the value can be avoided by making it an r-value with std::move
:
#include <fdeep/fdeep.hpp>
int main()
{
const std::vector<float> v = {1, 2, 3};
const fdeep::shared_float_vec sv(fplus::make_shared_ref<fdeep::float_vec>(std::move(v)));
fdeep::tensor5 t(fdeep::shape5(1, 1, 3, 1, 1), sv);
}
Thanks for the example. Can this be updated to reflect that
fdeep::shape3
has changed its name tofdeep::shape_hwc
? I had to go code hunting to find the change