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

Can cppflow2 directly call pb files? #156

Closed swin223 closed 2 years ago

swin223 commented 2 years ago

Hello, dear developer,I'm learning cppflow2 recently and want to ask a question. In the example of cppflow2, cppflow2 can directly load the model saved with the (.save) function in the python script.

Can I directly use cppflow2 to rebuild the "mnist" example in cppflow1?Is there a way for cppflow2 to directly call the pb file in this example?

dskkato commented 2 years ago

152 may be the way you're looking.

swin223 commented 2 years ago

Thank you, this looks like the way I am looking for. After reading the link you gave, I found an example (load_frozen_graph--it can directly call the .pb file) in this link. But when I ran this example on my computer, an error occurred.The error message is as follows:

SavedModel load for tags { serve }; Status: fail: Not found: Could not find SavedModel .pb or .pbtxt at supplied export directory path: ../model.pb. Took 12592 microseconds.
terminate called after throwing an instance of 'std::runtime_error'
  what():  Could not find SavedModel .pb or .pbtxt at supplied export directory path: ../model.pb

I have tried many ways to solve this error(for example, put the pb file into the "model" folder and load it, but it will not run)

If anyone has run this example successfully, please tell me.

In order to better use cppflow, should I use python to learn tensorflow first?Because there are many function interfaces in cppflow, I don't know what they mean, and I don't know how to call them.

ljn917 commented 2 years ago

I guess cppflow1 is better if you want to load pb files. Commit c38997cbc2fdde9e77002c302d891cbd30ceab87 is the last cppflow1.

dskkato commented 2 years ago

Thank you, this looks like the way I am looking for. After reading the link you gave, I found an example (load_frozen_graph--it can directly call the .pb file) in this link. But when I ran this example on my computer, an error occurred.The error message is as follows:

SavedModel load for tags { serve }; Status: fail: Not found: Could not find SavedModel .pb or .pbtxt at supplied export directory path: ../model.pb. Took 12592 microseconds.
terminate called after throwing an instance of 'std::runtime_error'
  what():  Could not find SavedModel .pb or .pbtxt at supplied export directory path: ../model.pb

Its a problem of example code. You need to instantiate model class with

    cppflow::model model("../model.pb", cppflow::model::FROZEN_GRAPH);

, not

    cppflow::model model("../model.pb", {});
swin223 commented 2 years ago

I guess cppflow1 is better if you want to load pb files. Commit c38997c is the last cppflow1. Ok,thanks. But I think cppflow2 is more convenient to use, so I want to consult how to call pb files on cppflow2.

swin223 commented 2 years ago

Its a problem of example code. You need to instantiate model class with

    cppflow::model model("../model.pb", cppflow::model::FROZEN_GRAPH);

, not

    cppflow::model model("../model.pb", {});

Yes, this example will work when I modify it as you suggested.

Does cppflow2 only have a few examples?In addition to this website, where can I get learning materials for cppflow2?Because I don’t know what function interfaces exist in cppflow2 and what they can do.

dskkato commented 2 years ago

Does cppflow2 only have a few examples?In addition to this website, where can I get learning materials for cppflow2?Because I don’t know what function interfaces exist in cppflow2 and what they can do.

That site is the only documentation for this cppflow. In general, TensorFlow has little documentation except for Python, and wrappers for other languages are outside the scope of TensorFlow itself. See: https://www.tensorflow.org/api_docs

Since this cppflow is the one of wrappers, so I recommend using limited functions like constructing Tensor and model inferences. If you are familiar with TensorFlow, you could use low level ops through raw_ops defined in ops.h and raw_ops.h. However, you should be aware that raw_ops itself is not well documented either.

bytosaur commented 2 years ago

this feature has been enabled in #152 make sure to name the format when calling model()

serizba commented 2 years ago

Yes, this feature is now in the code thanks to #152.