Artificial Intelligence has been a hot topic on recent years and there are strong reasons for that.
For starters, in the next decade around 40% of current job positions will be automated or replaced by artificial intelligence systems. Then there is the strong investor interest in AI projects on several key areas: Supply Chain Management, Sales, Marketing, Operations, IT or Finance for example.
While the AI field has different specializations, Deep Learning is perhaps the most fertile area from a practical applications point of view. Long story short, DL algorithms mimics the neural connections in human brain, being able to create pattern recognition models by feeding untagged data.
Image recognition, Computer Vision, Speech and Language processing have been largely tacked by DL and one can only expect magic to happen in the coming years as new applications are discovered.
On the iOS scene there are three fundamental players in this area: Tensorflow Lite, Core ML and PyTorch, each with it’s own merits and caveats.
Join us to review the top 3 Deep Learning frameworks for iOS, in this introductory essay.
In a properly automated and educated world, then, machines may prove to be the true humanizing influence. It may be that machines will do the work that makes life possible and that human beings will do all the other things that make life pleasant and worthwhileIsaac Asimov, Robot Visions
TensorFlow is the most popular and mature framework for Deep Learning projects, with the biggest community and largest code base of examples. It is both a model training and inference tool, whereas TensorFlow Lite is a framework designed particularly for inference on mobile and low computing power devices.
You begin by training the model under TensorFlow, and then applying the converter to get the optimized model.
Some of the disadvantages of Tensorflow Lite are inherent to the reduced storage space and computing power of mobile devices, like the expected tradeoff of accuracy in comparison to the full models.
On the positive side of things, converted models are compatible with both iOS and Android, and even IoT devices, being able to perform offline inference with low latency without requiring external API services.
When comparing Tensorflow Lite with CoreML (Apple ML set of libraries and components), it’s unavoidable to assume that the former won’t reach Apple’s native Framework performance, but Tensorflow Lite has been optimized to make use of iOS AI hardware, and performs best on devices with Apple A12 chip (iPhone XS) or higher that has built-in NPU units, and being able to generate a single model and import it into multiple platforms is a plus.
PyTorch is an open-source machine learning library based on Torch. It provides an imperative and Pythonic programming style that supports code as a model, makes debugging easy and is consistent with other popular scientific computing libraries, while remaining efficient and supporting hardware accelerators such as GPUs and NPUs.
With this library, computations run immediately, this means that the user doesn’t need to write the full code before checking if it works or not. We can efficiently run a part of the code and inspect it in real-time.
The library is python based built for providing flexibility as a deep learning development platform.
PyTorch has an accessible API that is easy to learn and train new model. If your team has a Python knowledge background, you will find useful that PyTorch smoothly integrates with the python data science stack. In fact it is similar to numpy, so if you are already using that, you will feel right at home.
The framework provides Dynamic computation graphs, a feature to build computational graphs on the go, and even change them during runtime instead of predefined graphs with specific functionalities. This service is valuable for situations where requirements of memory for creating a neural network is unknown.
Other key strengths of the machine learning framework include:
Core ML is Apple’s own attempt into the machine learning discipline. It provides a means to run inference on models exclusively on Apple ecosystem, leveraging their custom ARM architecture and NPU extensions, providing great performance and low CPU consumption, and is complemented by Create ML to be able to train models without having to resort to third party frameworks like TensorFlow.
Whereas TensorFlow Lite makes use of TensorFlow created models, Core ML can use TensorFlow or PyTorch converted multiplatform models, or directly use models created by Create ML, giving it full flexibility about the source model.
Create ML provides a graphical interface making it perhaps the most intuitive model trainer of the pack. One of it’s main disadvantages is perhaps a limited series of training algorithms comparing to TensorFlow or PyTorch.
Depending on the particular scenario to be implement, Create ML might be sufficient or it might fall short requiring to resort to other of the reviewed frameworks.
Differentiation grid for each alternative
|TensorFlow||PyTorch||Create ML + Core ML|
|Programming language||C++ / Python||Python||ObjC / Swift|
|Ease of use||Complex||Medium||User friendly|
|License||Open Source||Open Source||Proprietary|
In Overactive we believe that in every complex software project, picking the right tools and assembling the adequate team based on the technical requirements is first step in accomplishing a successful delivery.
The kind of problems that can be solved with Deep Learning requires a scientific, statistical and empirical approach based on trial and error, and continuous hypothesis verification.
Frameworks like Create ML that favor prototyping or offer playground environments as opposed to those requiring lengthy scripting to start validating model inference will surely be useful in getting a first approximation to the problem quickly.
On the other side, if the project requires complex layer types, TensorFlow is the framework to pick, as it has the broadest layer support in the industry, and also concentrates most of the courses, documents and code samples.
Special thanks to Laureano De Andrea and Damian Pintos from the Mobile Hub.