serizba / cppflow

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

get_data function error #149

Closed vahid-nateghi closed 2 years ago

vahid-nateghi commented 2 years ago

Hello, I want to load my model using the Complex Model Call. When I call my model in default mode, I can use get_data() function but when I call my model with specified signature I receive an error as below:

error: ‘class std::vector’ has no member named ‘get_data’

I used the signature that I found using get.operations() function.

Can you help me out here? I need to specify the signature, as I need to load two different models in one script and if I do not specify, for the second one, I receive an error saying there is no operation named "serving_default_input_1" which is reasonable based on the previous closed issues here.

Thanks in advance.

dskkato commented 2 years ago

Can you provide your code and signatures of your models to reproduce the errors?

You can also compare your code with the following example whici shows a complex model invoking you mentioned.

https://github.com/serizba/cppflow/tree/master/examples/multi_input_output

vahid-nateghi commented 2 years ago

Thanks for your quick reply. Actually I could manage to solve the issue but I did not understand why it was the solution. These are the two different ways of calling the model:

auto output = model (input); auto output1 = model ({{"serving_default_input_1:0", input}},{"StatefulPartitionedCall:0"});

Then when I want to use get_data for the first way of calling, I need to say:

std::vector myvector = output.get_data();

But when I want to use get_data for the second way of calling, I need to say:

std::vector myvector = output1[0].get_data();

It works like that but I do not know why!

dskkato commented 2 years ago

It's because you are calling different member functions based on arguments.

The former:

auto output = model (input);
std::vector myvector = output.get_data();

calls the following member function that returns a tensor.

https://github.com/serizba/cppflow/blob/883eb4c526979dae56f921571b1ab93df85a0a0d/include/cppflow/model.h#L169

While the latter

 auto output1 = model ({{"serving_default_input_1:0", input}},{"StatefulPartitionedCall:0"});

calls this function that returns a std::vector<tensor>.

https://github.com/serizba/cppflow/blob/883eb4c526979dae56f921571b1ab93df85a0a0d/include/cppflow/model.h#L122

This is the reason you need indexing for the latter case.

vahid-nateghi commented 2 years ago

I see. Yes, I did not pay attention to the function that is called. Ok then. Thanks for your help. I will close the issue.