Friday, February 5, 2016

Object Classification using Deep Learning and Raspberry PI

Of late, I have been playing with multimodal interaction [1] with a Raspberry PI (referred to as an IoT edge device) that is being powered by predictions using Deep Learning. In this post, I discuss how I created the pipeline using voice interaction (voice decoding and speaking) and Raspberry PI camera to identify fruits.

Image Dataset
FID30 [5] image dataset contains 30 fruit category of images. These images were augmented using manipulations of the images such as a 90 degree transformation, and negative transformation of the images. Whenever possible, these images were augmented with images along with the transformations.

Deep Learning
Deep Learning [3] can be used for object recognition in images and for decoding voice. In this demo, I have used Convolutional Neural Networks (CNN) [2] for image analysis. For this demo, I have build the CNN model; and used CMU Sphinx with Linux’s espeak for voice interaction.

Specifically, CNN is a type of feed forward artificial neural network that has a wide applicability in image recognition. The models built using NVidia Digits Framework [6] uses Caffe Framework [7] running an NVidia GPU [8]. For the network part, I have chosen to use AlexNet [4] to generate the model; other networks such as GoogLenet were evaluated too. Typically, CNN require a large dataset of labelled images, and the generated models was overfitting. To have a better accuracy and to reduce the overfitting, a huge repository of images is needed. Creation of such image repository with 100’s of thousands of images is a challenge and cannot be addressed by this post.

IoT Edge Device built using the Raspberry PI module
The edge node was built using Raspberry PI using a $2 microphone, a $34 camera, $10 usb wifi adaptor and a $12 speaker system. The system took about $100 to build. The software tech stack includes Python - PyAudio with models were based on CMU PocketSphinx for voice interaction.

Cloud Tech Stack
The model creation and prediction using the model was done in the cloud. Tech Stack included Linux for OS, Python, Java, MongoDB as the backend storage, NVidia GPU for model generation, Caffe Framework for model generation - object recognition and NVidia’s Digits for model generation.

What you will see in the Demo video
When the word “this” is detected by IoT Device, an image is captured and uploaded to the cloud (my laptop) via a REST interface. On the server, the object recognition module pulls the image, identifies the object and updates the entry via the REST Interface. The Raspberry PI polls the REST interface for the prediction result for the object it just uploaded and announces the object on the speakers.

All human interaction is with the IoT Device - through the speaking and listening; and all image recognition is performed on the server. It can be altered such that an initial prediction can be performed at the edge device making it a ‘true’ IoT device. This demo shows and end-to-end pipeline with CNN.

Apple being identified as Apples:
Lemons being identified as Lemons:
Orange being identified as Apricots:

In some cases, the same fruit with with a different background has been identified incorrectly.

[4] Krizhevsky, A., Sutskever, I. and Hinton, G. E. ImageNet Classification with Deep Convolutional Neural Networks. NIPS 2012: Neural Information Processing Systems, Lake Tahoe, Nevada.
[5] Škrjanec Marko, Automatic fruit recognition using computer vision. Bsc Thesis, (Mentor: Matej Kristan), Fakulteta za računalništvo in informatiko, Univerza v Ljubljani, 2013.
[6] Digits Framework.
[7] Caffe Framework.

Thursday, October 29, 2015

Using Apache Zeppelin for Spark, SparkML and SparkSQL

Apache Zeppelin[1] is quite a handy tool for exploratory analysis of data using Spark, SparkML and SparkSQL.

Sample Visualization in Apache Zeppelin generated using SparkSQL:

Create RDD, dataframe and register as a temp table:
Query your data using SparkSQL:
Use SparkML for analytics:

Once the Spark SQLContext has the data, Zeppelin can be used to visualize the data.
[1] Apache Zeppelin:

Monday, October 26, 2015

Deep Learning: Identification of Fruits Using Digits, Caffe Framework

Image classification using Neural Networks is a very interesting topic. During my bachelors,  I had a glimpse of Neural Networks - where I specifically worked on "C" code to convert hand written signatures into features that could be fed into the neural networks.

