Dobiasd / frugally-deep

A lightweight header-only library for using Keras (TensorFlow) models in C++.
MIT License
1.07k stars 236 forks source link

Access to individual elements (probabilities) of the object containing the result. #421

Closed Alex555github closed 2 months ago

Alex555github commented 3 months ago

Hello Tobias! I apologize in advance for a possibly stupid question, I'm a novice C++ programmer. Tobias, please tell me how to get each individual floating-point number from the result object into an arbitrary float array (or in other words, how to access each individual element of the result variable) in this code:

.................... const auto model = fdeep::load_model(model_path);

const auto result = model.predict( {fdeep::tensor(fdeep::tensor_shape(static_cast(5)), std::vector{0.0, 0.0, 0.0, 0.0, 1284.0})}); std::cout << fdeep::show_tensors(result) << std::endl; ....................................... Output:

[[[[[[0.2695, 0.7305]]]]]]. How to access the numbers 0.2695, 0.7305 through the result object and store them in an array or separate float variables. Thank you very much in advance.

Dobiasd commented 3 months ago

Hi, I suggest having a look at

"How to convert an fdeep::tensor to an std::vector?"

in the FAQ:

https://github.com/Dobiasd/frugally-deep/blob/master/FAQ.md#how-to-convert-an-fdeeptensor-to-an-stdvectorfloat