{"id":15159382,"url":"https://github.com/octadero/tensorflow","last_synced_at":"2025-10-24T16:30:56.426Z","repository":{"id":63919476,"uuid":"107549510","full_name":"Octadero/TensorFlow","owner":"Octadero","description":"Swift high-level API for TensorFlow.","archived":false,"fork":false,"pushed_at":"2018-07-08T12:59:51.000Z","size":11051,"stargazers_count":49,"open_issues_count":0,"forks_count":2,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-01-31T03:01:34.942Z","etag":null,"topics":["ai","graph","machine-learning","math","swift","tensorboard","tensorflow","tensorflow-models"],"latest_commit_sha":null,"homepage":"https://octadero.com/","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Octadero.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-19T13:24:22.000Z","updated_at":"2022-05-31T07:55:12.000Z","dependencies_parsed_at":"2023-01-14T14:00:24.918Z","dependency_job_id":null,"html_url":"https://github.com/Octadero/TensorFlow","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Octadero%2FTensorFlow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Octadero%2FTensorFlow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Octadero%2FTensorFlow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Octadero%2FTensorFlow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Octadero","download_url":"https://codeload.github.com/Octadero/TensorFlow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237999547,"owners_count":19399903,"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":["ai","graph","machine-learning","math","swift","tensorboard","tensorflow","tensorflow-models"],"created_at":"2024-09-26T21:20:30.300Z","updated_at":"2025-10-24T16:30:46.417Z","avatar_url":"https://github.com/Octadero.png","language":"Swift","readme":"# TensorFlow Swift high-level API. [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=TensorFlowKit%20is%20Swift%20API%20for%20tensorflow,%20easiest%20way%20to%20do%20your%20app%20more%20intelligent\u0026url=https://github.com/Octadero/TensorFlow\u0026via=octadero\u0026hashtags=swift,ml,tensorflow,NeuralNetworks,AI)\n\n\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://developer.apple.com/swift/\" target=\"_blank\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/Swift-4.0-orange.svg?style=flat\" alt=\"Swift 4.0\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://developer.apple.com/swift/\" target=\"_blank\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/Platforms-%20Linux%20%26%20OS%20X%20-brightgreen.svg?style=flat\" alt=\"Platforms Linux \u0026 OS X\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://github.com/Octadero/TensorFlow/blob/master/LICENSE\" target=\"_blank\"\u003e\n\u003cimg src=\"https://img.shields.io/aur/license/yaourt.svg?style=flat\" alt=\"GPL\"\u003e\n\u003c/a\u003e\n\u003ca href=\"http://twitter.com/Octadero\" target=\"_blank\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/Twitter-@Octadero-0084b4.svg?style=flat\" alt=\"Octadero Twitter\"\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\n## Structure of API\n![architecture](https://raw.githubusercontent.com/Octadero/TensorFlow/master/Documentation/resources/TensorFlowProject@2x.png)\n\nAPI based on [TensorFlow](https://www.tensorflow.org) library.\n* CTensorFlow is C API [system module](https://github.com/apple/swift-package-manager/blob/master/Documentation/Usage.md#require-system-libraries);\n* CAPI - Swift writen low-level API to C library;\n* Proto - Swift auto - generated classes for TensorFlow structures and models;\n* OpPruducer - Swift writen command line tool to produce new [TensorFlow Operations](https://www.tensorflow.org/extend/architecture)\n* TensorFlowKit - Swift writen high-level API;\n\n## Using library.\n\nFirst of all you should install tensorflow_c library. You can do that using brew on mac os.\nVersion 1.4 currantly  available for [mac os](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-1.4.1.tar.gz) and [linux](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.4.1.tar.gz) on Google cloud, so you can use it:\nAlso, you can install it from sources, [how to install TensorFlow from sources you can find here](https://www.octadero.com/2017/08/27/tensorflow-c-environment/).\n\n### Tutorials\n* There is [review of technology stack](https://www.octadero.com/2017/11/14/swift-and-tensorflow/)\n* [Short tutorial](https://www.octadero.com/2017/11/16/mnist-by-tensorflowkit/), please review them.\n\n### Xcode\n*Make shure that you read README of submodule CTensorFlow*\n\nTo generate xcode project file you can call:\nIf you install TensorFlow library (1.4.1 version) as brew package:\n```\nswift package -Xlinker -rpath -Xlinker /usr/local/Cellar/libtensorflow/1.4.1/lib/ generate-xcodeproj\n```\n```\nswift package -Xlinker -rpath -Xlinker /server/repository/tensorflow/bazel-bin/tensorflow generate-xcodeproj\n```\n_Where */server/repository/tensorflow/bazel-bin/tensorflow* path to your TensorFlow C library */user/local/lib, usualy.*_\n\nAlso you can use config:\n```\nswift package generate-xcodeproj --xcconfig-overrides TensorFlow.xcconfig\n```\n\n* At `TensorFlow.xcconfig` file set `TENSORFLOW_PATH` property with correct path.\n* It is important to set 'TensorFlow.xcconfig' name the same with projectfile.\n* *There is [issus SR-6073](https://bugs.swift.org/browse/SR-6073)* with LD_RUNPATH_SEARCH_PATHS property. So, currently you have to set `$(inherited)` value manualy at your build variable.\n\nBuild and set RPATH setting:\n\n```\n#MacOS\nswift build -Xlinker -rpath -Xlinker /usr/local/Cellar/libtensorflow/1.4.1/lib/\nswift test -Xlinker -rpath -Xlinker /usr/local/Cellar/libtensorflow/1.4.1/lib/\n```\n\n```\n#Linux\nswift build -Xlinker -rpath -Xlinker /server/repository/tensorflow/bazel-bin/tensorflow\nswift test -Xlinker -rpath -Xlinker /server/repository/tensorflow/bazel-bin/tensorflow\n```\n\n### Features\nSwift API provides accae to all available C features in TensorFlow library.\n\n* Create / read grapht;\n* Save statistic on file system;\n* Cunstruct and run session;\n* Include available operations;\n* Store and restore checkpoints by SavedModel class;\n\n![graph](https://raw.githubusercontent.com/Octadero/TensorFlow/master/Documentation/resources/grapht@2x.png)\n\n## Summary\n![Summary](https://raw.githubusercontent.com/Octadero/TensorFlow/master/Documentation/resources/tensorboard-1.gif)\n\nStarting from version 0.0.5 you have posibility to track any metrics using TensorFlowKit.\nThat is easy way to visualize your model in Swift application.\n### You can visualize weights and biases:\n![summary-distribution](https://raw.githubusercontent.com/Octadero/TensorFlow/master/Documentation/resources/summary-distribution@2x.png)\n\n### Draw your graph:\n![summary-graph](https://raw.githubusercontent.com/Octadero/TensorFlow/master/Documentation/resources/summary-graph@2x.png)\n\n### Track changes in 3D:\n![summary-histogram](https://raw.githubusercontent.com/Octadero/TensorFlow/master/Documentation/resources/summary-histogram@2x.png)\n\n### Extract components as png images:\n![summary-image](https://raw.githubusercontent.com/Octadero/TensorFlow/master/Documentation/resources/summary-image@2x.png)\n\n### Watch on dynamics of changes:\n![summary-scalar](https://raw.githubusercontent.com/Octadero/TensorFlow/master/Documentation/resources/summary-scalar@2x.png)\n\n### Troubleshooting\n* In case app can't load dynamic library on macOS:\n\n```\notool -L libtensorflow_cc.so\nsudo install_name_tool -id /%repository%/tensorflow/bazel-out/darwin_x86_64-opt/bin/tensorflow/libtensorflow_cc.so libtensorflow_cc.so\nsudo install_name_tool -id /%repository%/tensorflow/bazel-out/darwin_x86_64-opt/bin/tensorflow/libtensorflow_framework.so libtensorflow_framework.so\nsudo install_name_tool -id /%repository%/tensorflow/bazel-out/darwin_x86_64-opt/bin/tensorflow/libtensorflow.so libtensorflow.so\n```\n\n* In case if app can't load dynamic library on linux or mac os with error:\n```\nerror while loading shared libraries: *libtensorflow_cc.so*: cannot open shared object file: No such file or directory\n```\nAdd your library path linux:\n```\nexport LD_LIBRARY_PATH=/server/repository/tensorflow/bazel-bin/tensorflow:/usr/local/lib/:$LD_LIBRARY_PATH\n```\nmac os:\n```\nexport DYLD_LIBRARY_PATH=/server/repository/tensorflow/bazel-bin/tensorflow/:$DYLD_LIBRARY_PATH\n```\n\n---\nC++ old related issues.\n\n* At build phase error:\n```\nwarning: error while trying to use pkgConfig flags for CProtobuf: nonWhitelistedFlags(\"Non whitelisted flags found: [\\\"-D_THREAD_SAFE\\\", \\\"-D_THREAD_SAFE\\\"] in pc file protobuf\")\n```\nRemove `-D_THREAD_SAFE` keys from file /usr/local/lib/pkgconfig/protobuf.pc\n\nError at build phase:\n```\n#include \"tensorflow/core/framework/graph.pb.h\"                                                                                                                                         ^                                                                                                                                                                     1 error generated.                                                                                                                                                             error: terminated(1): /usr/bin/swift-build-tool -f /server/repository/TensorFlow/.build/debug.yaml main\n```\n\nDownload dependencies for C++ library at tensorflow repository.\n```\ntensorflow/contrib/makefile/download_dependencies.sh\n```\n\n## Developing and extending API\n\n### Create new proto files\n\n* Install swift protobuf generator from [Protobuf Swift library](https://github.com/apple/swift-protobuf) \n\n* Execute commands\n\n```\n// Create temperory folder\nmkdir /tmp/swift\ncd %path-to-tensorflow-reposytory%\n\n// Find all proto files and generate swift classes.\nfind. -name '*.proto' -print -exec protoc --swift_opt=Visibility=Public --swift_out=/tmp/swift {} \\;\n\n// All files will be removed after restart.\nopen /tmp/swift\n```\n\n### Debuging\nSets the threshold for what messages will be logged.\nAdd `TF_CPP_MIN_LOG_LEVEL=0` and `TF_CPP_MIN_VLOG_LEVEL=0`\n\n\n### List of operations\nThere are a few ways to get a list of the OpDefs for the registered ops:\n\n```\nTF_GetAllOpList in the C API retrieves all registered OpDef protocol messages. This can be used to write the generator in the client language. This requires that the client language have protocol buffer support in order to interpret the OpDef messages.\n\nThe C++ function OpRegistry::Global()-\u003eGetRegisteredOps() returns the same list of all registered OpDefs (defined in [tensorflow/core/framework/op.h]). This can be used to write the generator in C++ (particularly useful for languages that do not have protocol buffer support).\n\nThe ASCII-serialized version of that list is periodically checked in to [tensorflow/core/ops/ops.pbtxt] by an automated process.\n\n```\nOpProducer using C API to extract and prepare all available operation as Swift source code.\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foctadero%2Ftensorflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foctadero%2Ftensorflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foctadero%2Ftensorflow/lists"}