Neargye/hello_tf_c_api
Neargye/hello_tf_c_api has 473 GitHub stars and 133 forks. Star changes are not measured yet. Last checked 2026-11-16 18:31 UTC. Last push 2026-09-20.
Crecimiento de estrellas medido
- in 24h
- Actualización retrasada
- in 7 days
- Actualización retrasada
- in 15 days
- Actualización retrasada
- in 1 month
- Actualización retrasada
Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.
Acerca de
Neural Network TensorFlow C API
Aprendizaje automáticoREADME.md
OriginalTensorFlow C API Examples

TensorFlow C API examples for Windows, Linux, and macOS, with a small C++ helper library.
Requirements
- CMake 3.20 or newer and a C++17 compiler.
- Python with pip; CI uses Python 3.12.
- A 64-bit platform supported by the TensorFlow wheel.
Build and test
git clone --depth 1 https://github.com/Neargye/hello_tf_c_api
cd hello_tf_c_api
Windows (Visual Studio)
cmake -S . -B build -A x64
cmake --build build --config Release
ctest --test-dir build --output-on-failure -C Release
Linux and macOS
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
ctest --test-dir build --output-on-failure
CMake downloads the TensorFlow 2.21.0 wheel into build/_deps/tensorflow/python and links its native libraries. On Windows, it also copies the runtime DLLs. You do not need to install TensorFlow into your Python environment to build the C++ examples.
The repository includes models/graph.pb. Run examples from the build directory so they can find its copy: ./Release/repeated_inference.exe on Windows or ./repeated_inference on Linux/macOS.
Build options
Pass these options to cmake -S . -B build:
-DHELLO_TF_BUILD_EXAMPLES=OFF: skip example executables.-DBUILD_TESTING=OFF: skip tests.-DTENSORFLOW_ROOT=/path/to/tensorflow -DHELLO_TF_FETCH_TENSORFLOW=OFF: use an existing wheel extraction. Headers must be under<root>/python/tensorflow/include, with native libraries under<root>/python/tensorflowor itspythonsubdirectory. CMake does not overwrite an external root.
OpenCV is optional. CMake builds and tests the OpenCV example when it finds the library.
Examples
- TensorFlow version, load a graph.
- Create a tensor, allocate a tensor, string tensors.
- Run a session, run a target operation.
- Helper API, batch inference, repeated inference.
- Image tensors, image files with OpenCV.
- Tensor information, graph information.
Helper API
See tf_utils.hpp for declarations. Within this CMake project, link the helpers with:
target_link_libraries(your_target PRIVATE hello_tf_utils)
For raw C API examples, use the project's target_link_tensorflow(your_target) function. There is no installable CMake package.
CreateTensor(dims, values)infers the TensorFlow type from the vector element type. UseCreateStringTensorfor strings.- Reader overloads taking a result reference return
TF_Codeand leave the result unchanged on error. They distinguish errors from valid empty values. - The checked
GetTensorShapewritesnulloptfor unknown rank, an empty vector for a scalar, and-1for unknown dimensions. RunSessionrequires output slots initialized tonullptr. Delete returned tensors and reset the slots before reuse.
More
- Prepare models: GraphDef, operation names, and checkpoints.
- Runtime and performance: resource reuse and measurement.
- Create a Windows import library: only for manual linking.