{"id":19386221,"url":"https://github.com/davidstutz/tensorflow-cpp-op-example","last_synced_at":"2025-04-23T22:32:26.921Z","repository":{"id":53518885,"uuid":"80931693","full_name":"davidstutz/tensorflow-cpp-op-example","owner":"davidstutz","description":"Simple example of implementing a new Tensorflow operation and its gradient in C++.","archived":false,"fork":false,"pushed_at":"2019-03-28T15:06:13.000Z","size":9,"stargazers_count":56,"open_issues_count":1,"forks_count":23,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-02T21:51:19.187Z","etag":null,"topics":["tensorflow","tensorflow-operation"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidstutz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-04T16:25:07.000Z","updated_at":"2023-11-10T02:55:01.000Z","dependencies_parsed_at":"2022-09-13T05:50:21.588Z","dependency_job_id":null,"html_url":"https://github.com/davidstutz/tensorflow-cpp-op-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidstutz%2Ftensorflow-cpp-op-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidstutz%2Ftensorflow-cpp-op-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidstutz%2Ftensorflow-cpp-op-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidstutz%2Ftensorflow-cpp-op-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidstutz","download_url":"https://codeload.github.com/davidstutz/tensorflow-cpp-op-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250527271,"owners_count":21445341,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["tensorflow","tensorflow-operation"],"created_at":"2024-11-10T10:04:41.940Z","updated_at":"2025-04-23T22:32:21.892Z","avatar_url":"https://github.com/davidstutz.png","language":"Python","readme":"# Example of Tensorflow Operation in C++\n\nThis repository contains an example of a simple Tensorflow operation and its gradient both implemented in C++, as described in [this article](http://davidstutz.de/implementing-tensorflow-operations-in-c-including-gradients/).\n\n## Building\n\nThe operation is built using [CMake](https://cmake.org/) and requires an appropriate version of Tensorflow to be installed. In order to get the necessary include directories containing the Tensorflow header files, the following trick is used (also see the [Tensorflow documentation](https://www.tensorflow.org/how_tos/adding_an_op/)):\n\n    import tensorflow\n    print(tensorflow.sysconfig.get_include())\n\nIn the `CMakeLists.txt` this is used as follows:\n\n    execute_process(COMMAND python3 -c \"import tensorflow; print(tensorflow.sysconfig.get_include())\" OUTPUT_VARIABLE Tensorflow_INCLUDE_DIRS)\n\nThe remaining contents are pretty standard. Building is now done using:\n\n    $ mkdir build\n    $ cd build\n    $ cmake ..\n    $ make\n    Scanning dependencies of target inner_product\n    [ 50%] Building CXX object CMakeFiles/inner_product.dir/inner_product.cc.o\n    Linking CXX shared library libinner_product.so\n    [ 50%] Built target inner_product\n    Scanning dependencies of target inner_product_grad\n    [100%] Building CXX object CMakeFiles/inner_product_grad.dir/inner_product_grad.cc.o\n    Linking CXX shared library libinner_product_grad.so\n    [100%] Built target inner_product_grad\n\n`libinner_product.so` and `libinner_product_grad.so` can be found in `build` and need to be included in order to load the module in Python:\n\n    import tensorflow as tf\n    inner_product_module = tf.load_op_library('build/libinner_product.so')\n\nSee `inner_product_tests.py` for usage examples.\n\n## License\n\nCopyright (c) 2016 David Stutz\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidstutz%2Ftensorflow-cpp-op-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidstutz%2Ftensorflow-cpp-op-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidstutz%2Ftensorflow-cpp-op-example/lists"}