oluyede Segun (jr)
5 min readAug 24, 2020

COMPARING KERAS DEEP-LEARNING IMAGE CLASSIFICATION AND TRANSFER LEARNING(IBM WATSON CLOUD) USING APPLE AND BANANA IMAGES.

  1. INTRODUCTION

What is TRANSFER LEARNING:

Transfer learning is a machine learning method where a model developed for a task is reused as the starting point for a model on a second task.

It is a popular approach in deep learning where pre-trained models are used as the starting point on computer vision and natural language processing tasks given the vast compute and time resources required to develop neural network models on these problems and from the huge jumps in skill that they provide on related problems.

examples include: VGG16, Microsoft ResNet Model…

Read more: https://machinelearningmastery.com/transfer-learning-for-deep-learning/

What is KERAS IMAGE CLASSIFICATION?

KERAS: Keras is an open-source neural-network library written in Python. It is capable of running on top of TensorFlow. Commonly used for deep learning.

Image classification is a supervised learning problem: define a set of target classes (objects to identify in images), and train a model to recognize them using labeled example photos.

PROJECT GOAL : To differentiate between training a deep neural network model from scratch with keras versus using a transfer learning model like IBM (watson) VisualRecognition.

1.1 Python Libraries needed for keras image classification :

KERAS,NUMPY, MATPLOTLIB/OPENCV, OS

img 1 : import libraries for keras image classification

1.2 Load path to dataset on local computer OR google COLABS

Using python OS library we can access our train and test datasets on local computer.

I used 130 images for train dataset, 65 apple images and 65 banana images.

And 30 images for the test dataset.

img1.1 Loading train and test data with python
img1.2 images directory on laptop

1.3 Load your generators ,in order to generate your dataset and convert to machine understandable arrays , we will use the keras image generator for this.

Image data augmentation is a technique that can be used to artificially expand the size of a training dataset by creating modified versions of images in the dataset. … The Keras deep learning neural network library provides the capability to fit models using image data augmentation via the ImageDataGenerator class.

the Keras ImageDataGenerator class actually works by:

  1. Accepting a batch of images used for training.
  2. Taking this batch and applying a series of random transformations to each image in the batch (including random rotation, resizing, shearing, etc.).
  3. Replacing the original batch with the new, randomly transformed batch.

Read more: https://www.pyimagesearch.com/2019/07/08/keras-imagedatagenerator-and-data-augmentation/

We will use Train Genenerator is for the training dataset and Test Generator is for the test or validate dataset

img 1.3 keras image generator in python

1.4 Plot images with matplotlib

img 1.4 : plot images

1.5 Define keras deep neural network layer for training

img1.5 keras deep learning training

Also state the training parameters like accuracy and number of epochs, and validate data on test dataset containing images, and save the model

img1.6 training parameters and saving model

1.6 OUTPUT of training:

Accuracy on train dataset = 0.9286

Accuracy on test dataset = 0.9189

img1.7 Output of training after 5 epochs.

1.7 predict on an external image

It correctly predicted 1 for apple, and 0 for banana

img1.8 predict an external image with just ttrained model

2.TRANSFER LEARNING WITH PRETRAINED MODEL ON IBM WATSON CLOUD

2.1 i built a custom classifier using ibm cloud gui ,

Visit link : https://www.ibm.com/cloud/watson-visual-recognition.

On custom classifier, classify Image, click on create model

img2.1 Custom Image classifier on ibm cloud

2.2 Create an apple and banana class ,and add 10 images each to the classes

so we have a total of 20 images for the dataset, and click train at the top right corner

img2.2 apple and banana class on ibm cloud

2.2 Using the default custom model i built on ibm watson gui to classify cat and dog images

IMPORT REQUIRED LIBRARIES AND ACCESS YOUR IBM WATSON ACCOUNT THROUGH YOUR KEY, AND PASSWORD WITH PYTHON.

PYTHON LIBRARIES: watson_developer_cloud (VisualRecognitionV3), Json, cv2, matplotlib

img2.3 import libraries for the custom classifier i built on ibm cloud

2.3 Test custom classifiers on two images

img 2.4 test the default custom classifier on images

2.4 OUTPUT OF FIRST IMAGE

img 2.5 prediction on banana image

2.5 OUTPUT OF SECOND IMAGE

img 2.6 prediction on apple image

2.6 It accurately predicted the two images with high confidence level

2.7 (optional) you can train a default custom classifier using ibm api , rather than the ibm cloud gui.

img 2.7 creating a custom classifer with ibm api instead of ibm gui.

3 CONCLUSION

We now see that ibm watson pretrained models are more faster to use , and requires less coding also needs no hardware requirements, while;

Keras training requires the technical know how of libraries like keras, OS, numpy opencv/matplotlib(optional), and need a laptop with enough RAM, or use google COLABS.

So the choice depends on the user.

THANKS!.

WRITER: OLUYEDE SEGUN . A(jnr)

Explanatory Notebook and dataset: https://github.com/juniorboycoder/KERAS-IMAGE-CLASSIFICATION-VS-TRANSFER-LEARINING/blob/master/imageclassification.ipynb

linkelin profile: https://www.linkedin.com/in/oluyede-segun-jr-a-a5550b167/

twitter profile: https://twitter.com/oluyedejun1

TAGS: #AI #ML #KERAS #DEEPLEARNING #CNN # IBM #WATSON

oluyede Segun (jr)
oluyede Segun (jr)

Written by oluyede Segun (jr)

Certified I.T specialist | Computer Network Admin | Cloud | Artificial intelligence ( Machine Learning & Data Science),& webdev. python/JavaScript language

No responses yet