Thursday, November 22, 2018

Installing the New Anaconda Native TensorFlow Package

For a while now, the most reliable two ways to get TensorFlow installed is to either use the pip package, or compile from source.
Compiling TensorFlow from source takes hours, and still prone to errors (see "Failed Attempts at Building TensorFlow GPU from Source"). While the pip package is relatively easier, getting the GPU version of TensorFlow installed using pip was a hassle.

But not anymore. Because the conda native TensorFlow packages are here now.

Installing is quite easy.

Note: Don't install the pip and conda versions of TensorFlow on the same conda environment. If you already have the pip version installed uninstall it using,

pip uninstall tensorflow


To install the CPU version of TensorFlow, just run,

conda install tensorflow


To install the GPU version,

conda install tensorflow-gpu


Saturday, September 1, 2018

Using Multiple Cameras with OpenCV

As you know, OpenCV is capable of reading from any connected camera in your system, whether it's a built-in webcam (in a laptop) or a USB connected one.

But what if, you wanted to read from more than one cam at the same time?

Can OpenCV handle it?

OpenCV accessing 2 cameras at once
OpenCV accessing 2 cameras at once


Yes, it can!

It's quite simple. Here's how to do it.

Friday, August 31, 2018

Our YouTube Channel is Live!

We have a YouTube Channel now!

https://www.youtube.com/channel/UCRM3zD8oOHP7Epw6XVZ01ew


Don't forget to subscribe!
Fun and exciting Deep Learning experiments, Computer Vision, and Tech Tips too...

Thursday, August 23, 2018

Cleaning up your Anaconda installations

If you've been using Anaconda Python for a while, and been creating multiple environments and adding/removing packages, you may have noticed that it's starting to take up a lot of disk space (sometimes tens of GBs).

Anaconda installation can get big
Anaconda installation can get big


One reason is that anaconda environments are completely isolated workspaces from each other with their own copy of Python. So, the more environments you have, the larger the space needed by anaconda. But the other reason is that anaconda keeps a cache of the package files, tarballs etc. of the packages you've installed. This is great when you need to reinstall the same packages. But, over time, the space can add up.

So, how do we clean up this cache and regain some disk space?

Tuesday, July 10, 2018

Failed Attempts at Building TensorFlow GPU from Source

For the last 3 weeks, I've been trying to build TensorFlow from source. I wanted to get TensorFlow GPU version working on Windows with CUDA 9.2 and cuDNN 7.1. Since the pre-built wheels only work with CUDA 9.0, the only way we can get it working with 9.2 is to build it ourselves from source.

The Windows build of TensorFlow is done using CMake. The official instructions are here: https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/cmake

Unfortunately, as I found out after multiple attempts, the build process is not as simple as it sounds.
Every attempt I have made to build it failed so far.

But, I decided to post the steps I took - which didn't work - so that you all may be able use it as a reference if you decided to try it out yourselves. Again, note that these steps did not work.

First, I started with gathering all the dependencies to build on Windows 10:
  • Visual Studio 2015 Community Edition With Update 3 (14.0.25431.01) with C++
  • Anaconda Python 3.6.5
  • Git for Windows 2.18.0
  • Swigwin 3.0.12
  • CUDA Toolkit 9.2
  • cuDNN 7.1
  • CMake 3.11.3

Sunday, June 3, 2018

Setting up the OpenMV Cam

Few weeks back, we talked about OpenMV - the small embedded computer vision module with a built-in camera, that can be programmed to perform various vision tasks. It gives you the ability to bring computer vision in to your embedded projects.

After I first read about it, I was eager to get my hands on a kit. Their official site - openmv.io - offers international shipping, as well as links to local distributes in some countries. The shipping was quite fast.

The OpenMV Cam M7
The OpenMV Cam M7

First Impressions


The cam comes with a really nice clear plastic case. The headers (used to connect other shields on to the board) comes separate (pictured above). This gives you the option to solder them - or other types of headers - yourself if needed. Headers aren't essential for the basic usage of OpenMV. Both the case and the board itself has an excellent build quality.

The cam itself is smaller than I expected: about 2/3 the size of a credit card.

The size of the OpenMV Cam
The size of the OpenMV Cam

Monday, May 14, 2018

Fixing the Matplotlib PyPlot import errors

About a week back, I was reinstalling Keras, TensorFlow and all the other libraries after a reformat of my PC. When I started verifying the library installations, I came across a strange error. When I tried to run a simple deep learning model, Python runtime crashed. As soon as I execute the script I was getting the "python.exe has stopped working" error message (I'm using Windows 10).

Matplotlib is an important part of my deep learning workflows
Matplotlib is an important part of my deep learning workflows
A little bit of debugging narrowed down the error to the following line in my script.

import matplotlib.pyplot as plt

(I was using matplotlib to graph the training history of the model. See "How to Graph Model Training History in Keras")

The error did not occur if I simply import matplotlib. It only occurred when specifically importing the pyplot module.

import matplotlib
# no errors

import matplotlib.pyplot as plt
# crash!!!

This is a known issue due to some library conflicts in the installation, which should hopefully be fixed in a future release. Until then, if you're getting this error, you can fix it by following the steps below.

Sunday, April 22, 2018

Embedded Computer Vision with OpenMV

Have you ever wanted to put computer vision into an embedded device? But wasn't sure whether it's possible to cram in a computer vision algorithm into a small hardware device?

Well, that's what the OpenMV project is all about.

OpenMV is a programmable embedded device, with a built-in camera, that you can program with variety of vision tasks.

The OpenMV Cam M7
The OpenMV Cam M7 (Image source)

The OpenMV project has been started back in 2013 with a goal of becoming the "Arduino of Machine Vision". They now have the The OpenMV Cam M7 (pictured above), powered by a 216MHz ARM Cortex M7 processor and 512KB.

Tuesday, February 27, 2018

Track any object in a video with Dlib Correlation Trackers

Training an object detector is bit of a complicated task. You need to have a proper training dataset with the relevant bounding boxes, and then use something like a HOG feature extractor with a SVM classifier for the detection - such as the Dlib Object Detection classes (link).

But that's a lot of work if you just need to track an object across a limited number of frames, or just need to detect motion or direction of movement. For that, we can easily use the Correlation Trackers feature in Dlib.

Object Tracking
Object Tracking

See it in action,

Object Tracking in Action - Animated
Object Tracking in Action

Correlation Trackers - as their name suggests - works by correlating a set of pixels from one frame to the next.

Let's see how to build it.

Saturday, February 17, 2018

Using Data Augmentations in Keras

When I did the article on Using Bottleneck Features for Multi-Class Classification in Keras and TensorFlow, a few of you asked about using data augmentation in the model. So, I decided to do few articles experimenting various data augmentations on a bottleneck model. As a start, here's a quick tutorial explaining what data augmentation is, and how to do it in Keras.

The idea of augmenting the data is simple: we perform random transformations and normalization on the input data so that the model we’re training never sees the same input twice. With little data, this can greatly reduce the chance of the model overfitting.

But, trying to manually add transformations to the input data would be a tedious task.

Which is why Keras has built-in functions to do just that.

The Keras Preprocessing package has the ImageDataGeneraor function, which can be configured to perform the random transformations and the normalization of input images as needed. And, coupled with the flow() and flow_from_directory() functions, can be used to automatically load the data, apply the augmentations, and feed into the model.

Let’s write a small script to see the data augmentation capabilities of ImageDataGeneraor.

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: https://blog.keras.io/how-convolutional-neural-networks-see-the-world.html.

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.