Let's build an image classifier with TensorFlow and Python!
--
Welcome back! TensorFlow is one of the best packages for machine learning with Python, so let’s develop another ML project using this programming language! In this specific project, we’ll be developing out an image classifier with TensorFlow! Now, luckily for us the TensorFlow team has already coded out this project and hosted it on Google Colab, so make sure to check out the link below to run this project within your browser:
With that long introduction out of the way, let’s get to coding!
The Code
Starting off, we want to make sure we have TensorFlow and MatPlotLib installed on our machine, so be sure to install those within your environment (unless you're running this in Google Colab). Next up, we want to import these packages as the following:
import tensorflow as tfimport tensorflow_hub as hubimport requestsfrom PIL import Imagefrom io import BytesIOimport matplotlib.pyplot as pltimport numpy as np
Awesome! Now the next part is easily done within the Google Colab environment (so be sure to have that opened to follow along). Essentially, Google has several model’s that we can choose from, so you want to choose a model from the drop down (in this specific case we’ll be using the default one):
Awesome, now we get to choose an input image from the right side of the panel (if needed, you can always hard code your input). At this point, we’ll be bringing in some default images from Wikimedia to get some sample images easily: