Code Monkey home page Code Monkey logo

tensorflow-ios-example's Introduction

TensorFlow on iOS demo

This is the code that accompanies my blog post Getting started with TensorFlow on iOS.

It uses TensorFlow to train a basic binary classifier on the Gender Recognition by Voice and Speech Analysis dataset.

This project includes the following:

  • The dataset in the file voice.csv.
  • Python scripts to train the model with TensorFlow on your Mac.
  • An iOS app that uses the TensorFlow C++ API to do inference.
  • An iOS app that uses Metal to do inference using the trained model.

Training the model

To train the model, do the following:

  1. Make sure these are installed: python3, numpy, pandas, scikit-learn, tensorflow.
  2. Run the split_data.py script to divide the dataset into a training set and a test set. This creates 4 new files: X_train.npy, y_train.npy, X_test.npy, and y_test.npy.
  3. Run the train.py script. This trains the logistic classifier and saves the model to /tmp/voice every 10,000 training steps. Training happens in an infinite loop and goes on forever, so press Ctrl+C when you're happy with the training set accuracy and the loss no longer becomes any lower.
  4. Run the test.py script to compute the accuracy on the test set. This also prints out a report with precision / recall / f1-score and a confusion matrix.

Using the model with the iOS TensorFlow app

To run the model on the iOS TensorFlow app, do the following:

  1. Clone TensorFlow and build the iOS library.
  2. Open the VoiceTensorFlow Xcode project. In Build Settings, Other Linker Flags and Header Search Paths, change the paths to your local installation of TensorFlow.

The model is already included in the app as inference.pb. If you train the model with different settings, you need to run the freeze_graph and optimize_for_inference tools to create a new inference.pb.

Using the model with the iOS Metal app

To run the model on the iOS Metal app, do the following:

  1. Run the export_weights.py script. This creates two new files that contain the model's learned parameters: W.bin for the weights and b.bin for the bias.
  2. Copy W.bin and b.bin into the VoiceMetal Xcode project and build the app.

You need to run the Metal app on a device, it won't work in the simulator.

tensorflow-ios-example's People

Contributors

hollance avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tensorflow-ios-example's Issues

Running error

Hi i am getting this error Error: This device does not support Metal Performance Shaders: file /Users/mac/Downloads/TensorFlow-iOS-Example-master 3/VoiceMetal/VoiceMetal/ViewController.swift, line 49

'tensorflow/core/public/session.h' file not found

Hi.

I have run tensorflow/contrib/makefile/build_all_ios.sh and the following files now exist libtensorflow-core.a, libprotobuf.a, libprotobuf-lite.a at:

"/Users/anton6/tensorflow/tensorflow/contrib/makefile/gen/protobuf_ios/lib/libprotobuf-lite.a"

"/Users/anton6/tensorflow/tensorflow/contrib/makefile/gen/protobuf_ios/lib/libprotobuf.a"

"/Users/anton6/tensorflow/tensorflow/contrib/makefile/gen/lib/libtensorflow-core.a"

I have updated the paths in Build Settings/Other Linker Flags accordingly, but I get the error 'tensorflow/core/public/session.h' file not found when trying to run.

Any idea what I am doing wrong?

Thanks

hello!it's me again(awkward)!

In your article, you said
Then to install the package:

pip3 uninstall tensorflow
sudo -H pip3 install /tmp/tensorflow_pkg/tensorflow-1.0.0-XXXXXX.whl

I wanna know why I have to uninstall my tensor flow ,if I uninstall it, how can I use it after that?

hello!it's me again, thanks for the guide u gave me before and I fixed that bug,but I met another problem!

crissallandeMacBook-Pro:~ crissallan$ python3 train.py
Training set size: (2217, 20)
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
Initial loss 0.693146

hello!I meet a bug when run train.py could you please tell me how to fix it?

crissallandeMacBook-Pro:~ crissallan$ python3 train.py
Training set size: (2217, 20)
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
Traceback (most recent call last):
File "train.py", line 56, in
loss_value=sess.run(loss,feed_dict={x: X_train,y: y_train,regularization: 0})
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 767, in run
run_metadata_ptr)
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 903, in _run
raise RuntimeError('Attempted to use a closed Session.')
RuntimeError: Attempted to use a closed Session.

hi, i wanna run this project on my iPhone but meet some problems

None of your accounts are a member of 'MGCEKGP4Y4': An unexpected error occurred. Xcode cannot find a team matching 'MGCEKGP4Y4'.

No profiles for 'com.hollance.VoiceTensorFlow' were found: Xcode couldn't find a provisioning profile matching 'com.hollance.VoiceTensorFlow'.

Code signing is required for product type 'Application' in SDK 'iOS 10.3'
problem No.2

Integrating this in swift giving 'string' file not found error

I am using this framework in a swift project and used a bridging header to implement some functionalities. I was included this framework with CocoaPods into my swift project. But while trying to build the project, there are so many syntax errors like #include not found, #include not found etc. I have been banging my head around this issue from past two days but no luck. The Xcode compiler is able to build if i am using an Objective C Project. Somebody please guide me to resolve the issue with swift project

Thanks in Advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.