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

Running cppflow from DLL library #163

Closed tranvanh closed 1 year ago

tranvanh commented 2 years ago

Hi, If cppflow is used inside a DLL library the application gets stuck without throwing any errors at Restoring SavedModel bundle. I'm trying to load a simple TF model inside the DLL, make a prediction, and then include this DLL in main.cpp.

2021-11-16 15:54:37.003453: I tensorflow/cc/saved_model/reader.cc:32] Reading SavedModel from: ./TrainedModel
2021-11-16 15:54:37.070206: I tensorflow/cc/saved_model/reader.cc:55] Reading meta graph with tags { serve }
2021-11-16 15:54:37.070325: I tensorflow/cc/saved_model/reader.cc:93] Reading SavedModel debug info (if present) from: ./TrainedModel`
2021-11-16 15:54:37.070629: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-11-16 15:54:37.491785: I tensorflow/cc/saved_model/loader.cc:206] Restoring SavedModel bundle.

The application gets stuck here without running anything beyond loadModel. Usually, the follow-up lines for successful load would be:

2021-11-16 15:55:39.714093: I tensorflow/cc/saved_model/loader.cc:190] Running initialization op on SavedModel bundle at path: ./TrainedModel
2021-11-16 15:55:39.952420: I tensorflow/cc/saved_model/loader.cc:277] SavedModel load for tags { serve }; Status: success: OK. Took 1138566 microseconds.
dskkato commented 2 years ago

I'm assuming you're using Windows Command Prompt or Powershell, but is it possible to restart the process by pressing enter on the screen where the logging stops? If it does, it's probably not a problem with tensorflow.dll or cppflow.

tranvanh commented 2 years ago

I'm assuming you're using Windows Command Prompt or Powershell, but is it possible to restart the process by pressing enter on the screen where the logging stops? If it does, it's probably not a problem with tensorflow.dll or cppflow.

Yes, I'm running the application on Windows using Visual studio. No key inputs are registered, nor does enter do anything in this case. The application gets stuck in dll initialization, not even getting to the execution of simple print in main.

The cppflow and everything works fine when I use it directly in a console application (loadModel inside main function). The problem starts if you were to create a DLL, which internally loads up a tf model, then import this DLL in some other console application (simple main function with nothing else but a hello world). In my case the logging gets stuck while initializing the DLL(loading the model), not getting to hello world execution.

dskkato commented 2 years ago

Thank you for the information. I understand the configuration that causes this problem. I would like to have the code to reproduce it. Could you please publish the code you have tried on GitHub or somewhere?

tranvanh commented 2 years ago

Thank you for the information. I understand the configuration that causes this problem. I would like to have the code to reproduce it. Could you please publish the code you have tried on GitHub or somewhere?

I have prepared a dummy solution (run in Visual Studio), which should demonstrate the issue. Some basic steps are in the readme, but the solution should be runnable after cloning the repo with no setups needed. If anything is unclear, don't hesitate to hit me up :}.

The repo may seem large due to tensorflow library, which is also included in the repo.

https://github.com/tranvanh/TestDll/tree/master

serizba commented 2 years ago

@tranvanh

Can you check if the last changes fixed your error?

serizba commented 1 year ago

Closing due to lack of activity.