What is TensorFlow?
Tensorflow is an Open source machine learning framework. Its a library for doing Complex Numerical Computation to build machine learning models from scratch. TensorFlow is cross-platform. It runs on nearly everything: GPUs and CPUs—including mobile and embedded platforms.
What is an image classifier?
Image Classifier classifies any given image in categories using trained models. Let's say you train a model by providing 50 images of a dog. Once the model is trained to recognize dogs, you can test it out by providing any given image and the trained model will be able to recognise whether the given image is of a dog or not.
How do I make an image classifier with TensorFlow?
Step 1. SETTING UP THE ENVIRONMENT
Install Python, TensorFlow and download a TensorFlow repository.
-
Python(pip) - https://www.python.org/downloads/
-
TensorFlow -
pip install tensorflow
-
Clone a Tensorflow repo -
git clone https://github.com/googlecodelabs/tensorflow-for-poets-2
Step 2. PREPARING THE DATASET
-
Go inside the tf_filesfolder in the tensorflow-for-poets-2folder.
-
Create a parent folder and inside that create sub folders representing the categories.
-
For example, create a parent folder called people and create sub-folders inside the ‘people’ folder based on categories, namely, men, women and children.
-
Place photos of men, women and children in the respective folders. This will be the dataset and will be used by TensorFlow for training.
Step 3. TRAINING THE MODEL
In the command line, go inside the sensor flow-for-poets-2folder and type the following command.
python -m scripts.retrain--bottleneck_dir=tf_files/bottlenecks --model_dir=tf_files/models/mobilenet_0.50_224 --summaries_dir=tf_files/training_summaries/mobilenet_0.50_224 --output_graph=tf_files/retrained_graph.pb--output_labels=tf_files/retrained_labels.txt--architecture=mobilenet_0.50_224 --image_dir=tf_files/people
//where people is the parent folder with the training set.
This creates graphs and files for image recognition and classification and will be used to categorize any given image based on the training set.
Step 4. TESTING THE MODEL
- Now that the model is trained, its time to test if it works.
- Download a test image of a man or a woman and place it inside the user_datafolder.
- In the command line, go inside the tensorflow-for-poets-2folder and type the following command.
python -m scripts.label_image--graph=tf_files/retrained_graph.pb -- image=user_data/men.jpg//where men.jpgis the test image
OUTPUT
Evaluation time (1-image) 0.25 seconds
men 0.91115780
women 0.08678748