Image classification - ML on Raspberry Pi with MediaPipe Series

Google for Developers · Beginner ·👁️ Computer Vision ·2y ago

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 Developer Journey - Sunnyvale DSC Summit ‘19
Developer Journey - Sunnyvale DSC Summit ‘19
Google for Developers
2 How Google is working with students - Sunnyvale DSC Summit ‘19
How Google is working with students - Sunnyvale DSC Summit ‘19
Google for Developers
3 Starting your career in the Cloud - Sunnyvale DSC Summit ‘19
Starting your career in the Cloud - Sunnyvale DSC Summit ‘19
Google for Developers
4 The Solution Challenge  - Sunnyvale DSC Summit ‘19
The Solution Challenge - Sunnyvale DSC Summit ‘19
Google for Developers
5 Firebase - Sunnyvale DSC Summit ‘19
Firebase - Sunnyvale DSC Summit ‘19
Google for Developers
6 Cloud Hero - Sunnyvale DSC Summit ‘19
Cloud Hero - Sunnyvale DSC Summit ‘19
Google for Developers
7 Panel discussion  - Sunnyvale DSC Summit ‘19
Panel discussion - Sunnyvale DSC Summit ‘19
Google for Developers
8 The art of negotiation - Sunnyvale DSC Summit ‘19
The art of negotiation - Sunnyvale DSC Summit ‘19
Google for Developers
9 Courage to care, solve and share - Sunnyvale DSC Summit ‘19
Courage to care, solve and share - Sunnyvale DSC Summit ‘19
Google for Developers
10 Version 9 of Angular, Glass Enterprise Edition 2, path to DX deprecation, & more!
Version 9 of Angular, Glass Enterprise Edition 2, path to DX deprecation, & more!
Google for Developers
11 [DEPRECATING] Introducing a new series (Assistant for Developers Pro Tips)
[DEPRECATING] Introducing a new series (Assistant for Developers Pro Tips)
Google for Developers
12 Detecting memory bugs with HWASan, Bazel 2.1, Next ‘20 session guide, & more!
Detecting memory bugs with HWASan, Bazel 2.1, Next ‘20 session guide, & more!
Google for Developers
13 Why Podcast.app chose a .app domain name
Why Podcast.app chose a .app domain name
Google for Developers
14 Machine Learning Bootcamp Jakarta 2019
Machine Learning Bootcamp Jakarta 2019
Google for Developers
15 Android Studio 3.6, Android 11 Developer Preview, Kubeflow 1.0, & more!
Android Studio 3.6, Android 11 Developer Preview, Kubeflow 1.0, & more!
Google for Developers
16 [DEPRECATING]  Importance of community (Assistant on Air)
[DEPRECATING] Importance of community (Assistant on Air)
Google for Developers
17 Why the Flutter team switched from .io to a .dev domain name
Why the Flutter team switched from .io to a .dev domain name
Google for Developers
18 3 website-building tips from .dev creators
3 website-building tips from .dev creators
Google for Developers
19 Why NimbleDroid chose a .app domain name
Why NimbleDroid chose a .app domain name
Google for Developers
20 Android Platform Codelab, Bazel 2.2, Maps Android Utility Library v1.0, & more!
Android Platform Codelab, Bazel 2.2, Maps Android Utility Library v1.0, & more!
Google for Developers
21 Google for Games Developer Summit: A free, digital experience for game developers
Google for Games Developer Summit: A free, digital experience for game developers
Google for Developers
22 Inspecting Home Graph (Assistant for Developers Pro Tips)
Inspecting Home Graph (Assistant for Developers Pro Tips)
Google for Developers
23 Google for Games Developer Summit Keynote
Google for Games Developer Summit Keynote
Google for Developers
24 Stadia Games & Entertainment presents: Keys to a great game pitch (Google Games Dev Summit)
Stadia Games & Entertainment presents: Keys to a great game pitch (Google Games Dev Summit)
Google for Developers
25 Empowering game developers with Stadia R&D (Google Games Dev Summit)
Empowering game developers with Stadia R&D (Google Games Dev Summit)
Google for Developers
26 Supercharging discoverability with Stadia (Google Games Dev Summit)
Supercharging discoverability with Stadia (Google Games Dev Summit)
Google for Developers
27 Stadia Games & Entertainment presents: Creating for content creators (Google Games Dev Summit)
Stadia Games & Entertainment presents: Creating for content creators (Google Games Dev Summit)
Google for Developers
28 Bringing Destiny to Stadia: A postmortem (Google Games Dev Summit)
Bringing Destiny to Stadia: A postmortem (Google Games Dev Summit)
Google for Developers
29 Live Captioning in Google Slides
Live Captioning in Google Slides
Google for Developers
30 [DEPRECATING]  User engagement for the Google Assistant
[DEPRECATING] User engagement for the Google Assistant
Google for Developers
31 TensorFlow Dev Summit ‘20, Google for Games Dev Summit, Cloud AI Platform Pipelines, & much more!
TensorFlow Dev Summit ‘20, Google for Games Dev Summit, Cloud AI Platform Pipelines, & much more!
Google for Developers
32 Top 5 from the TensorFlow Dev Summit 2020
Top 5 from the TensorFlow Dev Summit 2020
Google for Developers
33 Developer Student Clubs 2019 Turkey Leads Summit
Developer Student Clubs 2019 Turkey Leads Summit
Google for Developers
34 Building simpler payment experiences | Google Pay Plugin for Magento 2
Building simpler payment experiences | Google Pay Plugin for Magento 2
Google for Developers
35 Become A Developer Student Club Lead
Become A Developer Student Club Lead
Google for Developers
36 Firebase Kotlin Extensions, ARM apps on the Android Emulator, Angular v9.1, & more!
Firebase Kotlin Extensions, ARM apps on the Android Emulator, Angular v9.1, & more!
Google for Developers
37 Test suite for Smart Home (Assistant for Developers Pro Tips)
Test suite for Smart Home (Assistant for Developers Pro Tips)
Google for Developers
38 Google Play updates, Bazel 3.0, Business Console for Google Pay, & more!
Google Play updates, Bazel 3.0, Business Console for Google Pay, & more!
Google for Developers
39 How to use error logs (Assistant for Developers Pro Tips)
How to use error logs (Assistant for Developers Pro Tips)
Google for Developers
40 Contact Center AI, Android Studio 4.1 Canary 5, TensorFlow QAT API, & more!
Contact Center AI, Android Studio 4.1 Canary 5, TensorFlow QAT API, & more!
Google for Developers
41 WebView DevTools, Kotlin meets gRPC, Flutter CodePen support, & more! (Episode 200)
WebView DevTools, Kotlin meets gRPC, Flutter CodePen support, & more! (Episode 200)
Google for Developers
42 Offline handling for Smart Home (Assistant for Developers Pro Tips)
Offline handling for Smart Home (Assistant for Developers Pro Tips)
Google for Developers
43 Android 11 Dev Preview 3, Google Fonts for Flutter, Shielded VM, & more!
Android 11 Dev Preview 3, Google Fonts for Flutter, Shielded VM, & more!
Google for Developers
44 Machine Learning Foundations: Ep #1 - What is ML?
Machine Learning Foundations: Ep #1 - What is ML?
Google for Developers
45 Flutter web support updates, BigQuery materialized views, Cloud Spanner emulator, & more!
Flutter web support updates, BigQuery materialized views, Cloud Spanner emulator, & more!
Google for Developers
46 Computer vision by building a neural network with TensorFlow | Machine Learning Foundations
Computer vision by building a neural network with TensorFlow | Machine Learning Foundations
Google for Developers
47 Machine Learning Foundations: Ep #3 - Convolutions and pooling
Machine Learning Foundations: Ep #3 - Convolutions and pooling
Google for Developers
48 Android 11 Beta plans, Flutter 1.17, Dart 2.8, & much more!
Android 11 Beta plans, Flutter 1.17, Dart 2.8, & much more!
Google for Developers
49 Machine Learning Foundations: Ep #4 - Coding with Convolutional Neural Networks
Machine Learning Foundations: Ep #4 - Coding with Convolutional Neural Networks
Google for Developers
50 Google Developers ML Summit
Google Developers ML Summit
Google for Developers
51 Real-world image classification using convolutional neural networks | Machine Learning Foundations
Real-world image classification using convolutional neural networks | Machine Learning Foundations
Google for Developers
52 Adobe XD support for Flutter, Architecture Framework, temporary closures with Places API, & more!
Adobe XD support for Flutter, Architecture Framework, temporary closures with Places API, & more!
Google for Developers
53 Machine Learning Foundations: Ep #6 - Convolutional cats and dogs
Machine Learning Foundations: Ep #6 - Convolutional cats and dogs
Google for Developers
54 Machine Learning Foundations: Ep #7 - Image augmentation and overfitting
Machine Learning Foundations: Ep #7 - Image augmentation and overfitting
Google for Developers
55 Announcing Firebase Live, Flutter Day, Java 11 on Google Cloud Functions, & more!
Announcing Firebase Live, Flutter Day, Java 11 on Google Cloud Functions, & more!
Google for Developers
56 Machine Learning Foundations: Ep #8 - Tokenization for Natural Language Processing
Machine Learning Foundations: Ep #8 - Tokenization for Natural Language Processing
Google for Developers
57 Android 11 Beta, Google Play Asset Delivery, Firebase Crashlytics SDK, & much more!
Android 11 Beta, Google Play Asset Delivery, Firebase Crashlytics SDK, & much more!
Google for Developers
58 Natural Language Processing: Using sequencing APIs in TensorFlow | Machine Learning Foundations
Natural Language Processing: Using sequencing APIs in TensorFlow | Machine Learning Foundations
Google for Developers
59 Build a sarcasm classifier using NLP and TensorFlow | Machine Learning Foundations
Build a sarcasm classifier using NLP and TensorFlow | Machine Learning Foundations
Google for Developers
60 AR Realism with the ARCore Depth API
AR Realism with the ARCore Depth API
Google for Developers

Related Reads

Up next
9-Phase Computer Vision Roadmap 2026 | AI & Deep Learning | #shorts
SCALER
Watch →