Building a Deep Learning Image Classifier | Learning Intelligence 43

Daniel Bourke and Josh build a banana classifier using TensorFlow and Python, scraping Google Images for training data and achieving 78-99% accuracy on test images. A live demo shows the model correctly identifying his co-founder Zenith as "not banana" with 96% confidence, though the banana itself scores lower, revealing room for improvement.
Chapters
Shh, we're gonna be very quiet. There's a wild animal behind the camera. Hey, how are you? Look at this, it's so friendly. What's going on, team? Welcome to Learning Intelligence 43. Shh, there's another wild animal behind the camera. Oh, it's a battle. Hey, hey, it's okay, it's okay. What's going on, Josh? What's up, brother? You having some food? Quiet, mum's asleep. Oh, everyone's asleep in this house. What do you want to do today? I don't know, I want to eat the soup first. You want that soup? And you want to build a model? Yeah, yeah. Banana, not banana. So Josh and I— Josh has been learning iOS. What is it, Core ML? Yeah. Coramel and ARKit. Look at that, a little Barbie. And so today we want to build a, like, have you seen the app Hot Dog Not Hot Dog? Let's start with a hot dog. We want to build a similar one, but banana not banana, because we want to build a project to do with nutrition education and use an iPhone with Coramel and whatnot. So we're going to start, actually, we don't even have any bananas in the house. We'll figure it out. I think we're going to get some images from Google Images. I'm going to build the image classification model. Josh is going to work on integrating that into iOS. So that's today's project. It's going to be fun! You excited, bro? How's that soup? It's pretty hot, eh? It's pretty hot? Yeah. I've got to eat too now. I only need one dish. Okay Google, 45-minute timer. Okay, 45 minutes starting now. Oh boy, am I ready! Same meal as always, nice and simple, eggs and greens. I'm gonna eat this while the chicken cooks. And then get into some study. And I prepare all my food in big batches, so that way I'm not always cooking. I love to cook, but it does take up a fair bit of time, so I want to make sure if I want to study and I want to eat, I can come up, heat up a meal. It's going to be a good, high-quality, nutritious meal to fuel me for the rest of the knowledge gains. That was delicious. Let's do some studying. Time to build us a model. The chicken is still on. Okay Google, stop the timer. I was so excited to get back into studying, I almost forgot about the chicken I had in the oven. Good thing we got Uncle Goog on the help. Uncle Goog? Aunty Goog? What do you call it? Whatever. Oh yeah! Foggy. Man! All right, food's done. Breakfast's done. Meal prep's done. It's time to build a food model, or a, yeah, food classifier model. Josh, what are you doing? You're gaming, man. Playing some games. All right, I'll get our model done. First things first I like to do with any problem is spend a little bit of time planning it out. So I'm gonna, gonna do at least one Pomodoro, aka 25 minutes of un-inno— uninterrupted time of working out how best to approach it, and then I'll report back. Alexa, 25-minute timer. 25 minutes starting now. Alexa, stop the timer. All right, so I found some pretty good guides online, especially this video, Using Google Images to Gather Deep Learning Training Data. So essentially, that's what I need to do first to create banana, not banana. I'm looping through Google. Have a look at this. To get all of these images of bananas to train my model. Ah, we got a bunch of errors. I need to fix this. Check this out. All these errors. Error, error, error, error, error. So what I'm trying to do is run a script to download me images from Google, and right now it's not working, but we will fix it. You hear that? My puppy's going crazy. We better get him. Oi, oi, oi, oi! What are you two doing? Hey, hey, hey! Inside, inside, inside. Come on. Come on, good girls, good girls, good girls. They've gone rogue. What have you been up to? Absolutely drifting, drifting, drifting. Come on, come on, pardon me, inside, inside, inside. No, absolutely no control. I've lost it. Back to code. It's working! Look at all these images of bananas coming up. It's just filling up my desktop with, with images of bananas. Well, not my desktop, but a folder on my desktop. See, just slowly populating with images of bananas. This is going to be our training dataset. This, this guide is actually very, very cool. If you want to learn how to do some deep learning with computer vision, check out this website. It's in the description, by the way. Back to it. Check it out, check it out, check it out, check it out. What's happening here? Our model's training. Oh yeah, we followed through the tutorial here. It's actually one of the best tutorials I've ever seen. Check it out, I can't stop speaking highly enough of it. Next is to write a test network. So this is training the network here. We're going to test the network to see how good it is, but the ultimate test will be taking a photo of a banana, a random one that we find, and then running it against the network and seeing if it's a banana, not a banana. We might compare it to Zenith. Are you a banana? No. No? See, hopefully the model predicts Zenith as not being a banana. All right, we've got a trained model on banana, not banana. We've got a test network, but we need some images of bananas in the ultimate showdown. Zenith's not here. As you can see, my co-founder's working very hard. We're gonna go to gym, get a workout in, and then come home for the ultimate showdown. And there's a supermarket near gym, so we'll get some bananas and really test this model to see if it actually works with real-life banana pictures, not just Google Images. Workout's finished, feeling real good. Now it's time to get some bananas. Let's find them. Here we go. I wonder if these will work. These will do. I like bananas. So I'm going to get heaps. Actually, I think I need a few more things, so I'm not going to do that whole thing in front of your face. Daniel Bourke, select from these food items or look up ice cream. Thank you for shopping with the push. Bananas acquired. All right, now the ultimate challenge begins when we get home. Time to test the model. Banana vs. Zenith. Oh, Zenith! Oh wait, Zenith isn't here, so we're gonna have some dinner. I'm gonna make sure he's coming home because I really want to test this banana vs. Zenith. Hey Siri, text Zenith, are you coming home tonight? Question mark. Your message to Zenith Rapley says Are you coming home tonight? I'll send it. He better be. Now we go heat up one of the meals I cooked today because it's all prepped and ready to go. Get these for safekeeping. What are those, Mum? Did you get some bananas today? Yes, I got plenty of nanas now. Stocked up. Keep those safe. Meal time. You know what, guys? It's nearly midnight. I know Zenith's getting in here. The door! Is that— is that you? Can we— can we do Zenith's first banana? We gotta do it. You ready to train the model? Yeah. Yeah, you got me excited. All right, we need to get a photo of you and we need to go get a banana. We've got the banana. See the resemblance? Look at that. Ring ring ring, the banana phone. Alright, I need to get a photo of you and a photo of this. Just for the audience. We're not cheating here. We got Zenith vs banana. First we'll do banana dot— is it PNG? Dot JPEG. Alright, we're running. This is banana. How's the model gonna go using TensorFlow backend? Not banana! Daniel. 99 points. 99 points? 96.28% not banana. You're kidding me! Are you kidding me? I swear to God if it says I'm a banana. Alright, now we have— now, alright, that's one fail for today. Let's get in Zenith. What are you hoping for, Zenith? That I'm not a banana. This is the one that counts. This is the moment of truth. Yeah. Alright? We can fix that banana image, but we need to make sure that Zenith is not a banana. Alexa, play some dramatic music. I couldn't find any dramatic songs. You have one job, Alexa, one job! Alexa, play a dramatic song playlist. I can't see the playlist dramatic song. Hopefully our model works a bit better than Alexa. Alright, this is the moment of truth. We're going in, Zenith.jpg. Alexa, play Temperature by Sean Paul. Temperature. It's not a banana! In a high, high percent. It thinks I'm more like a banana than the banana is. That's right, you're not a banana. You're not a banana. Alexa, stop. Alexa, don't wanna stop, bro. Alexa, stop. Everything's going wrong. When Alexa playing a banger like Sean Paul's Temperature, she ain't stopping for no one. Apparently this is not a banana, but I did, I did get a backup after many trials, many fails. Banana! You got it! With only a 78.75% accuracy, but there we go, ladies and gentlemen. Zenith is not a banana, and that is a banana. Leave a comment below on how we can improve our deep learning network, because it's not that good at the moment, but we got there. Positive results all around. Zenith, sign us out since you're not a banana. This is it from the Daniel Bourke Show, and keep learning!
More from Daniel

Small Language Models (SLMs) Are the Future: Fine-Tuning AI That Runs on Your iPhone

Introducing Sunny - A MedGemma-Powered Skin Health Tracking App (Kaggle Competition Entry)

Benchmarking: NVIDIA DGX Spark & NVIDIA RTX 4090 | Part 4 - Comparing the results

Benchmarking: NVIDIA DGX Spark & NVIDIA RTX 4090 | Part 3 - Running LLMs on the RTX 4090

Benchmarking: NVIDIA DGX Spark & NVIDIA RTX 4090 | Part 2 - Formalizing the tests

Benchmarking: NVIDIA DGX Spark & NVIDIA RTX 4090 | Part 1 - Creating a series of tests

Local Multimodal RAG on the NVIDIA DGX Spark | Part 4 - Publishing our demo to Hugging Face

Local Multimodal RAG on the NVIDIA DGX Spark | Part 3 - Putting it all together