Following is work to take open datasets and classify fruits.

Classification of Orange using the model developed using Digits 2 and Caffe Framework.


  1. CUDA: 7.0
  2. Caffe framework [1]
  3. NVidia GeForce GTX 860M with 640 cores
  4. NVidia Digits 2


  1. Fruit DataSet [2]  (30 categories)
Digits does image classification, with 25% of the images are set for validation.

After many modifications and using AlexNet[2], I have received an accuracy of 60%. Anything beyond this has lead to overfitting. Overfitting is part of Convolution Neural Networks. To avoid over fitting, a large amount of images needs to be available.

I posted on multiple forums to see if practitioners/researchers can get larger image data. Following are the next steps that I can envision:

  1. Looking at other datasets, to extract the same features from them, to add to the dataset. 
  2. Downloading non-copyrighted images from Search Engines. Google's API allows only 64 images to be downloaded. I asked on their forum on how to filter images that are copyrighted.
I would like to create a framework that could create automated image datasets (non-copyrighted images) including translations and transformations. 


[1] Caffe Deep Learning Framework:
[2] Marko Škrjanec, Fruit Image Data set
[3] Convolution Neural Networks,

Tuesday, October 6, 2015

Running CUDA 7 on Ubuntu 14.04: blank screen after CUDA install: Solved

Update: CUDA 8 is awesome; and seems more stable.

Installation of CUDA on Ubuntu 14 has resulted in blank screen. After fixing those issues, the GUI login screen shows up, but login would not work. After multiple attempts to fix, either CUDA works or X works.

Trying to use Nouveau driver for GUI and Nvidia driver for CUDA, lead me to a blog [1]. It worked for me and thanks Chen.

Chen suggests to blacklist Nouveau (which CUDA installer does as well), remove and purge nvidia drivers, install CUDA. During this part, install Nvidia driver, but NOT the OpenGL driver.

And everything works. Thanks, Chen.

To fix Ubuntu's blank Screen

If Ubuntu boots to blank screen [2]:
  1. Goto command line: ctrl + alt + f1.
  2. Stop lightdm: sudo service lightdm stop
  3. Disable gpu-manager by backing up /etc/init/gpu-manger.conf and commenting its contents.
  4. Switch to prime mode by installing and using sudo prime-select nvidia
  5. Get the correct busid for nvidia: lspci | grep NVIDIA
  6. Update /etc/X11/xorg.conf with the correct busid. "PCI:01:00.0"
  7. Perform sudo chattr +i /etc/X11/xorg.conf
  8. Start lightdm: sudo service lightdm start

[1] Chen,

Sunday, August 30, 2015

Caffe Install: ATLAS installation Ubuntu CPU throttling apparently enabled

Caffe Install requires a Math library. Of the 3 options, ATLAS is open source and, hence, the default. Installation of ATLAS was causing issues because intel_pstate governor. Governor does power management for Kernel [1].

To identify if, the intel_pstate is the issue, identify if the governor is intel_pstate. 

  1. cpufreq-info will show the governor.
  2. If intel_pstate is shown as the governor, disable intel_pstate.
  3.  Edit the file /etc/default/grub and add: GRUB_CMDLINE_LINUX_DEFAULT="intel_pstate=disable"
  4. Update grub.cfg ala grub-mkconfig -o /boot/grub/grub.cfg

Friday, February 26, 2010

Calculating distance between two IPs using Maxmind database

This is a faster mechanism to find distance between two IPs instead of using Haversine distance to calculate the distance between two points (each defined by a lat, long tuple) on the globe .

Thursday, February 25, 2010

Hadoop: Effectiveness of a Combiner Class

The execution speed difference for an MR job with and without a combiner class is huge. The Security log analytics without a combiner class  did not complete in 1.5 days. With the addition of a Combiner class, the code finished in 15-20 minutes! Now, the reasons for this performance enhancement are obvious.
  • <K, V> are in memory and network latency and traffic to reducers is decreased.
  • Disk operations are minimal at the reducers as a result of combine operations.