Image Classifier using TFLearn
Let’s us go through the example below to understand how we implement CNN in TensorFlow.
The code below imports CIFAR-10 datasets with 32X32 color images in 10 classes. CIFAR-10 datasets have 60,000 images with 6,000 images per class. There are 50000 training images and 10000 test images.
CIFAR-10 has each image in 32X32 RGB channels and has 10 labels.
Let us start building an image classifier (Object Detector) by using CNN architecture.
Load Data : CIFAR-10 dataset is loaded and divided into training and test datasets
Preprocess Data: Making data usable for modeling
Reshaping Data and converting data type to float32
Normalizing Data
One-hot encoding: Representation of categorical variables as binary vectors and then Building the model architecture
Our network structure is as below:
1. Convolutional input layer, 32 feature maps with a size of 5 X 5, activation function, ELU
2. Max Pool layer with size 2 X 2
3. Convolutional layer, 32 feature maps with a size of 3 X 3, activation function ReLU.
4. Max Pool layer with size 2 X 2
5. Dropout is set to 30%
6. Convolutional layer, 64 feature maps with a size of 3 X 3, activation function ELU.
7. Max Pool layer with size 2 X 2
8. Fully connected layer with 512 units and activation function is sigmoid.
9. Dropout is set to 30%
10. Fully connected output layer with 10 units and activation function is soft-max.
Fitting the model
Here we fit the model by using training datasets by taking the batch size of 1000. It takes first 1000 instances/rows (from 1st to 1000th) from the training dataset and trains network. Then it takes second 1000 instances (from 1001st to 2000th) for training network again. In this way, we propagate all instances through the networks. One epoch means one forward pass and one backward pass of all the training examples. It takes some iterations to complete one epoch.
Making Prediction for test data
Hye guys! Don't feel disheartened after seeing poor accuracy. Given that we have huge pixels) and multi-class, we need to have more number of layers with regularization. TO improve the accuracy, we can use transfer learning which we shall learn in next article. In the transfer learning, we take advantage of pre-trained models
CIFAR-10 class: [airplane, automobile, bird, cat, deer, dog, frog, horse, ship, and truck]
It means the model predicts the bird class.
In the same way, we can use CIFAR-100 datasets then we can be able to detect any object out of 100 specified classes in CIFAR-100 dataset.
Hope you have enjoyed learning of “tflearn” in building an object detector.