Mobile App Dev β€Ί On-Device Machine Learning
🧠 Module 03 · Advanced

Give Your App a Pocket Brain

What if your app could recognize a hotdog just by pointing the camera at it? 🌭 Or tell the difference between your cat and your dog instantly? This isn't science fictionβ€”it's On-Device Machine Learning. Let's build an app with its own pocket-sized brain!

πŸƒ Pan's Pro Tip: The Pocket Brain!

Think about it: normally, AI needs a connection to the internet to work. But "On-Device ML" means you download a tiny, super-smart version of that brain directly to your phone. It's lightning fast, super private, and works even in a tunnel or on a plane with no WiFi!

This isn't just a toy. This is the exact same technology that powers incredible features like Face ID on your iPhone, the instant translation in the Google Translate app's camera mode, and the magical filters on Snapchat that know where to put the dog ears. You're learning the building blocks of the future.

Two Ways for AI to Think

☁️ Cloud AI

Phone sends picture to internet β†’ Big computer thinks β†’ Answer comes back.

Slower, needs WiFi.

🧠 Pocket Brain AI

Phone looks at picture β†’ Tiny brain inside the phone thinks β†’ Answer appears instantly.

Super fast, works anywhere!

See It In Action! πŸ€–

Let's see a Pocket Brain do its thing. The AI in this little demo is trained to recognize hundreds of everyday objects. Watch how fast it works!

I see a... keyboard! (98% sure)

πŸ›‘οΈ Safety Check: In a real app, your camera feed is processed right there in your browser or phone and is never sent to a server. It's your data, on your device!

πŸ‘¨β€πŸ‘©β€πŸ‘§ Family Mission: Stump the AI!

Grab a parent and think of three random objects from your room (a toy, a book, a weird sock). Do you think a real AI could guess all three correctly? Try to think of something it might not know!

πŸ€” Pop Quiz: Pocket Brain Superpowers

Which of these is a real superpower of a Pocket Brain? 🦸

It works even on an airplane! ✈️
It needs super-fast internet.
It sends your pictures to a secret server.

Challenge: Train Your Own Pocket Brain!

Seeing is cool, but building is better. Your next mission is to teach an AI to tell the difference between a πŸ‘ (thumbs-up) and a ✊ (fist). We'll use a real tool called Teachable Machine from Google. It’s all done right in your browser, no code needed!

1

Set Up Your Classes

Open Google's Teachable Machine in a new tab. You'll see "Class 1" and "Class 2". Rename them to "Thumbs Up" and "Fist".

2

Give It Examples

For each class, click the "Webcam" button and take at least 20 pictures of your hand in that position. The more pictures you give it, the smarter your AI will get!

3

Train Your Model

Once you have enough pictures for both classes, click the big "Train Model" button. It might take a minute while the AI brain learns from your examples. It's really thinking, so don't switch tabs!

4

Test Your Creation!

The preview window on the right will now show you what your custom AI sees. Hold up a thumbs-up or a fist. Does it guess correctly? You just trained your first Pocket Brain! πŸŽ‰

πŸŽ‰ YOU'RE AN AI TRAINER! πŸŽ‰

You did it! You just taught a computer a new trick. Go find a parent or sibling and show them how your AI can tell the difference between a thumbs-up and a fist. You just built a real Pocket Brain!

πŸ’‘ Bonus Intel: From Toy to Tool

Pro developers train models just like you did, and then they export that model file to use in their apps. In Teachable Machine, you'd click the "Export Model" button. That's how you'd take the brain you just trained and put it inside an app like the one we're about to build in Thunkable!

Your Main Mission: Build a "What's That?" App

Okay, agent. You've seen the magic and you've trained your own model. Time to build a real app. Ready? Let's go! πŸš€

We'll use Thunkable, a powerful block-based app builder, to create an app that uses your phone's camera to identify objects in the real world.

1

Download the Starter Project

We built the user interface for you so we can get straight to the AI fun. Download the starter project file below and upload it to your Thunkable account. (You'll need a parent's help to create a free account if you don't have one.)

Download Starter Project (.aia)
2

Find the AI Blocks

In Thunkable, click the "Blocks" tab to switch from the design view to the code view. On the left side, scroll down the components list and find the Image Recognizer. This is the Pocket Brain component we'll be using!

3

Connect the Camera to the Brain

Your goal is to tell the app: "When the 'Scan' button is clicked, take a picture with the camera, and send that picture to the Image Recognizer for analysis." You'll need to drag and drop the blocks to make them look like this:

4

Display the Answer

After the Image Recognizer gets a result, it gives you two things: a `description` (what it thinks it saw) and a `confidence` (how sure it is). Your final step is to take that green `description` block and put it inside the block that sets the text of your main label. When you're done, test it on your phone using the Thunkable Live app and see your creation come to life!

</> Peek at the JavaScript Code
// A peek at how a pro would do this with code!
// 1. First, we load our pre-trained model.
const model = await mobilenet.load();

// 2. Then, we get the image from the camera.
const image = document.getElementById('webcam-image');

// 3. Finally, we ask the model to predict what it sees.
const predictions = await model.classify(image);
console.log('I see a: ', predictions[0].className);
5

Make It Your Own!

Your app works, but can you make it even cooler? Try one of these missions:

  • Mission 1 (Easy): Add a sound! Find the 'Sound' component and make the app play a 'beep' whenever it recognizes something.
  • Mission 2 (Medium): Make it speak! Use the 'Text-to-Speech' component to make the phone say the `description` out loud.
  • Mission 3 (Hard): Confidence Meter! Can you use an `if/else` block to change the label's color to green if the `confidence` is high (e.g., > 0.75) and yellow if it's low?

πŸ—ΊοΈ Your Path to Pro-Level AI

Ready to see how the pros do it? These are the real toolkits and next steps for building the apps you use every day.

  • Build for iPhone: Explore Apple's CoreML and learn how to put an image classifier into a real iOS app using Swift.
  • Build for Android: Check out Google's TensorFlow Lite Guide to see how AI works in Android apps.
  • Code in the Browser: Try this beginner-friendly CodePen tutorial to build a 'Rock, Paper, Scissors' game using your webcam and TensorFlow.js.