{"id":13750004,"url":"https://github.com/hollance/TensorFlow-iOS-Example","last_synced_at":"2025-05-09T13:31:50.961Z","repository":{"id":138081918,"uuid":"83991662","full_name":"hollance/TensorFlow-iOS-Example","owner":"hollance","description":"Source code for my blog post \"Getting started with TensorFlow on iOS\"","archived":false,"fork":false,"pushed_at":"2017-03-06T14:23:21.000Z","size":425,"stargazers_count":440,"open_issues_count":8,"forks_count":86,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-04-07T07:06:09.855Z","etag":null,"topics":["ios","logistic-regression","machine-learning","metal","tensorflow","voice-recognition"],"latest_commit_sha":null,"homepage":null,"language":"Swift","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/hollance.png","metadata":{"files":{"readme":"README.markdown","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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-03-05T18:16:26.000Z","updated_at":"2025-01-16T10:27:07.000Z","dependencies_parsed_at":"2024-01-07T00:06:35.397Z","dependency_job_id":"1f91c1c0-10c8-48d0-81ad-07777e607919","html_url":"https://github.com/hollance/TensorFlow-iOS-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/hollance%2FTensorFlow-iOS-Example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hollance%2FTensorFlow-iOS-Example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hollance%2FTensorFlow-iOS-Example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hollance%2FTensorFlow-iOS-Example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hollance","download_url":"https://codeload.github.com/hollance/TensorFlow-iOS-Example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253258287,"owners_count":21879620,"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":["ios","logistic-regression","machine-learning","metal","tensorflow","voice-recognition"],"created_at":"2024-08-03T07:01:21.719Z","updated_at":"2025-05-09T13:31:50.629Z","avatar_url":"https://github.com/hollance.png","language":"Swift","funding_links":[],"categories":["iOS","Swift","General"],"sub_categories":["Web"],"readme":"# TensorFlow on iOS demo\n\nThis is the code that accompanies my blog post [Getting started with TensorFlow on iOS](http://machinethink.net/blog/tensorflow-on-ios/).\n\nIt uses TensorFlow to train a basic binary classifier on the [Gender Recognition by Voice and Speech Analysis](https://www.kaggle.com/primaryobjects/voicegender) dataset.\n\nThis project includes the following:\n\n- The dataset in the file **voice.csv**.\n- Python scripts to train the model with TensorFlow on your Mac.\n- An iOS app that uses the TensorFlow C++ API to do inference.\n- An iOS app that uses Metal to do inference using the trained model.\n\n## Training the model\n\nTo train the model, do the following:\n\n1. Make sure these are installed: `python3`, `numpy`, `pandas`, `scikit-learn`, `tensorflow`.\n2. 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`.\n3. 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.\n4. 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.\n\n## Using the model with the iOS TensorFlow app\n\nTo run the model on the iOS TensorFlow app, do the following:\n\n1. Clone [TensorFlow](https://github.com/tensorflow) and [build the iOS library](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/makefile).\n2. Open the **VoiceTensorFlow** Xcode project. In **Build Settings**, **Other Linker Flags** and **Header Search Paths**, change the paths to your local installation of TensorFlow.\n\nThe 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.\n\n## Using the model with the iOS Metal app\n\nTo run the model on the iOS Metal app, do the following:\n\n1. 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.\n2. Copy `W.bin` and `b.bin` into the **VoiceMetal** Xcode project and build the app.\n\nYou need to run the Metal app on a device, it won't work in the simulator.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhollance%2FTensorFlow-iOS-Example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhollance%2FTensorFlow-iOS-Example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhollance%2FTensorFlow-iOS-Example/lists"}