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

Proper syntax for loading a metagraph #164

Closed JordanDavis-1 closed 2 years ago

JordanDavis-1 commented 2 years ago

Hello! First off I want to say that I am relatively new to Tensorflow but I am rapidly learning a lot. I currently have a project I'm trying to implement in C++ and thankful for stumbling upon cppflow. My understanding of C++ is also rusty but it's quickly coming back.

I am training a model in Python and would like to restore it for inference using cppflow within my app. It would be insightful if someone could help me reinterpret this python code below into how it could be loaded then ran using cppflow. The model is being restored from a checkpoint file.

_x = (np.random.rand(1, 100) * 2.) - 1.

x = graph.get_tensor_by_name('x:0')
D_z = graph.get_tensor_by_name('D_z:0')[:, :, 0]
_D_z = sess.run(G_z, {x: _x})

Any help would be appreciated and would help me move forward in my project and understanding!

ljn917 commented 2 years ago

cppflow v1 loads ckpt file easier than v2. v2 currently only supports loading SavedModel. I think there was a PR for adding ckpt file support into v2 before.

On Wed, Dec 1, 2021, 01:42 JordanDavis-1 @.***> wrote:

Hello! First off I want to say that I am relatively new to Tensorflow but I am rapidly learning a lot. I currently have a project I'm trying to implement in C++ and thankful for stumbling upon cppflow. My understanding of C++ is also rusty but it's quickly coming back.

I am training a model in Python and would like to restore it for inference using cppflow within my app. It would be insightful if someone could help me reinterpret this python code below into how it could be loaded then ran using cppflow. The model is being restored from a checkpoint file.

_x = (np.random.rand(1, 100) * 2.) - 1.

x = graph.get_tensor_by_name('x:0') D_z = graph.get_tensor_by_name('D_z:0')[:, :, 0] _D_z = sess.run(G_z, {x: _x})

Any help would be appreciated and would help me move forward in my project and understanding!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/serizba/cppflow/issues/164, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALDTHRCIDZKUPWOH4L3CVDUOW7TRANCNFSM5JDVBXNQ .

JordanDavis-1 commented 2 years ago

Thanks for your quick reply! Ahh that makes sense. Would it be easier for me to just convert it to a SavedModel?

I will downgrade to v1 then if not. (What would be the syntax for v1?)

ljn917 commented 2 years ago

https://github.com/serizba/cppflow/blob/c38997cbc2fdde9e77002c302d891cbd30ceab87/examples/mnist/main.cpp

On Wed, Dec 1, 2021, 02:04 JordanDavis-1 @.***> wrote:

Thanks for your quick reply! Ahh that makes sense. I will downgrade to v1 then if that's the case. What would be the syntax for v1?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/serizba/cppflow/issues/164#issuecomment-983349429, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALDTHQ3GIS2DZDOYUQLRU3UOXCINANCNFSM5JDVBXNQ .