GithubHelp home page GithubHelp logo

How to do this on macOS about tensorflow_cc HOT 8 CLOSED

floopcz avatar floopcz commented on September 28, 2024
How to do this on macOS

from tensorflow_cc.

Comments (8)

FloopCZ avatar FloopCZ commented on September 28, 2024 4

tensorflow_cc.so is not the only thing you need. There are plenty of headers and directories you have to include when compiling your code that uses the TF C++ API. That is why this project uses CMake - to do this automatically for you.

If you really want to use tensorflow_cc.so without the help of this project, you have two options.

  1. Build your code using Bazel as described in the official guide. Your code has to be placed inside the tensorflow repository hierarchy.

  2. Build your code manually. See this StackOverflow answer that lists the directories you have to include (using -I flag in your compiler). Also don't forget to link -lpthread and -ldl.

However, I would still suggest to use this project instead, since it becomes a lot easier. Since you have built tensorflow_cc.so once already, your system must have all the dependencies installed. Therefore, you should be able to follow the instructions beginning from step 2). Just install CMake and try to follow the commands used for building the shared library. You don't have to be familiar with CMake, copy paste and uncommenting a few lines should be sufficient.

One more thing, if you want GPU support on macOS, you should change this line to GIT_TAG v1.1.0. I cannot guarantee it will work then, however.

from tensorflow_cc.

gilbertfrancois avatar gilbertfrancois commented on September 28, 2024 2

I've compiled the tensorflow_cc.so libs and gathered the necessary headers for developing your own C++ programs with tensorflow on macOS. I made a little blog post to describe the steps. However, it is not really a clean way of doing it. Suggestions to improve it are most welcome.
http://www.blitzblit.com/2017/06/11/creating-tensorflow-c-headers-and-libraries/

from tensorflow_cc.

FloopCZ avatar FloopCZ commented on September 28, 2024 1

Hi, unfortunately, I do not own an Apple machine nor I have a CI set-up for MacOS. Therefore, it will be a little bit hard for me to help you (pull requests welcome).

Have you tried to follow the instructions for Linux shared library? Where has it failed and what error has it produced? Have you installed Bazel and brew install coreutils? Have you tried to edit build_tensorflow.sh using MacOS compilation guide?

You don't have to bother with CUDA settings, since Google dropped the GPU support for MacOS in TF 1.2.0 anyway.

from tensorflow_cc.

PharrellWANG avatar PharrellWANG commented on September 28, 2024
  1. I am using TF1.1.0, and I got a GPU configured with my mac.
  2. I have successfully built TF from source and I have built the libtensorflow_cc.so successfully on my Mac.
  3. I am able to run python training programs using GPU on my Mac.

However,

  1. I am not familiar with CMAKE, so it is hard for me to create a similar project for Mac.
  2. I am not sure how to use that libtensorflow_cc.so lib on Mac. I have copied it to /usr/local/lib directory but seems it does not work. [Do you have any suggestion about how to use a .so lib on Mac? I have googled but cannot find a good helpful guide.]

from tensorflow_cc.

PharrellWANG avatar PharrellWANG commented on September 28, 2024

@FloopCZ
Great, thank you so much. I have followed your instructions and your example is actually working now.
I would like to try for my own project.

And I have two question here:

  1. You mentioned in your last reply for me that "You don't have to be familiar with CMake".
    But to build my own project, I still need to configure a CMakelist.txt by myself, is it? There's no way to use the TF C++ API without CMake under the circumstance that I used your project here, is it?

  2. And I haven't verified that whether my previous tensorflow installation of python3 still working or not. Do you have a quick answer that can tell me it is not affected by using your project? Thank you.
    (I think probably not affected. since your are not building //tensorflow/tools/pip_package:build_pip_package)

from tensorflow_cc.

PharrellWANG avatar PharrellWANG commented on September 28, 2024

@gilbertfrancois
I have tried your suggestions. But since I am not familiar with CMake, I stopped at the last step in your post. Thank you for your info. I think I shall spend some time learning CMake.

from tensorflow_cc.

FloopCZ avatar FloopCZ commented on September 28, 2024

Glad it worked!

And yes, you are right. To build your own project, you have to configure CMakeLists.txt by yourself, or with the help of your IDE. If you don't want to use CMake at all (which I would not recommend), you can do the following. In the very last step of the README.md that describes how to build the example:

  1. Build and run your program
mkdir build && cd build
cmake .. && make
./example 

replace the second line with cmake .. && VERBOSE=1 make. The make command will then output the exact command it uses to build the example. You can use the compiler flags in your own project.

This comment has been edited to improve clarity.

from tensorflow_cc.

FloopCZ avatar FloopCZ commented on September 28, 2024

You mentioned in your last reply for me that "You don't have to be familiar with CMake".
But to build my own project, I still need to configure a CMakelist.txt by myself, is it? There's no way to use the TF C++ API without CMake under the circumstance that I used your project here, is it?

See my previous reply that describes how to extract the raw compiler command.

And I haven't verified that whether my previous tensorflow installation of python3 still working or not. Do you have a quick answer that can tell me it is not affected by using your project? Thank you.
(I think probably not affected. since your are not building //tensorflow/tools/pip_package:build_pip_package)

Exactly as you say, your original python TF is not affected.

from tensorflow_cc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.