Comments (62)
Providing APIs for every 'very popular' lang would probably bloat the main project quite quickly.
from tensorflow.
I'll take on this.
from tensorflow.
1.5 years ago, I said: #19 (comment)
And now I’m here to close this issue :)
Welcome to Swift for TensorFlow.
Swift for TensorFlow video | TensorFlow Dev Summit 2018
from tensorflow.
Given that TensorFlow is designed to also run on mobile and that Apple is recommending Swift as a primary language for iOS development, I think having a Swift API for TensorFlow would be a good idea.
I don't think adding support for the most widely-used languages such as Java, C#, and Swift would be a bad idea. The gRPC project already supports 10 languages, including Java, C#, and JavaScript (via Node.js).
@jamesliu96 Feel free to open an issue for adding a Go API.
from tensorflow.
I understand the sentiment, but Swift, C# and Java are not "every" language, and this is not "every project" either. This is open source and Github so there might be enough hands to man the maintanance of ports to the most popular languages for such an important piece of software. Python is quite popular in academia but a little less popular with the bulk of private sector developers.
from tensorflow.
A Swift frontend, especially for simply running graphs for inference on mobile would be great. I don't know of current plans to provide one, so feel free to dive in. Since our exact plans on accepting external contributions are still in flux, it would be a good idea to check in with the discuss mailing list with a draft of the code ahead of time to figure out where it should live exactly.
from tensorflow.
I couldn't agree more with janerivi and davidzchen. Swift has many advanced features that make it one, if not the best choice for full API support for TensorFlow.
This is especially true since Swift is now open source. This language is very pleasant to work with and has all of the great features of top expressive languages like Haskell; Generics, Closures, etc.
I would not agree that C# or Java are good candidates in terms of speed. Glyn Williams is a trusted and respected contributor and writer in many areas and had this to say at:
https://www.quora.com/In-terms-of-performance-speed-is-Swift-faster-than-Java
Glyn Williams:
Swift is significantly faster than Java.
It compiles to native code. And a number of the language features enable an optimizing compiler to produce very fast code indeed.
Vivian Keating:
Swift will typically run faster than Java, since it compiles into native code via the LLVM compiler. Most recent metrics find it comparable to C++ in production.
This is the tip of the iceberg in terms of comparisons. Apple took great care in designing this modern language and how it compiles to native code, and now it's Open Source.
from tensorflow.
@johndpope Honestly none of those Swift ML libraries are nearly ready, cross-platform, nor written in Swift 3.0+.
from tensorflow.
so good news & bad news
To anyone - coming to pick up a 'swift' port of tensorflow - as of this writing -
there's a limit to how far the c api will take this codebase.
https://www.tensorflow.org/versions/r0.12/how_tos/language_bindings/
it seems there's no plans to have any language other than python do the actual training.
there appears to be a train wreck of github repos attempting to port tensorflow over.
One that was quite a stand out -
https://github.com/kmalakoff/tensorflow-node
Good News -> Easily craft fast Neural Networks on iOS! Use TensorFlow models.
Metal under the hood.
https://github.com/xmartlabs/Bender
from tensorflow.
@siilime many significant limitations. I'm working on other approaches. Stay tuned ;)
from tensorflow.
fyi - thanks to @RockfordWei - we have https://github.com/PerfectlySoft/Perfect-TensorFlow 🎉
from tensorflow.
@johndpope You are welcome! I am doing the documentation now and community examples based on Perfect-TensorFlow are absolutely
Please join us Slack http://perfect.ly to get instant feedback online (I am always there), we support both English and Chinese, as the Perfect-TensorFlow and all Perfect frameworks.
We are planning to publish all documents to our website perfect.org,
And building more examples on Perfect Team's example repo github/PerfectExamples.
Also, Perfect-TensorFlow will support the incoming Swift 4.0 soon (honestly, only one or two source code issues for the new features listed in 4.0, majorly because of the protocol buffer made by Apple/Swift).
from tensorflow.
@siilime fyi - Google released an official swift3 grpc library last week.
https://github.com/grpc/grpc-swift
There's still some heavy lifting to do to get it all working(eg generate swift 3 services classes). You may want to revisit your implementation and yield to official library. Surely less painful in the long run. I'm aware of some other grpc libraries and wrapping the c classes into swift module.(just search on GitHub (swift + grpc) there's one by Huawei. My interest is to get it working server side. If anyone wants to help / check the issues grpc-swift for docker issues ticket.
from tensorflow.
Looks like @rxwei has made some progress here around providing some basic test cases around a swift wrapper for the tensorflow c api.
https://github.com/rxwei/tensorflow/tree/master/tensorflow/swift
https://github.com/rxwei/CTensorFlow
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/c/c_api.h
from tensorflow.
should align to golang library.
To use swift via GRPC - you can use this https://github.com/johndpope/swift-grpc-tensorflow
depends on grpc / (has a minor compile issue out of the box with missing boring ssl - see issues log for instructions.) I tagged a simplified version 0.0.1 which just has the protobuffer files / no grpc.
hit a bit of a tech spike with Operations. > 700kb
https://github.com/johndpope/tensorflow/blob/swift/tensorflow/swift/Sources/GoOpWrapper.swift
from tensorflow.
https://github.com/PerfectlySoft/Perfect-TensorFlow has upgraded to 1.3.0!!!
New Features:
- Fixing QInt16 size issue
- Gradient has new namespaces (
graph.addGradients()
has been activated since 1.2.1) - Adding Devices to Session for distributive computation.
- Adding Matrix Tensor with auto shape/auto flat functionality.
- Fixing memory leak between sessions.
- Fully supports Swift 4.0
NOTE using install.sh
is a good start.
from tensorflow.
No one asked me to do that. So no, there is no summary
object in Perfect TensorFlow now, but you can request one then I can put it on the list, or you can write one to pull a request. Currently, I am working for the incoming "Function" of 1.4.0, so it can be a part of the next subversion.
from tensorflow.
Just released new version of swift API for TensorFlow:
- Added SaveModel class, now you can store and restore your state;
- Added Summary class to visualize your graph and training progress;
You are welcome to try!
from tensorflow.
Hello! @alexnivanov
It is not common way, but you could try:
- Install libtensorflow (from sources, but for iOS platform).
- clone TensorFlowKit repository
- create Xcode project file:
swift package generate-xcodeproj
- Build project in the Xcode.
- At the end you will have list of Frameworks, you could use at your project just add them to project.
But I think you will have fake (empty) CTensorFlow Framework, just create empty framework to avoid link errors.
If I will have enough time, I will do example.
from tensorflow.
I have this swift docker file with parsley mcparsefsce / tensorflow + separate swift 3 dev container. - I will plugin swift grpc once google resolve an issue with their just released grpc library
https://github.com/johndpope/DockerParseyMcParsefaceAPI
I could use some help to get it all working.
Some @nubbel stubbed out proto files in swift here
https://github.com/nubbel/swift-tensorflow/tree/master/types
Should be able to leverage this environment to get above working.
from tensorflow.
I have been working on a painful private project for a while using Swift. I'll be migrating the project API library to Swift 3 soon and opening it up under the same licensing as TensorFlow (Apache 2.0). It was reasonably complete before Swift 3 and I plan to have the Swift 3 version complete before the end of 2016, sans mistakes from original, and including lessons learned.
from tensorflow.
@johndpope Good tip. Thanks. My focus was on the server side originally, and it's where the majority of my work has been so I'll be taking a look at that.
from tensorflow.
I've done a lot of review work over my original code base and the official Swift gRPC code base in the past few days, and although there's advantages to using the gRPC in some cases, there's still a lot missing, (specifically an easy option to train TensorFlow directly from Swift), and those gaps are the areas I'll be focusing on, whilst aiming to develop a complete solution in Swift.
Good start with @rxwei contribution so will aim to assist in that, whilst migrating existing code base.
from tensorflow.
Currently the C API is under-documented and offers only a few core components, Graph, Tensor, and Session. I start to wonder if wrapping all the C API is worthwhile.
from tensorflow.
@rxwei What feasible alternative approaches are there?
from tensorflow.
for reference - found this - https://github.com/somaticio/tensorflow.rb
a ruby wrapper around tensorflow. (there maybe more)
It looks like they wrapped the c api in another c wrapper. Not sure if this helps.
https://github.com/somaticio/tensorflow.rb/tree/master/ext/sciruby/tensorflow_c/files
Another shot is to use grpc to interact with tensor.
but the services layer needs fleshing out which will be simpler once google can spit out service class definitions (think afnetworking for protobuf) for grpc
the python API has hundreds of granular parameters.
https://www.tensorflow.org/versions/r0.10/api_docs/python/index.html
compared to c++ API / c api.
https://www.tensorflow.org/versions/r0.10/api_docs/cc/index.html
Env
tensorflow::Env
tensorflow::RandomAccessFile
tensorflow::WritableFile
tensorflow::EnvWrapper
Session
tensorflow::Session
tensorflow::SessionOptions
Status
tensorflow::Status
tensorflow::Status::State
Tensor
tensorflow::Tensor
tensorflow::TensorShape
tensorflow::TensorShapeDim
tensorflow::TensorShapeUtils
tensorflow::PartialTensorShape
tensorflow::PartialTensorShapeUtils
Thread
tensorflow::Thread
tensorflow::ThreadOptions
If you're looking to machine learning in swift today (nov-2016) it'd pay to shop around for other libraries. https://github.com/search?utf8=%E2%9C%93&q=swift+ml&type=Repositories&ref=searchresults
One day - another (somewhat unfeasible) approach could be to rewrite the python library in swift.
from tensorflow.
@johndpope service approach makes sense for now, as a wrapper.
from tensorflow.
related grpc/grpc-swift#2
also there is this swift library for those that want to get their feet? / toes wet. https://github.com/qoncept/TensorSwift
from tensorflow.
@johndpope That one is dependent on Darwin platforms and Apple's Accelerate framework. Not suitable for general use.
from tensorflow.
@rxwei Are there not significant limitations by using the service approach?
from tensorflow.
fyi - I cherry picked @nubbel proto definitions from https://github.com/nubbel/swift-tensorflow
and have two docker containers
- tensorflow / parsey mcparseface api
- swift3 dev container
these should fire up by simply typing
make start (warning this could take > 90 minutes to compile for this image)
https://github.com/johndpope/DockerParseyMcParsefaceAPI/
(there is a node client that will hit the grpc service of parsey / but that's not the tensor flow grpc)
It might be worthwhile jumping on to this slack tensorflow hangout
https://tensor-flow-talk-invite.herokuapp.com/invite
found this from this link
https://github.com/node-tensorflow/node-tensorflow
I'm currently blocked on progressing until I/we can resolve this
grpc/grpc-swift#6
Looking through the protobufs here -
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/protobuf
services route may not be so restrictive.
from tensorflow.
Has anyone had any success with wrapping the objc ios camera example in a swift project?
from tensorflow.
@MattSich presumably you saw https://github.com/acerbetti/TensorFlowPod? maybe open a ticket on that repo if it's broken? I didn't try it.
I cobbled this script together to spit out every swift files for every proto file in tensorflow for grpc communication - but without intermediary services layer - this isn't going anywhere. https://gist.github.com/johndpope/5d176f4eebeb7ec983fa77d945c18fb1
We do have an objective-c services layer. but it might as well be in c++
Please upvote / help out this issue which would provide a native swift services layer.
grpc/grpc-swift#2
Frankly I'm a bit in the dark with next steps.
Will need to pain stakingly map each respective swift file to tensorflow api.
from tensorflow.
@MattSich I just rewrote the camera part to Swift but the runCNNOnFrame method is still in Objective-C++.
from tensorflow.
@chengsam actually already did it but have been waiting for the client for my current project to approve the contribution back to this repo
from tensorflow.
@chengsam @MattSich how were you able to rewrite the camera in Swift while keeping the runCNNOnFrame method in Obj-C++ ? Looking for some pointers; trying to do the same thing.
from tensorflow.
@ssgutierrez42 You have to use a bridging header to call Obj-C++ code from Swift.
from tensorflow.
Would it be useful to include a swift project in the repo that's setup to call runCNNOnFrame via Obj-C++? If so I can probably contribute later on.
@chengsam yup. My problem was with linking libraries but I got it.
from tensorflow.
so - I have some base grpc SERVICE classes in swift 3 using google grpc.
Feel free to grab my script to do mass conversion->
https://github.com/nubbel/swift-tensorflow
https://github.com/nubbel/swift-tensorflow/tree/master/Generated
looking for help if anyone has extra bandwidth
from tensorflow.
so proto buffers are neat. turns out you can rip apart trained models with a few lines of swift code.
here's a gist using inception .pb trained model
https://gist.github.com/johndpope/5b6bb864d335398bf9b0886c4a09217d
latest code here
https://github.com/johndpope/tensorflow/tree/master/tensorflow/swift
(I'm yet to cut in tensors.)
from tensorflow.
I think the major standout TensorFlow porting project right now is the C#/F# port called TensorFlowSharp by Miguel de Icaza.
from tensorflow.
Today published first version for high-level swift API TensorFlowKit. Have plans to push to google repository in future.
from tensorflow.
@VolodymyrPavliukevych please feel free to absorb mature components of the first successful TensorFlow Swift language binding acknowledged by google : Perfect TensorFlow, which works well in OS X and Ubuntu and simple easy installation and as well as the runtime downcast compatibility from TensorFlow 1.2 to 1.4. Welcome aboard! The Perfect TensorFlow has already a full testing script with 34 different tests to completely cover the TensorFlow C API. You can take as many as possible, it’s Apache 2.0 open source
from tensorflow.
Anyway it also has Chinese documents and Perfect Swift server native compatibility
from tensorflow.
@RockfordWei, how to write model and statistic to file system for tensorboar using Perfect?
from tensorflow.
Perfect TensorFlow provides a super high level & convenient API to deal with the graph:
For example, there is a graph protocol buffer file "graph.pb", you can do the following steps to load / save it:
import PerfectTensorFlow
import PerfectLib
import Foundation
typealias TF = TensorFlow
// load file into Data structure first
let fModel = File("graph.pb")
try fModel.open(.read)
let bytes = try fModel.readSomeBytes(count: fModel.size)
let data = Data(bytes: bytes)
// turn the data into graph definition
let def = try TF.GraphDef(serializedData: data)
// import it into the running graph
let graph = try TF.Graph()
try graph.import(definition: def)
// run a session
let session. = try graph.runner()
.feed("DecodeJpeg/contents", tensor: someTensor)
.fetch("final_result")
.run()
// get the current buffer after session
if let dat = graph.buffer?.data {
// now you can save the data bytes into another file
}
from tensorflow.
@RockfordWei but how to save and open graphs and statistic of changes for TensorBoard?
from tensorflow.
@VolodymyrPavliukevych summary
is a python object with those statistics as a writer:
tensorflow/python/summary/write
Like I said, it would grab the graph bytes and then add an event with other tags as "meta assets" - so you can load/save the model with these statistics.
You can surely implement it in Swift with the same method.
from tensorflow.
@RockfordWei, So there isn’t that write feature in perfect? am I right?
from tensorflow.
@RockfordWei, don’t worry, you can use TensorFlowKit library for that.
from tensorflow.
@VolodymyrPavliukevych
No, let me clarify a bit: Perfect does have all required protobufs, such as summary and events:
https://github.com/PerfectlySoft/Perfect-TensorFlow/blob/f638c65e03ffc6d6bf488576f582246eee12540a/Sources/PerfectTensorFlow/pb.summary.swift
https://github.com/PerfectlySoft/Perfect-TensorFlow/blob/f638c65e03ffc6d6bf488576f582246eee12540a/Sources/PerfectTensorFlow/pb.event.swift
It is up to the end user and I can surely add it with TensorFlow 1.4.0 if need.
from tensorflow.
Thanks, @VolodymyrPavliukevych , Now Perfect-TensorFlow has the same test script from you for how to use TensorBoard - thank you for reminding me to double check that Perfect-TensorFlow's powerful features - it had been there since 1.1.5, the very first release, actually, my fault, I didn't realize the end user would like such a demo.
from tensorflow.
@RockfordWei any plan to create a pod? So that we can use it in ios apps too?
from tensorflow.
@tirrorex Thanks for asking. However, PerfectlySoft currently doesn't have such a plan because Apple has already published CoreML framework which supports mobile application well enough. Perfect-TensorFlow is a Server Side Swift to maximize the power of the cloud computation and makes zero conflicts with Apple's strategy.
However, you can still have a good try. Tips are right here: tensorflow ios examples
This is a very old pod release for 1.1.x, which can help you build an iOS version of tensorflow framework, which is theoretically compatible with Perfect-TensorFlow by setting the customized framework into a dylib to call. Check Perfect-TensorFlow APIloader.swift for detail - it is using dlopen()
and dlsym()
to load TensorFlow binaries on demand.
However, even it works, you may need to accept the fact that the old iOS framework example would like to cost your app an extra 300MB or even larger, so please make sure that you know exactly what you want and read some valuable CoreML articles before doing it.
Thank you.
from tensorflow.
@RockfordWei what my company want is to keep supporting people not running ios 11, either because they don't want to or because they can't.
Since we use tensorflow already on android and with coreML not being available for all our customers we have no choice but to use tensorflow.
ps : looking more closely at the examples i can now see that the code is in fact objectice-c ++
So there is no way to use it in swift without bridging everything, at least none that i am aware off.
Shouldn't it be possible to copy some of PerfectlySoft's work to get this bridge?
It could even be included into tensorflow itself and fix this issue for everyone using swift ?
@ssgutierrez42 yes please
from tensorflow.
@VolodymyrPavliukevych , sorry for dumb question, but how to include your library into Cocoa Pods project? I'm new to Swift Package Manager, and don't know how to make it friends with Cocoa Pods...
from tensorflow.
@alexnivanov Actually, please note that TensorFlow itself has a brand new lib for mobile app: TensorFlow Lite
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/lite
It looks pretty cool
from tensorflow.
@VolodymyrPavliukevych thanks, it's pretty complex though :)
I managed to integrate objc with my swift project, so I'll live with it for now...
@RockfordWei yeah it's cool, but not all models can be converted to TF Lite. I'm waiting for TF 1.5 release to check it again...
from tensorflow.
Perfect-TensorFlow - Swift Lanugage Binding for TensorFlow on Server Side just synchronized to
1.5.0:
Adding Results
for Graph: results.missingUnusedInputMappings()
Preparing next GM for:
- TF_NewApiDefMap
- TF_DeleteApiDefMap
- TF_ApiDefMapPut
- TF_ApiDefMapGet
- TF_SetAttrFuncName
- TF_GraphNumFunctions
- TF_GraphGetFunctions
from tensorflow.
Hi @rxwei
I am not able to use the TensorFlow module inside Swift. Is it available in the swift package manager.
Welcome to Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.39.1). Type :help for assistance. 1> import TensorFlow error: repl.swift:1:8: error: no such module 'TensorFlow' import TensorFlow
from tensorflow.
@droidresearch We will be open-sourcing Swift for TensorFlow in April.
from tensorflow.
Thanks for the clarification.
from tensorflow.
Related Issues (20)
- tf.linalg.svd([inf, -inf]) throws internal error logs to the console, and generates inconsistent results on different dtypes. HOT 3
- "ValueError: Layer 'dense' expected 1 input(s). Received 2 instead" on tf.keras.models.load_model HOT 2
- TF 2.16.1 and Apple Silicon GPU support not working. HOT 3
- Conv3D Operation Error on Windows platform HOT 2
- TFLite 2.16.1 conversions fail with "AttributeError: 'Sequential' object has no attribute '_get_save_spec'" HOT 4
- Aborted (core dumped) in tf.raw_ops.SparseMatrixZeros HOT 1
- Tensorflow WSL GPU CUDA recognition issue RTX3090 HOT 8
- Selectively build TFLite frameworks failed! HOT 1
- Converting Model to TFLite using Tensorflow 2.16.1 fails - works w/ 2.15.0 HOT 7
- android.support.v13.app does not exist while building TfLiteCameraDemo HOT 4
- Aborted (core dumped) in tf.math.unsorted_segment_mean HOT 2
- Could not find variable Conv_Pool_7/kernel_7. This could mean that the variable has been deleted. In TF1, it can also mean the variable is uninitialized. Debug info: container=localhost, status error message=Container localhost does not exist. (Could not find resource: localhost/Conv_Pool_7/kernel_7) HOT 3
- Upgrading to tensorflow 2.15.1 from 2.14.1 produces pylint bug: E1101: Module 'tensorflow' has no 'keras' member HOT 3
- ‘Val_loss’ is not generated and training is getting interrupted before the completion of the last epoch for a multi-input multi-output model. This is happening when my checkpoint directory is checkpoint_dir + "/checkpoint-{epoch:02d}.tf" HOT 3
- How to open a Tensorflow <= 2.0 Legacy Model ? HOT 1
- Add MetaGraphDef parser to C API to get SignatureDef (inputs / outputs) from saved model HOT 2
- Working code broke after deploying to new installation. ValueError: When using `stateful=True` in a RNN, the batch size must be static. Found dynamic batch size: sequence.shape=(None, xx, xx)
- Unexpected steps_per_epoch behavior in model.fit HOT 2
- slient overflow occurs in tf.range leading to incorrect result, here is a possible fix HOT 5
- Issue with file reading when using TPU enabled colab machine HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tensorflow.