First of all you should install tensorflow_c library. You can do that using brew on mac os.
Version 1.4 currantly available for mac os and linux on Google cloud, so you can use it:
Also, you can install it from sources, how to install TensorFlow from sources you can find here.
Make shure that you read README of submodule CTensorFlow
To generate xcode project file you can call:
If you install TensorFlow library (1.4.1 version) as brew package:
swift package -Xlinker -rpath -Xlinker /usr/local/Cellar/libtensorflow/1.4.1/lib/ generate-xcodeproj
swift package -Xlinker -rpath -Xlinker /server/repository/tensorflow/bazel-bin/tensorflow generate-xcodeproj
Where /server/repository/tensorflow/bazel-bin/tensorflow path to your TensorFlow C library /user/local/lib, usualy.
Also you can use config:
swift package generate-xcodeproj --xcconfig-overrides TensorFlow.xcconfig
At TensorFlow.xcconfig file set TENSORFLOW_PATH property with correct path.
It is important to set ‘TensorFlow.xcconfig’ name the same with projectfile.
There is issus SR-6073 with LD_RUNPATH_SEARCH_PATHS property. So, currently you have to set $(inherited) value manualy at your build variable.
Build and set RPATH setting:
#MacOS
swift build -Xlinker -rpath -Xlinker /usr/local/Cellar/libtensorflow/1.4.1/lib/
swift test -Xlinker -rpath -Xlinker /usr/local/Cellar/libtensorflow/1.4.1/lib/
#Linux
swift build -Xlinker -rpath -Xlinker /server/repository/tensorflow/bazel-bin/tensorflow
swift test -Xlinker -rpath -Xlinker /server/repository/tensorflow/bazel-bin/tensorflow
Features
Swift API provides accae to all available C features in TensorFlow library.
Create / read grapht;
Save statistic on file system;
Cunstruct and run session;
Include available operations;
Store and restore checkpoints by SavedModel class;
Summary
Starting from version 0.0.5 you have posibility to track any metrics using TensorFlowKit.
That is easy way to visualize your model in Swift application.
warning: error while trying to use pkgConfig flags for CProtobuf: nonWhitelistedFlags("Non whitelisted flags found: [\"-D_THREAD_SAFE\", \"-D_THREAD_SAFE\"] in pc file protobuf")
Remove -D_THREAD_SAFE keys from file /usr/local/lib/pkgconfig/protobuf.pc
// Create temperory folder
mkdir /tmp/swift
cd %path-to-tensorflow-reposytory%
// Find all proto files and generate swift classes.
find. -name '*.proto' -print -exec protoc --swift_opt=Visibility=Public --swift_out=/tmp/swift {} \;
// All files will be removed after restart.
open /tmp/swift
Debuging
Sets the threshold for what messages will be logged.
Add TF_CPP_MIN_LOG_LEVEL=0 and TF_CPP_MIN_VLOG_LEVEL=0
List of operations
There are a few ways to get a list of the OpDefs for the registered ops:
TF_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.
The C++ function OpRegistry::Global()->GetRegisteredOps() 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).
The ASCII-serialized version of that list is periodically checked in to [tensorflow/core/ops/ops.pbtxt] by an automated process.
OpProducer using C API to extract and prepare all available operation as Swift source code.
TensorFlow Swift high-level API.
Structure of API
API based on TensorFlow library.
Using library.
First of all you should install tensorflow_c library. You can do that using brew on mac os. Version 1.4 currantly available for mac os and linux on Google cloud, so you can use it: Also, you can install it from sources, how to install TensorFlow from sources you can find here.
Tutorials
Xcode
Make shure that you read README of submodule CTensorFlow
To generate xcode project file you can call: If you install TensorFlow library (1.4.1 version) as brew package:
Where /server/repository/tensorflow/bazel-bin/tensorflow path to your TensorFlow C library /user/local/lib, usualy.
Also you can use config:
TensorFlow.xcconfig
file setTENSORFLOW_PATH
property with correct path.$(inherited)
value manualy at your build variable.Build and set RPATH setting:
Features
Swift API provides accae to all available C features in TensorFlow library.
Summary
Starting from version 0.0.5 you have posibility to track any metrics using TensorFlowKit. That is easy way to visualize your model in Swift application.
You can visualize weights and biases:
Draw your graph:
Track changes in 3D:
Extract components as png images:
Watch on dynamics of changes:
Troubleshooting
C++ old related issues.
-D_THREAD_SAFE
keys from file /usr/local/lib/pkgconfig/protobuf.pcError at build phase:
Download dependencies for C++ library at tensorflow repository.
Developing and extending API
Create new proto files
Install swift protobuf generator from Protobuf Swift library
Execute commands
Debuging
Sets the threshold for what messages will be logged. Add
TF_CPP_MIN_LOG_LEVEL=0
andTF_CPP_MIN_VLOG_LEVEL=0
List of operations
There are a few ways to get a list of the OpDefs for the registered ops:
OpProducer using C API to extract and prepare all available operation as Swift source code.