COMPARING KERAS DEEP-LEARNING IMAGE CLASSIFICATION AND TRANSFER LEARNING(IBM WATSON CLOUD) USING APPLE AND BANANA IMAGES.
- 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
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.
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:
- Accepting a batch of images used for training.
- Taking this batch and applying a series of random transformations to each image in the batch (including random rotation, resizing, shearing, etc.).
- 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
1.4 Plot images with matplotlib
1.5 Define keras deep neural network layer for training
Also state the training parameters like accuracy and number of epochs, and validate data on test dataset containing images, and save the model
1.6 OUTPUT of training:
Accuracy on train dataset = 0.9286
Accuracy on test dataset = 0.9189
1.7 predict on an external image
It correctly predicted 1 for apple, and 0 for banana
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
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
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
2.3 Test custom classifiers on two images
2.4 OUTPUT OF FIRST IMAGE
2.5 OUTPUT OF SECOND 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.
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