本文共 1984 字,大约阅读时间需要 6 分钟。
Table of Contents
TensorFlow provides a C API that can be used to build . The API is defined in and designed for simplicity and uniformity rather than convenience.
TensorFlow for C is supported on the following systems:
TensorFlow C library | URL |
---|---|
Linux | |
Linux CPU only | |
Linux GPU support | |
macOS | |
macOS CPU only | |
Windows | |
Windows CPU only | |
Windows GPU only |
Extract the downloaded archive, which contains the header files to include in your C program and the shared libraries to link against.
On Linux and macOS, you may want to extract to /usr/local/lib
:
sudo tar -C /usr/local -xzf (downloaded file)
On Linux/macOS, if you extract the TensorFlow C library to a system directory, such as /usr/local
, configure the linker with ldconfig
:
sudo ldconfig
If you extract the TensorFlow C library to a non-system directory, such as ~/mydir
, then configure the linker environmental variables:
export LIBRARY_PATH=$LIBRARY_PATH:~/mydir/libexport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/mydir/lib
With the TensorFlow C library installed, create an example program with the following source code (hello_tf.c
):
#include#include int main() { printf("Hello from TensorFlow C library version %s\n", TF_Version()); return 0;}
Compile the example program to create an executable, then run:
gcc hello_tf.c -ltensorflow -o hello_tf./hello_tf
The command outputs: Hello from TensorFlow C library version number
Success: The TensorFlow C library is configured.
If the program doesn't build, make sure that gcc
can access the TensorFlow C library. If extracted to /usr/local
, explicitly pass the library location to the compiler:
gcc -I/usr/local/include -L/usr/local/lib hello_tf.c -ltensorflow -o hello_tf
TensorFlow is open source. Read to build TensorFlow's C library from source code.
转载地址:http://eptaf.baihongyu.com/