Browsing Category

Deep Learning

b14
Deep Learning, Python,

Basic Image Recognition with Built-in Models in Keras

In this blog post we are going to look at Image Recognition with built-in models available in Keras. The notebook can be also viewed on Github.

There are various pre-trained models available in Keras. The weights for these models are trained on a subset of ImageNet dataset. ImageNet is an image dataset containing millions of images with each image described in words. The models are trained on a dataset of 1000 types of common objects (the list of 1000 categories). This dataset is used during The ImageNet Large Scale Visual Recognition Challenge (ILSVRC).

The models for image classification available in Keras are listed below:

  • Xception
  • VGG16
  • VGG19
  • ResNet50
  • InceptionV3
  • InceptionResNetV2
  • MobileNet
  • DenseNet
  • NASNet

Once the model is instantiated, the weights are automatically downloaded to ~/.keras/models/ folder. We will be implementing ResNet50 (50 Layer Residual Network – further reading: Deep Residual Learning for Image Recognition) in the example below. The file containing weights for ResNet50 is about 100MB.

The versions

In this example I am using Keras v.2.1.4 and TensorFlow v.1.5.0 with GPU (using NVIDIA CUDA).

 

b13
Deep Learning, Machine Learning, Python,

Basic Example of a Neural Network with TensorFlow and Keras

This blog post covers basic example of a Neural Network, using TensorFlow and Keras in Python. The notebook can be also viewed on Github.

TensorFlow and Keras

TensorFlow was developed at Google to use internally for machine learning tasks, and applied to the applications like speech recognition, Search, Gmail, etc. It was made public in 2015 as an open source application. The library is in C++, used with Python API. TensorFlow can be used for various problems like image recognition, language processing, implementation in self-driving cars, etc. There are various alternatives available to TensorFlow such as Theano, and Torch.

We are going to use Keras in this notebook, with Tensorflow as a backend engine. Keras is a high-level wrapper, which can be used both with TensorFlow and Theano. It simplifies common operations. The code is similar to scikit-learn, making it easier to get used to it, while in the background TensorFlow or Theano is used for processing.

The data

In this example we will be looking at MNIST database (a subset of a larger set by National Institute of Standards and Technology). This is a classic dataset containing 60000 training images, 10000 test images, and corresponding training and test labels. The images are handwritten digits, in the shape of 28 x 28 pixels, and divided into 10 categories (from 0 to 9).

The versions

In this example I am using Keras v.2.1.4 and TensorFlow v.1.5.0 with GPU (using NVIDIA CUDA). Running examples on a GPU can speed up the training process.

In [1]:
# To avoid warnings
import warnings
warnings.filterwarnings('ignore')

# Importing keras and tensorflow, and printing the versions
import keras
print('Keras: {}'.format(keras.__version__))

import tensorflow as tf
print('TensorFlow: {}'.format(tf.__version__))
Using TensorFlow backend.
Keras: 2.1.4
TensorFlow: 1.5.0