Monday, January 15, 2018

OpenAI and the Dota 2 Bot

OpenAI – a non-profit AI research company, founded by Elon Musk and Sam Altman, which focuses on developing friendly AI – unveiled their Dota 2 AI Bot in August 2017, which is capable of defeating top Dota professional players in 1v1 matches.

OpenAI Logo
OpenAI Logo

Dota 2 is a multiplayer online battle arena (MOBA) game developed by the Valve Corporation. First released on July 2013, the game is a sequel to the community game Defence of the Ancients (DotA) which was released back in 2003 as a mod for the game Warcraft III.

The Dota 2 Game Logo
The Dota 2 Game Logo

A typical match of Dota 2 is played by five-verses-five (5v5), although other variations of the game exists, such as 1v1. The players each choose a ‘hero’ from 115 playable characters, each with its strengths and weaknesses, and various abilities and powers. The game is played in a real-time strategy manner, where each ream battles the other and attempts to destroy the ‘Ancient’ (the large structure on their base) of the opposing team while defending their own.

Wednesday, January 3, 2018

Visualizing the Convolutional Filters of the LeNet Model

First of all, Happy New Year to you all!

We have a great year ahead. And, let's start it with something interesting.

We've talked about how Convolutional Neural Networks (CNNs) are able to learn complex features from input procedurally through convolutional filters in each layer.

But, how does a convolutional filter really look like?

In today's post, let's try to visualize the convolutional filters of the LeNet model trained on the MNIST dataset (handwritten digit classification) - often considered the 'hello world' program of deep learning.

We can use a technique to visualize the filters from the article "How convolutional neural networks see the world" by Fran├žois Chollet (the author of the Keras library). The original article is available at the Keras Blog:

The original code is designed to work with the VGG16 model. Let’s modify it a bit to work with our LeNet model.

We need to load the LeNet model with its weights. You can follow the code here to train the model yourself and get the weights. Let's name the weights file as 'lenet_weights.hdf5'.

We'll start with the imports,

from scipy.misc import imsave
import numpy as np
import time
from keras import backend as K

from keras.models import Sequential
from keras.layers.convolutional import Conv2D
from keras.layers.convolutional import MaxPooling2D
from keras.layers.core import Activation
from keras.layers.core import Flatten
from keras.layers.core import Dense

from keras.optimizers import SGD

We need to build and load the LeNet model with the weights. So, we define a function - build_lenet - for it.

Friday, December 8, 2017

What is AlphaGo, AlphaGo Zero, and AlphaZero

AlphaGo – developed by the DeepMind team of Google – is an AI program which plays the board game Go.

