Build a TensorFlow Image Classifier in 5 Min
Key Takeaways
This video demonstrates how to build a TensorFlow image classifier in 5 minutes to detect Darth Vader images using transfer learning and a pre-trained Inception model. The process involves installing Docker, downloading the TensorFlow Docker image, preparing the image dataset, linking the images to the Docker container, downloading the training script, retraining the Inception classifier, and writing a script to use the retrained classifier for image detection.
Full Transcript
hello world it's SJ in this episode we're going to build an image classifier using tensorflow in 30 lines of python and I don't mean a classifier that can detect handwritten digits or Iris Flowers I'm talking literally anything you want you'll be able to train this thing to classify chocolate if you want it [Music] h the possibilities are endless there's so many industries that can be disrupted by just this simple solution a Japanese cucumber farmer built a machine to detect whether each of his cucumbers was one of nine different types using this thing let's say we want to build a sage classifier if we think about this problem in the traditional programming Paradigm we want to handcraft a bunch of features maybe we could do some Edge detection to save the shape of my hair or use a color histogram to save the color of my teeth the problem with that is there's so much variance in sjas my hair is alive seriously it's never the same this is where a comp evolutional neural networks come into play they're essentially a black box that constructs features that we would otherwise have to handcraft and these abstract features they create from training are so generalized that they account for variance if we wanted to train a CNN ourselves we need a lot of computing power and a lot of time both of which we don't have I don't even have time to do my dishes sorry remits that's why we want to use a pre-trained CNN model called Inception Inception was trained by Google on 100K images with a thousand categories our use case in this video will be classifying Darth Vader pictures but Inception wasn't trained on Vader so we're going to perform a process called transfer learning that means applying the learnings from a previous training session to a new training session if we look at the Inception model we can see that when we feed in an image as an input at each layer it will perform a series of operations on that data until it outputs a label and classification percentage each layer is a different set of abstractions in the first layers it's basically taught itself Edge detection then shape detection in the middle layers and they get increasingly more abstract up until the end if we look at the last few layers these are the highest level detectors for whole objects for transfer learning we basically just want to retrain that last layer on features of Darth Vader so it can add a representation of him to its repository of knowledge so this is going to be a seven-step process and we're going to go through each step in order sound good step one is to install Docker which is a tool for creating a virtual container on your machine for running apps the benefit of Docker is you don't have to install any dependencies on your machine so we'll eventually download a Docker image that has all the necessary dependencies for tensor flow built in just download the docker toolbox go through the installation process and then you can launch your Docker container anytime easily by double clicking the docker quickart terminal cool now that we have Docker open that brings us to step two installing the tensorflow docker image by pasing in this line it'll take a few minutes then once it's installed we'll move on to step three downloading our image data set to our local machine we'll stop Docker with contr d then create a directory called TF file Star Wars in our home directory locally we want to put a folder labeled Darth Vader that contains a couple hundred Vader p Pi in here there's this dope Chrome extension I found called faton batch download image that bulk downloads all the images from your Google image search results just go to Google image search type in Darth Vader and start downloading all of those images once we've got them we'll just drag that folder into our TF file Star Wars folder that brings us to step four now that we have our images in our TF files directory we want to link them to our Docker container with this command boom all Linked UP step five is to download the training script via git just CD into the tensorflow directory then run git hole this code will allow us to retrain the Inception classifier with a newly linked Darth Vader image data set step six is the actual retraining part the bottleneck directory will be used to Cache the outputs of the lower layers on disk so they don't have to repeatedly be recalculated we'll run this example for 500 iterations the next flag asks where to store our trained model our output craft which we can later view in tensor board our output labels which will be the same as our training data folder name and the image directory where we stored our Vader images let's go ahead and run the script right from terminal it'll take about 30 minutes so to train our classifier so do something productive the script should output a training accuracy somewhere between 85 and 99% when it's done and this brings us to our final step we want to write a script that will use our new retrain classifier to detect if a novel image contains Darth Vader we'll write the script ourselves first things first we'll import tensorflow then we'll want to create a variable to store the user input image path we'll create another variable to store the data from that image and one more to load the label of that image from the label file next we'll want to grab our model from the saved retrained graph file store it in the graph def variable and parse it now that we have our image and model ready it's time to make our prediction by feeding the image data into our retrained model to get our prediction output in order to do this we'll create a tensorflow session this will give us an environment to perform operations on our tensor data in the first thing we'll do in a session is get our softmax function tensor from the last layer of our model the softmax function is used in the final layer to map input data into probabilities of an expected output we will execute our softmax tensor function on our input image data via the session run function it will output our predictions as an array we'll next want to sort our prediction labels in order of confidence and lastly for every prediction we have we can get the predicted label and the score and print it out to terminal let's take the script and run it on one of our Vader pictures the result is pretty good tensorflow makes it much easier to classify an image and I've got a challenge for you guys on this episode The Challenge is to create a classifier that you think would be a useful tool for scientists to have it can be any field of science you'd like upload your code to GitHub and in the read me write up a few sentences on how a scientist would use this post a repository in the comment section and I'll judge them based on utility and accuracy the winner gets a shout out from me two videos from now so in 2 weeks and I'll also send you a free signed copy of my book decentralized applications for now I've got to go not buy the iPhone 7 so thanks for watching
Original Description
In this episode we're going to train our own image classifier to detect Darth Vader images.
The code for this repository is here:
https://github.com/llSourcell/tensorflow_image_classifier
I created a Slack channel for us, sign up here:
https://wizards.herokuapp.com/
The Challenge:
The challenge for this episode is to create your own Image Classifier that would be a useful tool for scientists. Just post a clone of this repo that includes your retrained Inception Model (label it output_graph.pb). If it's too big for GitHub, just upload it to DropBox and post the link in your GitHub README. I'm going to judge all of them and the winner gets a shoutout from me in a future video, as well as a signed copy of my book 'Decentralized Applications'.
This CodeLab by Google is super useful in learning this stuff:
https://codelabs.developers.google.com/codelabs/tensorflow-for-poets/?utm_campaign=chrome_series_machinelearning_063016&utm_source=gdev&utm_medium=yt-desc#0
This Tutorial by Google is also very useful:
https://www.tensorflow.org/versions/r0.9/how_tos/image_retraining/index.html
This is a good informational video:
https://www.youtube.com/watch?v=VpDonQAKtE4
Really deep dive video on CNNs:
https://www.youtube.com/watch?v=FmpDIaiMIeA
I love you guys! Thanks for watching my videos and if you've found any of them useful I'd love your support on Patreon:
https://www.patreon.com/user?u=3191693
Much more to come so please SUBSCRIBE, LIKE, and COMMENT! :)
edit: Credit to Clarifai for the first conv net diagram in the video
Follow me:
Twitter: https://twitter.com/sirajraval
Facebook: https://www.facebook.com/sirajology Instagram: https://www.instagram.com/sirajraval/ Instagram: https://www.instagram.com/sirajraval/
Signup for my newsletter for exciting updates in the field of AI:
https://goo.gl/FZzJ5w
Hit the Join button above to sign up to become a member of my channel for access to exclusive content! Join my AI community: http://chatgptschool.io/ Sign up for
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Siraj Raval · Siraj Raval · 34 of 60
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
▶
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
What is Bitcoin?
Siraj Raval
5 Ways to Use Bitcoin
Siraj Raval
BTC Fever - Siraj [Music Video]
Siraj Raval
5 Reasons to Build Decentralized Apps
Siraj Raval
The Interplanetary File System
Siraj Raval
How to Build a Dapp in 3 min
Siraj Raval
Life Before Smartphones
Siraj Raval
4 Ways to Use Smart Contracts
Siraj Raval
3 Dapps You HAVE to See
Siraj Raval
Char's Life as a BitTorrent Engineer
Siraj Raval
4 Reasons AlphaGo is a Huge Deal
Siraj Raval
Build a Neural Net in 4 Minutes
Siraj Raval
Sentiment Analysis in 4 Minutes
Siraj Raval
The Hackathon Life
Siraj Raval
Your First ML App - Machine Learning for Hackers #1
Siraj Raval
Build an AI Composer - Machine Learning for Hackers #2
Siraj Raval
Build a Game AI - Machine Learning for Hackers #3
Siraj Raval
Build a Movie Recommender - Machine Learning for Hackers #4
Siraj Raval
Build an AI Artist - Machine Learning for Hackers #5
Siraj Raval
Build a Chatbot - ML for Hackers #6
Siraj Raval
Build an AI Reader - Machine Learning for Hackers #7
Siraj Raval
Build an AI Writer - Machine Learning for Hackers #8
Siraj Raval
Build a Chatbot w/ an API - ML for Hackers #9
Siraj Raval
One-Shot Learning - Fresh Machine Learning #1
Siraj Raval
Generative Adversarial Nets - Fresh Machine Learning #2
Siraj Raval
Tone Analysis - Fresh Machine Learning #3
Siraj Raval
Generate Rap Lyrics - Fresh Machine Learning #4
Siraj Raval
Build an Autoencoder in 5 Min - Fresh Machine Learning #5
Siraj Raval
Build a Self Driving Car in 5 Min - Fresh Machine Learning #6
Siraj Raval
Build an Antivirus in 5 Min - Fresh Machine Learning #7
Siraj Raval
TensorFlow in 5 Minutes (tutorial)
Siraj Raval
Build a Recurrent Neural Net in 5 Min
Siraj Raval
Build a Simulation in 5 Min
Siraj Raval
Build a TensorFlow Image Classifier in 5 Min
Siraj Raval
Tensorboard Explained in 5 Min
Siraj Raval
Generate Music in TensorFlow
Siraj Raval
Build a Game Bot (LIVE)
Siraj Raval
Deep Learning Frameworks Compared
Siraj Raval
Introduction - Learn Python for Data Science #1
Siraj Raval
Build a Neural Network (LIVE)
Siraj Raval
Twitter Sentiment Analysis - Learn Python for Data Science #2
Siraj Raval
Recommendation Systems - Learn Python for Data Science #3
Siraj Raval
Predicting Stock Prices - Learn Python for Data Science #4
Siraj Raval
Pong Neural Network (LIVE)
Siraj Raval
Deep Dream in TensorFlow - Learn Python for Data Science #5
Siraj Raval
Visualizing Data with D3.js (LIVE)
Siraj Raval
Genetic Algorithms - Learn Python for Data Science #6
Siraj Raval
Enter Siraj [Music Video]
Siraj Raval
Build a Web Scraper (LIVE)
Siraj Raval
Why is P vs NP Important?
Siraj Raval
How to Make a Neural Network (LIVE)
Siraj Raval
How to Make an Amazing Tensorflow Chatbot Easily
Siraj Raval
How to Make an Amazing Video Game Bot Easily
Siraj Raval
How to Make a Tensorflow Neural Network (LIVE)
Siraj Raval
How to Make a Simple Tensorflow Speech Recognizer
Siraj Raval
Joel Shor - Really Quick Questions with an Awesome Google Engineer
Siraj Raval
How to Make a Path Planning Algorithm Easily (LIVE)
Siraj Raval
The Best Way to Prepare a Dataset Easily
Siraj Raval
Catherine Olsson - Really Quick Questions with an OpenAI Engineer
Siraj Raval
How to Make a Tic Tac Toe Neural Network Easily (LIVE)
Siraj Raval
More on: CV Basics
View skill →Related Reads
📰
📰
📰
📰
AI Tools that Actually Pay You Back: A Developer's Guide to Monetizing AI
Dev.to AI
Creativity AI #82: Anthropic maps how people really use AI, designers shift from making to mending…
Medium · AI
The End of YouTube Search? Why AI Creator Discovery Is Becoming the Smarter Way to Learn in 2026
Medium · AI
Why AI Tools Are Becoming Essential for Modern Professionals
Medium · AI
🎓
Tutor Explanation
DeepCamp AI