serizba / cppflow

Run TensorFlow models in C++ without installation and without Bazel
https://serizba.github.io/cppflow/
MIT License
774 stars 177 forks source link

Error while running the example #233

Closed lilingnan closed 1 year ago

lilingnan commented 1 year ago

Hi,I like the function of cppflow very much, but I encountered an error when I tried to run an example after installing, and it didn't work even after updating the gcc version to 9.4.0.Do you know what is the reason?

error was: main.cpp: In function ‘int main()’: main.cpp:45:30: error: could not convert ‘input’ from ‘cppflow::tensor’ to ‘std::cxx11::string {aka std::cxx11::basic_string}’ auto output = model(input); ^ main.cpp:49:35: error: expected primary-expression before ‘float’ auto values = output.get_data(); ^~~~~ main.cpp:51:19: error: unable to deduce ‘auto&&’ from ‘values’ for (auto v : values) {

thanks, li

serizba commented 1 year ago

Hi!

Can you provide a complete example of what you are trying to do? With just two lines of code is difficult to tell.

On thing that I see is that you are not telling your datatype when using get_data, it should be something like output.get_data<float>().

lilingnan commented 1 year ago

Hi! thank you for replying me! I just tried the simple example that you offered to us:

include <cppflow/ops.h>

include <cppflow/model.h>

// C++ headers

include

int main() { auto input = cppflow::fill({10, 5}, 1.0f); cppflow::model model(std::string(MODEL_PATH)); auto output = model(input);

std::cout << output << std::endl;

auto values = output.get_data<float>();

for (auto v : values) {
    std::cout << v << std::endl;
}
return 0;

}

and "auto" reports an error as "explicit type is missing("int" assumed)

thanks, li

serizba commented 1 year ago

Is that the only code you are using?

Could you post the complete error you getting?

lilingnan commented 1 year ago

Yes, only this one

Screenshot from 2023-01-11 20-24-06

main.cpp: In function ‘int main()’: main.cpp:45:25: error: could not convert ‘input’ from ‘cppflow::tensor’ to ‘std::string’ {aka ‘std::__cxx11::basic_string’} 45 auto output = model(input); ^~~~~
cppflow::tensor

main.cpp:49:35: error: expected primary-expression before ‘float’ 49 | auto values = output.get_data(); | ^~~~~

serizba commented 1 year ago

It looks like the compiler is not finding the MODEL_PATH var. Check if it's declared in the CMakeLists.txt, or change the path directly in the code:

cppflow::model model(std::string("/path/to/model"));

lilingnan commented 1 year ago

Thank you so much for replying me patiently, the problem has been successfully solved! thanks and happy new year!

serizba commented 1 year ago

You're welcome!