A Go board (By Donarreiskoffer - Self-photographed, CC BY-SA 3.0,
A Go board (By Donarreiskoffer - Self-photographed, CC BY-SA 3.0,

The Go board game is an abstract strategy game, which has been invented in China over 2500 years ago. Despite its simple set of rules, Go is considered to be much more complex than Chess, and is one of the most studied strategy game of all time.

The AlphaGo Logo
The AlphaGo Logo

The AlphaGo uses a Monte Carlo tree search algorithm to find moves using the trained deep neural network which works as its knowledge core. AlphaGo was initially trained on a training set of over 30 million moves data from human Go matches. It was then further trained by letting it compete against copies of itself using reinforcement learning.

Wednesday, November 15, 2017

TensorFlow Lite Developer Preview Announced

TensorFlow yesterday (14th Nov) announced the developer preview of TensorFlow Lite, a lightweight solution of TensorFlow for mobile and embedded devices, targeted for low-latency inference of on-device machine learning models.

TensorFlow Lite Logo
TensorFlow Lite Logo

TensorFlow Lite is an evolution of TensorFlow Mobile, and designed to be lightweight, cross-platform (Android and iOS for a start), and fast.

Through the Android Neural Networks API, TensorFlow Lite would be capable of utilizing purpose-built machine learning hardware in the devices as they become available.

A trained TensorFlow model can be converted to the TensorFlow Lite format (.tflite) using the provided converter, and deployed to the mobile app (Android or iOS), where the converted model gets executed using the TF Lite Interpreter.

TensorFlow Lite contains a C++ API with a Java API wrapper on Android.

It has out-of-the-box support for MobileNet, Inception V3, and Smart Reply Models.

Read more about TensorFlow Lite on the following links,

Related Links,

Build Deeper: Deep Learning Beginners' Guide is the ultimate guide for anyone taking their first step into Deep Learning.

Get your copy now!

Sunday, October 29, 2017

Codes of Interest becomes 1 Year Old!

It's been one year!

I began the Codes of Interest Blog a year ago with a simple thought - to share my enthusiasm of Machine Learning and Computer Vision with everyone.

It's been a fulfilling journey.

Now, after a year, Codes of Interest has become a thriving community of like-minded and engaging Machine Learning and Computer Vision enthusiasts. We've covered over 40 tutorials on Deep Learning on libraries like Keras, TensorFlow, and Theano, and playing around Computer Vision libraries such as OpenCV and Dlib.

The constant feedback and suggestions from you all has allowed me to launch the Codes of Interest Facebook Community.
And, I was able to release my first book on Deep Learning: Build Deeper: Deep Learning Beginners' Guide, which is now available on Amazon.

Build Deeper: Deep Learning Beginners' Guide

I'm getting more and more emails and comments daily. So much that I'm having trouble responding to all.

So, I'm taking this opportunity to thank all the readers and subscribers of Codes of Interest for your input and encouragement. I can assure you that more exciting content is coming.

Wednesday, September 27, 2017

Migrating a Model to Keras 2.0

Keras v2.0 has been released for a couple of months now - v2.0.0 released on 5th May, 2017, while the latest version is 2.0.8 at the time of this writing. It brought in a lot of new features and improvements, but also made some syntax changes. Trying to run a code with the old syntax may result in anything from a flood of deprecation warnings, to not being able to run the code at all. Since there are many code examples online which uses the older syntax - including some older posts in Codes of Interest - it's better to know how to get such older syntax model to work on the 2.0 API.

The complete list of changes in Keras v2.0 was extensive, but the following list would help you to narrow down majority of the changes.

The most prominent change is the changing of image_dim_ordering parameter to image_data_format, and its associated values from "tf", and "th" to "channels_last" and "channels_first". We talked about this change in detail in our earlier post "What is the image_data_format parameter in Keras, and why is it important".

Likewise, in all the places where "dim_ordering" argument/parameter was used, it has been changed to "data_format".

All of the Convolution* layers have now need renamed to Conv*.
E.g. Convolution2D is renamed to Conv2D

Saturday, September 9, 2017

What is the image_data_format parameter in Keras, and why is it important

We've talked about the image_dim_ordering parameter in Keras and why is it important. But since from Keras v2 changed the name of the parameter, I thought of bringing this up again.

As you know, Keras  is a higher-level neural networks library for Python, which is capable of running on top of TensorFlow, CNTK (Microsoft Cognitive Toolkit), or Theano, (and with limited support for MXNet and Deeplearning4j), which Keras refers to as 'Backends'.

Which backend Keras should use is defined in the keras.json file, which is located at ~/.keras/keras.json in Linux and Mac OS, and at %USERPROFILE%\.keras\keras.json on Windows.

The default keras.json file (default set to TensorFlow) would look like this,
   "epsilon": 1e-07,  
   "floatx": "float32",  
   "image_data_format": "channels_last",  
   "backend": "tensorflow"  
The "backend" parameter should either be "tensorflow", "cntk", or "theano". When switching the backend, make sure to switch the "image_data_format" parameter too. For "tensorflow "or "cntk" backends, it should be “channels_last”. For “theano”, it should be “channels_first”.