Image classification - ML on Raspberry Pi with MediaPipe Series
Key Takeaways
Classifies images using MediaPipe on Raspberry Pi
Full Transcript
Hey all, I'm Paul Ruiz, an engineer with the developer relations team on Google ML. And this is the first video in the ML on Raspberry Pi with MediaPipe series, where you will learn about the basics of machine learning, along with how you can use Google's newest on-device machine learning tool, MediaPipe, to add useful features to your own Raspberry Pi apps. This series will aim to introduce some general concepts and vocabulary around machine learning, how to create a simple model, and how to implement some common ML tasks, such as hand gesture recognition, audio classification, and object detection, all on the Raspberry Pi. By the end of this series, you should have enough of a foundation in machine learning with MediaPipe to continue learning and making great apps without getting too far off track with all of the math or underlying details. If you are interested in a lot more of the details behind machine learning, I've also included a link in the video description to our TensorFlow zero to hero video series, which is similar enough to MediaPipe for our purposes. So, let's go ahead and start by talking about what machine learning even is. With traditional programming languages, you provide an input and a function, then the program produces an output. So, for example, you might have a function that adds two to any input number. So, one outputs three, eight outputs 10, and 40 outputs 42. With machine learning, you provide a set of known inputs and a set of known outputs, and then the computer tries to figure out what the function is that connects those two. This process is called training, and it's one of the core steps in machine learning. Without getting too far into the details, training involves solving a set of complex problems, including optimizing models to work on relatively restricted hardware, using specific device hardware for acceleration, and ensuring your models work across multiple platforms, which is why we've created MediaPipe as a way to make these challenges a whole lot easier for our developers. Once training is done and your model is ready to go, your next step is implementing that model on your Raspberry Pi. Though, we'll cover that in a lot more detail both later in this video and in later videos through this series. So, just a few moments ago, I mentioned that MediaPipe is a tool for on-device machine learning. But, what does that even mean? As the name implies, on-device machine learning is a subfield of machine learning and is a way to run machine learning inference rather than training directly on an edge device. This includes mobile phones and tablets, IoT devices, and even web pages. Because of the single attribute, developers gain three specific advantages. First, machine learning is able to run quickly using models that have been specifically designed for edge devices. Next, your apps will be able to use machine learning features regardless of whether or not the device has connectivity. For example, when a user or device is in a tunnel or in a rural area. Lastly, because data is never leaving the device, that data is more secure and private. This has opened the door for a variety of new products and features for developers, especially when combined with all of the options and flexibility that you get with IoT hardware like the Raspberry Pi. While discussing these new ML features throughout this series, I'm going to divide them into four separate categories. Natural language processing or essentially text, which are tasks that you might use to translate text, provide answers from a contextual paragraph, or understand some dialogue. Vision, which involves images or videos to recognize content, track objects, or even provide a modified version of visual inputs. These tend to be the most commonly used features and a few IoT use cases in this domain include barcode scanning, item quality inspection, and object sorting. Audio files that can accept input from a microphone or audio file in order to classify sounds, input spoken language, or check the similarity between two separate audio files. And finally, other for those one-off tasks. These could be tasks for content recommendation, tabular classification, or generative content. This list on the screen is also just a subset of what we either currently support or plan to support with MediaPipe. So, be sure to check out the official documentation at developers.google.com/mediapipe to keep up with the latest as we continue to improve. Great. So, what makes MediaPipe unique in the on-device machine learning ecosystem? MediaPipe handles a lot of the monotonous tasks that go along with machine learning, like flow control, meaning you don't need to worry about your app sending data faster than inference can happen, handling the underlying data structures so that you can work with regular objects instead of a series of matrices, or chaining multiple models together to form even larger jobs. MediaPipe also consist of a selection of solutions, such as MediaPipe Tasks, which lets the developers easily deploy ML features in their apps, MediaPipe Model Maker, which helps you create custom models, and then MediaPipe Studio, which lets you try out tasks directly from a browser without needing to write any code. This video series will primarily focus on MediaPipe Tasks as it's the most relevant to IoT development, though it's worth mentioning that MediaPipe Tasks also works with Android, web, and iOS. I will include links to content focused on MediaPipe Model Maker and MediaPipe Studio in the video description for those of you that are interested in learning more about those two tools. Plus, there will be a video later in the series covering both. All right. Now that you know a little more about on-device machine learning, as well as what MediaPipe is, let's go into something a little more exciting. In this case, we're going to make a simple Python program that performs image classification, and I'm going to use a custom model that can detect a small set of animals. For a bit of background, I have a few chickens in my yard, but one thing to know about chickens is that a lot of other animals would love to eat them. In this example, I've created a new model using a set of images that I pulled from Kaggle, which you can find in this video's description. And I'm using that model to detect things like raccoons, foxes, or cats. If I were using this model in a full project, then I might use that detected information to notify me of anything coming around. That way I can know if I need to fix any parts of my chicken coop, or add any additional fencing. So, before you get started, you will need to set up your Raspberry Pi. The most important thing to know is that you must run a 64-bit operating system on the device. In this case, and throughout this series, I'm going to use the standard 64-bit Raspberry Pi OS on a Raspberry Pi 4B. You'll also need a camera hooked up to your Raspberry Pi for this example, as well as any other computer vision examples. Though you can use either the Pi ribbon camera or a USB webcam. The next thing you will need to do is make sure that you have the MediaPipe dependency installed on your Raspberry Pi. You can do that with this command from the terminal. And since this is on-device machine learning, you are going to need your machine learning model stored on your device. There's a variety of ways that you can do this, including using the wget command from the terminal to get a stock model that has been tested already. Though I'm going to simply place my custom model in the same directory as my Python script. If you do want to use a tested default model, we provide a few options from our developer documentation, which you can find in the video description. Now that the housekeeping is done, it's time to create your new Python script to do the actual classification. While I'm only going to cover the most important parts here, you can find an entire example on GitHub, which I'll also link to below. First, there's a couple imports that you'll need at the top of your program. After you have those, you can create a configuration options object for your image classifier. Some of the available properties for these option objects includes the max number of results that you want to receive from the classifier, the minimum confidence score that must be met before a result is returned, and a callback that will receive the results from image classification. In this case, you will use the live stream running mode because this example is going to use the camera to constantly classify against a video stream. Once you have your configuration object made, you can create the image classifier object that will do the majority of the ML work for you. Next, you'll get an image frame from the camera and do some preprocessing on it, including converting that image to the red, green, blue format that the machine learning model requires, as well as create a new MediaPipe image object that will be used for inference. With that all out of the way, you can call the classify async method on the classifier with that MediaPipe image and a timestamp, which will return the classification result to your callback function. One nice thing about this is that because MediaPipe already handles flow control for you, you don't need to worry about sending camera frames faster than they can be processed. If you do happen to send more data than MediaPipe can infer at the moment, MediaPipe will handle dropping the oldest image to keep your processing time down. Finally, this callback will receive a result object, which you can use to do whatever it is that your goals are with your new Raspberry Pi app. The important part to know is the structure for image classification results that you can see here on the screen. This is what you'll use to navigate through the result object to find the information that you need for your app. In this case, I'm just going to display the results on the screen for the most likely seen item that meets the score threshold that I already specified. Here you can see that I'm able to point the camera at a picture of a raccoon and see that it's classified correctly with a 70 to 80% confidence. We're excited to see all the cool things that you make with MediaPipe on the Raspberry Pi. So, let us know in the comments what you've made or what you want to make, and I'll see you in the next video. Thanks.
Original Description
Ready to unlock the power of machine learning on your Raspberry Pi? Join Paul Ruiz, Developer Relations Engineer, as he takes you through the basics of Google’s newest on-device machine learning tool, MediaPipe.
This tutorial will aim to introduce some general concepts and vocabulary around machine learning and teach you how to create a simple model. Plus, how to implement some common ML tasks such as:
- hand gesture recognition
- audio classification
- and object detection all on the Raspberry Pi.
In summary, you'll learn how to build a Python program that performs image classification, a fundamental task in computer vision. We'll break down the concepts step-by-step, ensuring you have a solid understanding without getting too bogged down in the math or underlying details. By the end of this series, you should have enough of a foundation in machine learning with MediaPipe to continue learning and making great apps.
Resources:
Intro to ML (ML Zero to Hero) → https://goo.gle/40u9cAx
MediaPipe → https://goo.gle/3u7sbos
MediaPipe Studio → https://goo.gle/3QpSMEN
MediaPipe Model Maker → https://goo.gle/46404E1
Animals Detection Images Dataset → https://goo.gle/3sub67B
Watch more ML on Raspberry Pi with MediaPipe → https://goo.gle/MPRP
Subscribe to Google for Developers → https://goo.gle/developers
#Ml #PythonImageClassification #ImageClassification #PythonRaspberryPi #RaspberryPiApps #RaspberryPi #MachineLearning #MediaPipe #MediaPipe #Developers #Google
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Google for Developers · Google for Developers · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Developer Journey - Sunnyvale DSC Summit ‘19
Google for Developers
How Google is working with students - Sunnyvale DSC Summit ‘19
Google for Developers
Starting your career in the Cloud - Sunnyvale DSC Summit ‘19
Google for Developers
The Solution Challenge - Sunnyvale DSC Summit ‘19
Google for Developers
Firebase - Sunnyvale DSC Summit ‘19
Google for Developers
Cloud Hero - Sunnyvale DSC Summit ‘19
Google for Developers
Panel discussion - Sunnyvale DSC Summit ‘19
Google for Developers
The art of negotiation - Sunnyvale DSC Summit ‘19
Google for Developers
Courage to care, solve and share - Sunnyvale DSC Summit ‘19
Google for Developers
Version 9 of Angular, Glass Enterprise Edition 2, path to DX deprecation, & more!
Google for Developers
[DEPRECATING] Introducing a new series (Assistant for Developers Pro Tips)
Google for Developers
Detecting memory bugs with HWASan, Bazel 2.1, Next ‘20 session guide, & more!
Google for Developers
Why Podcast.app chose a .app domain name
Google for Developers
Machine Learning Bootcamp Jakarta 2019
Google for Developers
Android Studio 3.6, Android 11 Developer Preview, Kubeflow 1.0, & more!
Google for Developers
[DEPRECATING] Importance of community (Assistant on Air)
Google for Developers
Why the Flutter team switched from .io to a .dev domain name
Google for Developers
3 website-building tips from .dev creators
Google for Developers
Why NimbleDroid chose a .app domain name
Google for Developers
Android Platform Codelab, Bazel 2.2, Maps Android Utility Library v1.0, & more!
Google for Developers
Google for Games Developer Summit: A free, digital experience for game developers
Google for Developers
Inspecting Home Graph (Assistant for Developers Pro Tips)
Google for Developers
Google for Games Developer Summit Keynote
Google for Developers
Stadia Games & Entertainment presents: Keys to a great game pitch (Google Games Dev Summit)
Google for Developers
Empowering game developers with Stadia R&D (Google Games Dev Summit)
Google for Developers
Supercharging discoverability with Stadia (Google Games Dev Summit)
Google for Developers
Stadia Games & Entertainment presents: Creating for content creators (Google Games Dev Summit)
Google for Developers
Bringing Destiny to Stadia: A postmortem (Google Games Dev Summit)
Google for Developers
Live Captioning in Google Slides
Google for Developers
[DEPRECATING] User engagement for the Google Assistant
Google for Developers
TensorFlow Dev Summit ‘20, Google for Games Dev Summit, Cloud AI Platform Pipelines, & much more!
Google for Developers
Top 5 from the TensorFlow Dev Summit 2020
Google for Developers
Developer Student Clubs 2019 Turkey Leads Summit
Google for Developers
Building simpler payment experiences | Google Pay Plugin for Magento 2
Google for Developers
Become A Developer Student Club Lead
Google for Developers
Firebase Kotlin Extensions, ARM apps on the Android Emulator, Angular v9.1, & more!
Google for Developers
Test suite for Smart Home (Assistant for Developers Pro Tips)
Google for Developers
Google Play updates, Bazel 3.0, Business Console for Google Pay, & more!
Google for Developers
How to use error logs (Assistant for Developers Pro Tips)
Google for Developers
Contact Center AI, Android Studio 4.1 Canary 5, TensorFlow QAT API, & more!
Google for Developers
WebView DevTools, Kotlin meets gRPC, Flutter CodePen support, & more! (Episode 200)
Google for Developers
Offline handling for Smart Home (Assistant for Developers Pro Tips)
Google for Developers
Android 11 Dev Preview 3, Google Fonts for Flutter, Shielded VM, & more!
Google for Developers
Machine Learning Foundations: Ep #1 - What is ML?
Google for Developers
Flutter web support updates, BigQuery materialized views, Cloud Spanner emulator, & more!
Google for Developers
Computer vision by building a neural network with TensorFlow | Machine Learning Foundations
Google for Developers
Machine Learning Foundations: Ep #3 - Convolutions and pooling
Google for Developers
Android 11 Beta plans, Flutter 1.17, Dart 2.8, & much more!
Google for Developers
Machine Learning Foundations: Ep #4 - Coding with Convolutional Neural Networks
Google for Developers
Google Developers ML Summit
Google for Developers
Real-world image classification using convolutional neural networks | Machine Learning Foundations
Google for Developers
Adobe XD support for Flutter, Architecture Framework, temporary closures with Places API, & more!
Google for Developers
Machine Learning Foundations: Ep #6 - Convolutional cats and dogs
Google for Developers
Machine Learning Foundations: Ep #7 - Image augmentation and overfitting
Google for Developers
Announcing Firebase Live, Flutter Day, Java 11 on Google Cloud Functions, & more!
Google for Developers
Machine Learning Foundations: Ep #8 - Tokenization for Natural Language Processing
Google for Developers
Android 11 Beta, Google Play Asset Delivery, Firebase Crashlytics SDK, & much more!
Google for Developers
Natural Language Processing: Using sequencing APIs in TensorFlow | Machine Learning Foundations
Google for Developers
Build a sarcasm classifier using NLP and TensorFlow | Machine Learning Foundations
Google for Developers
AR Realism with the ARCore Depth API
Google for Developers
🎓
Tutor Explanation
DeepCamp AI