Introduction to Machine Learning on Mobile [Video]
Introduction to Machine Learning on Mobile [Video]
With all the latest machine learning frameworks and tools available, we can now make our mobile apps smarter with very little effort.
Join the DZone community and get the full member experience.Join For Free
Start coding something amazing with the IBM library of open source AI code patterns. Content provided by IBM.
Machine learning and AI technology are taking mobile app development to a new level. Apps utilizing machine learning can now recognize speech, images, and gestures, and translate voices with extraordinary success rates! Why is this important? It gives us new and compelling ways to engage and interact with objects, people, and the world around us. Machine learning is truly making our smart devices smart. And as a mobile developer, you create the bridge between the technology and the device. How cool is that?!
I'm passionate about this because I'm a mobile developer and a cloud solutions architect. This article is intended for mobile developers who want an understanding of machine learning and how to use it in a mobile application without understanding the complexities of algorithms and how they train models and learn. Let the data scientists worry about that!
In this article, I'll briefly define AI and machine learning, explain why machine learning is so hot, pinpoint the parts of machine learning most relevant to mobile development, and provide tips for getting started.
Here we go!
What Is AI?
Artificial intelligence (AI) is a broad term for applying any technique that enables computers to mimic human intelligence, using logic, if-then rules, decision trees, and machine learning (including deep learning). Think chatbots, robots, and KITT from Knight Rider!
What Is ML?
A subset of AI, machine learning (ML) is a set of methods that can automatically detect patterns in data, and then use the uncovered patterns to predict future data or to perform other kinds of decision making under uncertainty.
Machine learning is all about using data to answer questions. First, data (e.g. images, text, or voice) is provided along with answers (labels) to that data. Then, the computer (model) is trained on this data so it can "learn" and later make predictions (aka inference) on the mobile device.
Mobile apps use pre-trained models to make predictions. These models are first trained outside of the app — typically in the cloud — and then brought into the app to accomplish the task of answering questions based on the data you provide.
Why All the Hype?
Several developments in the world of ML are creating an exciting playing field for mobile developers:
Advances in neural networks (algorithms) have dramatically improved accuracy in recognizing images and speech. Accuracy rates matter. So, what seemed like science fiction not so long ago is here today.
Advances in cloud computing have greatly reduced the time it takes to train these models. I'm talking weeks to hours! That means fewer resources, reduced capital expenses, and faster time-to-market.
There's also been a flood of third-party API-driven machine learning services hitting the market that do a lot of the heavy lifting for you. Build your own or let someone else do it.
For these reasons and more, engineers, data scientists, and developers are jumping in to help build tools and frameworks to stoke this momentum, thus putting AI and ML in the hands of every mobile developer.
Three Types of Machine Learning
There are three types of machine learning:
Supervised learning is a system of all labeled data and a predictive model. We use labeled data to train a "model" and then use that "model" to make predictions (inference) on new unlabeled data. The trained model is the core of our discussion when it comes to machine learning on a mobile device.
Supervised learning covers more than 90% of practical uses of machine learning for mobile apps and will be the focus of this article.
Supervised learning consists of two problem-solving tasks: regression and classification.
Regression: Based on data input, this ML predicts a continuous numerical value where the output is a real value, such as "dollars" or "pounds". For example, I have a 2009 Honda Civic EX with 200,000 miles in fair condition in Seattle. What will my car be worth in two years?
Classification: This ML takes mined data to deliver a categorical output variable, such as "cat" or "dog". For example, when you take a picture of your neighbor's pet, the ML on your phone can tell you it's a dog and what the dog is doing.
Getting Started Considerations
So, we now understand machine learning, why it's being used, and what problems it can solve, but how do you start playing with it as a mobile developer?
There are a variety of machine learning tools available for iOS and Android developers; however, most of these tools are unfriendly for the mobile environment, often require significant work and/or may not be proven to work on mobile devices. So, currently, only a few good choices exist for AI/ML on-device tools for mobile development. For iOS, use Core ML (read more here). For Android, use TensorFlow Lite.
For iOS developers, Apple provides machine learning tools like Core ML, Vision, and NLP. Core ML is the framework used across Apple products for providing optimized on-device ML inference and is fully integrated with the Vision and NLP frameworks. In this case, the fully trained model is trained in the cloud, converted to Core ML format, and then added to your Xcode project.
For Android development, use TensorFlow Lite (in preview), which is the lightweight version of the TensorFlow open-source library. TensorFlow Lite is a small binary for mobile and embedded devices to provide on-device, low-latency machine learning inference using a pre-trained TensorFlow Lite model file.
What about cross-platform machine learning?!?!
Good question. The TensorFlow framework does support both Android and iOS, but I'll answer by saying Apple builds the hardware and software. The Core ML framework is optimized for iOS and the integrated ML toolset from Apple just doesn't make sense for developers to use the TensorFlow framework on iOS. However, the simple solution, if you are committed to TensorFlow, is to use the TensorFlow ML framework to train and build the ML model in the cloud and then convert the TensorFlow model file (.tflite) to Core ML model type (.mlmodel) using this TensorFlow to CoreML Converter tool.
This is the best of both worlds, as the ML model is really the core of ML and you are simply interfacing with the same trained model on the device but using the best framework for each platform.
With all the latest machine learning frameworks and tools available, we can now make our mobile apps smarter with very little effort. ML and AI functionality in mobile apps will soon be the norm — and your customers will begin to expect and demand these solutions (even if they don't know it's AI/ML under the hood).
Think about what problems you want to solve with your app, but also play around, have fun, and maybe you'll even identify a huge gap and disrupt an entire industry!
To learn more, check out my other DZone article Understand Core ML in 5 Minutes.
I hope you enjoy!
This article was first published by Dennis Hills on Medium.
Published at DZone with permission of Dennis Hills . See the original article here.
Opinions expressed by DZone contributors are their own.