{"id":15039674,"url":"https://github.com/xmartlabs/bender","last_synced_at":"2025-05-15T11:09:07.474Z","repository":{"id":47960525,"uuid":"90192362","full_name":"xmartlabs/Bender","owner":"xmartlabs","description":"Easily craft fast Neural Networks on iOS! Use TensorFlow models. Metal under the hood.","archived":false,"fork":false,"pushed_at":"2023-11-07T10:28:36.000Z","size":72730,"stargazers_count":1802,"open_issues_count":18,"forks_count":89,"subscribers_count":55,"default_branch":"master","last_synced_at":"2025-05-07T05:36:02.852Z","etag":null,"topics":["apple","convolutional-neural-networks","deep-learning","deep-neural-networks","ios","iphone","machine-learning","metal","neural-networks","residual-networks","swift"],"latest_commit_sha":null,"homepage":"https://xmartlabs.github.io/Bender/","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xmartlabs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":"xmartlabs","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2017-05-03T20:52:12.000Z","updated_at":"2025-05-04T16:38:19.000Z","dependencies_parsed_at":"2022-08-26T06:10:17.068Z","dependency_job_id":"8b779b13-97a8-4084-8661-54a65426793a","html_url":"https://github.com/xmartlabs/Bender","commit_stats":{"total_commits":88,"total_committers":13,"mean_commits":6.769230769230769,"dds":0.5,"last_synced_commit":"67b326a815e2bfd7f8df264c84b1ee0f1a0b4d51"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xmartlabs%2FBender","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xmartlabs%2FBender/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xmartlabs%2FBender/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xmartlabs%2FBender/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xmartlabs","download_url":"https://codeload.github.com/xmartlabs/Bender/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254328386,"owners_count":22052632,"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":["apple","convolutional-neural-networks","deep-learning","deep-neural-networks","ios","iphone","machine-learning","metal","neural-networks","residual-networks","swift"],"created_at":"2024-09-24T20:43:35.623Z","updated_at":"2025-05-15T11:09:07.455Z","avatar_url":"https://github.com/xmartlabs.png","language":"Swift","funding_links":["https://github.com/sponsors/xmartlabs"],"categories":[],"sub_categories":[],"readme":"# Bender\n\n\u003cp align=\"left\"\u003e\n\u003ca href=\"https://travis-ci.org/xmartlabs/Bender\"\u003e\u003cimg src=\"https://travis-ci.org/xmartlabs/Bender.svg?branch=master\" alt=\"Build status\" /\u003e\u003c/a\u003e\n\u003cimg src=\"https://img.shields.io/badge/platform-iOS-blue.svg?style=flat\" alt=\"Platform iOS\" /\u003e\n\u003ca href=\"https://developer.apple.com/swift\"\u003e\u003cimg src=\"https://img.shields.io/badge/swift4-compatible-4BC51D.svg?style=flat\" alt=\"Swift 4 compatible\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://cocoapods.org/pods/MetalBender\"\u003e\u003cimg src=\"https://img.shields.io/cocoapods/v/MetalBender.svg\" alt=\"CocoaPods compatible\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/Carthage/Carthage\"\u003e\u003cimg src=\"https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat\" alt=\"Carthage compatible\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://raw.githubusercontent.com/xmartlabs/Bender/master/LICENSE\"\u003e\u003cimg src=\"http://img.shields.io/badge/license-MIT-blue.svg?style=flat\" alt=\"License: MIT\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://app.fossa.io/projects/git%2Bgithub.com%2Fxmartlabs%2FBender?ref=badge_shield\" alt=\"FOSSA Status\"\u003e\u003cimg src=\"https://app.fossa.io/api/projects/git%2Bgithub.com%2Fxmartlabs%2FBender.svg?type=shield\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n![Bender](Documentation/Media/Artboard.png)\n\nBender is an abstraction layer over MetalPerformanceShaders useful for working with neural networks.\n\n## Contents\n* [Introduction](#introduction)\n* [Why did we need Bender](#why)\n* [Basic usage](#usage)\n* [Requirements](#requirements)\n* [Getting involved](#getting-involved)\n* [Examples](#examples)\n* [Installation](#installation)\n* [Changelog](#change-log)\n\nThe documentation can be found under the `Documentation` folder:\n* [API](Documentation/API.md) contains the most important information to get started.\n* [Supported Layers] explains which layers are supported and how they map to TensorFlow ops.\n* [Importing] explains how to import models from other frameworks such as TensorFlow. You can also find information on how to enhance this functionality for custom implementations.\n\n## Introduction\n\nBender is an abstraction layer over MetalPerformanceShaders which is used to work with neural networks. It is of growing interest in the AI environment to execute neural networks on mobile devices even if the training process has been done previously. We want to make it easier for everyone to execute pretrained networks on iOS.\n\nBender allows you to easily define and run neural networks using the most common layers like Convolution, Pooling, FullyConnected and some normalizations among others. It is also flexible in the way it receives the parameters for these layers.\n\nWe also want to support loading models trained on other frameworks such as TensorFlow or Caffe2. Currently Bender includes an adapter for TensorFlow that loads a graph with variables and \"translates\" it to Bender layers. This feature supports a subset of TensorFlow's operations but we plan to enhance it to cover more cases.\n\n## Why did we need Bender? \u003ca name=\"why\"\u003e\u003c/a\u003e\n\nAt [Xmartlabs] we were about to start a Machine Learning project and investigated frameworks to use in iOS. We found MetalPerformanceShaders useful but not very user friendly and we saw ourselves repeating a lot of code and information. That is why we starting building a framework to handle that kind of stuff.\n\nWe also found ourselves creating scripts to translate the models we had from training with TensorFlow to iOS. This means transposing the weights to the MPSCNN format and also mapping the parameters of the different kinds of layers in TensorFlow to the parameters used by the MPSCNN kernels. TensorFlow can be compiled for iOS but currently it does not support running on GPU which we wanted to do. We also did not want to include TensorFlow's static library into our project. This is why we also started to work on an adapter that would parse a TF graph and translate it to our Bender layers.\n\n## Usage\n\nYou can define your own network in Bender using our custom operator or you can load a model exported from TensorFlow. Defining a network and loading a model can be done like this:\n\n```swift\nimport MetalBender\n\nlet url = Bundle.main.url(forResource: \"myModel\", withExtension: \"pb\")! // A TensorFlow model.\nlet network = Network.load(url: url, inputSize: LayerSize(h: 256, w: 256, f: 3))\n\nnetwork.run(input: /* ... */) { output in\n    // ...\n}\n```\n\nYou can read more information about this in [Importing](Documentation/Importing.md).\n\nIf you want to define your network yourself you can do it like this:\n\n```swift\nlet network = Network(inputSize: LayerSize(h: 256, w: 256, f: 3))\n\nnetwork.start\n    -\u003e\u003e Convolution(convSize: ConvSize(outputChannels: 16, kernelSize: 3, stride: 2))\n    -\u003e\u003e InstanceNorm()\n    -\u003e\u003e Convolution(convSize: ConvSize(outputChannels: 32, kernelSize: 3, stride: 2), neuronType: .relu)\n    -\u003e\u003e InstanceNorm()\n    -\u003e\u003e FullyConnected(neurons: 128)\n    -\u003e\u003e Neuron(type: .tanh)\n    -\u003e\u003e FullyConnected(neurons: 10)\n    -\u003e\u003e Softmax()\n// ...\n```\n\nand once you're done with all your layers:\n\n```swift\nnetwork.initialize()\n```\n\nTo know more about this have a look at [API](Documentation/API.md).\n\n\n## Requirements\n\n* Xcode 9\n* iOS 11.0+ (but deployment target is iOS 10.0, so iOS 10 is supported)\n\n## Getting involved\n\n* If you **want to contribute** please feel free to **submit pull requests**.\n* If you **have a feature request** please **open an issue**.\n* If you **found a bug** or **need help** please **check older issues, [FAQ](#faq) and threads on [StackOverflow](https://stackoverflow.com) before submitting an issue**.\n\nBefore contribute check the [CONTRIBUTING] file for more info.\n\nIf you use **Bender** in your app We would love to hear about it! Drop us a line on [Twitter](https://twitter.com/xmartlabs).\n\n## Examples\n\nFollow these steps to run the examples:\n* Clone Bender repository (or download it).\n* Run `carthage update --platform iOS` in the downloaded folder.\n* Open Bender workspace and run the *Example* project.\n\n\u003e There is an Image recognition example which includes a MobileNet model in Bender and one in CoreML. It is also set up to run an Inception model but you will have to download it separately as it is almost 100 MB in size.\nYou can download it from http://download.tensorflow.org/models/inception_v3_2016_08_28.tar.gz but then you have to freeze it and add it to the 'Example' Xcode project as 'inception_v3.pb'.\n\n## Installation\n\n#### CocoaPods\n\nTo install Bender, simply add the following line to your Podfile:\n\n```ruby\npod 'MetalBender', '~\u003e 0.5'\n```\n\n\u003e Remember that Bender compiles for iOS 10. So you must add `platform :ios, '10.0'` to your Podfile\n\n#### Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a simple, decentralized dependency manager for Cocoa.\n\nTo install Bender, add the following line to your Cartfile:\n\n```ogdl\ngithub \"xmartlabs/Bender\" ~\u003e 0.5\n```\n\nThen run:\n\n```bash\ncarthage update --platform iOS\n```\n\nFinally, drag the built `.framework` binaries for `MetalBender`, `MetalPerformanceShadersProxy` and `SwiftProtobuf` to your application's Xcode project.\n\n## Author\n\n* [Xmartlabs SRL](https://github.com/xmartlabs) ([@xmartlabs](https://twitter.com/xmartlabs))\n\n\n# Change Log\n\nThis can be found in the [CHANGELOG.md](CHANGELOG.md) file.\n\n\u003c!-- Links --\u003e\n[Xmartlabs]: http://xmartlabs.com\n[Importing]: Documentation/Importing.md\n[CONTRIBUTING]: .github/CONTRIBUTING.md\n[API]: Documentation/API.md\n[Supported Layers]: Documentation/Supported_Layers.md\n\n\n## License\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fxmartlabs%2FBender.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fxmartlabs%2FBender?ref=badge_large)\n\n## Citation\nIf you use this code in your research please cite us:\n\n```bibtex\n@misc{xmartlabs-2017-bender,\n  author = {Mathias Claassen and Santiago Castro},\n  title = {Bender: Easily craft fast Neural Networks on {iOS}!},\n  year = {2017},\n  publisher = {GitHub},\n  journal = {GitHub repository},\n  howpublished = {\\url{https://xmartlabs.github.io/Bender/}}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxmartlabs%2Fbender","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxmartlabs%2Fbender","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxmartlabs%2Fbender/lists"}