serizba / cppflow

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

Cmake issue #229

Closed bmiftah closed 1 year ago

bmiftah commented 1 year ago

Thank you for sharing the tool . I was able to install TF C API and trying to install cppflow as per the procedure you put. However, when I issue cmake commmand in the same directory where I extract the TF C API , and of course inside build directory , I am having this error " The source directory /home/.... does not appear to contain CMakeLists.txt
I am unable to complete cppflow installation due to this catch. I follow the recommendation to tell cmake the directory where TF C API is installed , while doing that I got the this error :- No source or binary directror was provided . Both will be assumed to be the same as the current working directory , but note that this warning will become fatal error in the future CMake releases.

I try searching on the net , but most explain this case for opencv and somehow it can't relate to the issue I face. I am unable to move on and apprecite any help on this ... thank you

resetpointer commented 1 year ago

@bmiftah,

Does your project use Cmake; if not, why did you try to build your code with Cmake?

BTW, I use gnuMake and have configured cppflow to build like this:

PREFIX=${CURDIR}/sysroot
cppflow:
        [ -d cppflow ] || git clone https://www.github.com/serizba/cppflow.git
        mkdir -p cppflow/build
        cd cppflow/build && cmake -DBUILD_EXAMPLES=OFF -Dtensorflow_INCLUDE_DIRS=${CURDIR}/tensorflow -Dtensorflow_LIBRARIES=${PREFIX}/lib ..
        cd cppflow/build && make
        mkdir -p ${PREFIX}/include
        cd cppflow && cp -rf include/cppflow ${PREFIX}/include

notice that tensorflow is also in the build directory. This was just my preference, I did not think I followed any of the provided instructions

bmiftah commented 1 year ago

Thanl you for your reply. I was simply trying to run my tensorflow model in a C++ linux en't. For that, I was drawn to your repository -> https://serizba.github.io/cppflow/installation.html#install-cppflow , I just have xx.pd model ( saved model with Save_Model function of tensorflow) I install TF C API as :-

sudo tar -C /usr/local -xzf (downloaded file) sudo ldconfig and exported the path

export LIBRARY_PATH=$LIBRARY_PATH:/path/to/mydir/lib export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/mydir/lib

And followed this from the source shared :- As for your query - Does your project use Cmake; if not, why did you try to build your code with Cmake? umm ... I was just following the below tip **we provide a CMake file that will install the library in your system. To install it, you just have to:

mkdir build cd build cmake .. make -j make install** I did this inside the directory where I extract TF C API. I think may have gotten the concept and/or steps wrong , I should do this inside cppflow ... I will follow the above step you shared , Btw , I was having access issue when I try to clone cppflow.git .... pardon my approach !

ljn917 commented 1 year ago

Hi @bmiftah , as the error message said, you need to have a CMakeLists.txt file for your project if you want to use cmake. Otherwise, cppflow is just a header only library, and you just need to add the cppflow and TF include/lib to the compiler flags.

bmiftah commented 1 year ago

Hi @ljn917 Thank you for your tip. Yes I did that following the steps given above by @resetpointer ... Here is the command line error I bump into ..it could be silly mistake but I didn't catch it . image

ljn917 commented 1 year ago

It seems you need to tell the compiler the location of the include dir with -I flag

On Tue, Dec 20, 2022, 11:35 AM Miftah Bedru @.***> wrote:

Hi @ljn917 https://github.com/ljn917 Thank you for your tip. Yes I did that following the steps given above by @resetpointer https://github.com/resetpointer ... Here is the command line error I bump into ..it could be silly mistake but I didn't catch it . [image: image] https://user-images.githubusercontent.com/28997140/208577985-bef1220a-1bb9-484e-ac2c-3f13a033eff0.png

— Reply to this email directly, view it on GitHub https://github.com/serizba/cppflow/issues/229#issuecomment-1358795196, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALDTHTGIPIDR3NBX6YZSUDWOESQVANCNFSM6AAAAAATDFG5O4 . You are receiving this because you were mentioned.Message ID: @.***>

bmiftah commented 1 year ago

Hi again @ljn917 , Yes , I did that when running the sample main.cpp test code. Here is how I run it :

g++ -I include -o main.out main.cpp -ltensorflow

-I include , to tell the complier location the cppflow.h , I also gave complete path to dir include, nothing change then.

Below is the error and this time iostream.h is not found. I have the TF C API installed and path exported.

main.cpp:1:10: fatal error: iostream.h: No such file or directory 1 | #include | ^~~~ compilation terminated.

I don't have problem running for example the ff c code. gcc hello_tf.c = ltensorflow -o hello_tf ./hello_tf it give the output as expected.

That C++ Code is not running yet.

ljn917 commented 1 year ago

@bmiftah Try #include <iostream> (without the .h)

main.cpp:1:10: fatal error: iostream.h: No such file or directory 1 | #include | ^~~~ compilation terminated.

bmiftah commented 1 year ago

Hi , @ljn917 I remove the '.h' and put the location of cppflow in the compiling command as follows : g++ -I include -std=c++17 -o main.out main.cpp -ltensorflow and I was able to run the demo example.

Thanks , I will go on to the real adventure of running saved model !

bmiftah commented 1 year ago

Thank you @ljn917 @resetpointer for being supportive. This is resolved !