Wednesday, January 1, 2020

Fixing the KeyError: 'acc' and KeyError: 'val_acc' Errors in Keras 2.3.x

Have you been using the 'History' object returned by the fit() functions of Keras to graph or visualize the training history of your models? And have you been getting a 'KeyError' type error such as the following since recent Keras upgrade and wondering why?


Traceback (most recent call last):
  File "lenet_mnist_keras.py", line 163, in <module>
    graph_training_history(history)
  File "lenet_mnist_keras.py", line 87, in graph_training_history
    plt.plot(history.history['acc'])
KeyError: 'acc'

The KeyError: 'acc' when attempting to read the history object
The KeyError: 'acc' when attempting to read the history object


Traceback (most recent call last):
  File "lenet_mnist_keras.py", line 163, in <module>
    graph_training_history(history)
  File "lenet_mnist_keras.py", line 88, in graph_training_history
    plt.plot(history.history['val_acc'])
KeyError: 'val_acc'

The KeyError: 'val_acc' when attempting to read the history object
The KeyError: 'val_acc' when attempting to read the history object

Well, this is due to a breaking change introduced in Keras release 2.3.0.

Sunday, December 29, 2019

How to Install TensorFlow 2.0 on Anaconda (with CUDA support)

TensorFlow 2.0 has been released for a few months now. This latest version comes with many new features and improvements, such as eager execution, multi-GPU support, tighter Keras integration, and new deployment options such as TensorFlow Serving.

So, it's time we all switched to TensorFlow 2.0.

TensorFlow 2.0


The Anaconda-native TensorFlow 2.0 packages are now available in the main conda repository. So, let's see how we can install TensorFlow 2.0 on Anaconda Python. This method will work on both Windows and Linux. And, if you have a CUDA capable NVIDIA GPU, you can enable GPU support as well.

Step 1.Creating a New Conda Environment


We'll start by creating a new conda environment. (I'll name it 'tensorflow2'. You can choose another name if you like):

conda create --name tensorflow2 python=3.7 anaconda


Create a new conda environment
Create a new conda environment

Monday, December 16, 2019

How to Build and Install the Latest Version of Dlib on Anaconda on Windows

Dlib is a toolkit for C++ and Python containing machine learning algorithms and tools for creating complex software to solve real world problems. Dlib provides algorithms for machine learning/deep learning, multi-class classification and clustering models, support vector machines, regression models, a large set of numerical algorithms for areas such as matrix manipulations and linear algebra, graphical model inference algorithms, and utility algorithms for computer vision and image processing. And due to C++ implementations backing most of these implementations, they’re optimized to the point that can be used in some real-time applications as well.

If you’re interested in facial recognition models or facial emotion processing, then Dlib is a library you should definitely try out.

Dlib v19.19 in action on conda on Windows
Dlib v19.19 in action on conda on Windows

But with all the great features in Dlib, installing it has always been a little bit troublesome because of some specific dependency requirements it needs which had a habit of almost always conflicting with your other libraries. With the latest versions however, installing Dlib has become somewhat simple.

If you’re using Anaconda Python for your python experiments, like me, you’ll find that there is no native Dlib package in the native conda package list. In one of my earlier tutorials I showed how to install the Dlib conda package from the conda-forge channel in to your conda environment. The conda-force package works perfectly fine, and it’s still one of the quickest ways to install Dlib.

But if you really want the latest official package of Dlib installed (v19.19 as the latest at the time of this writing) then using the pip package is the way to go. In order to install the Dlib pip package you’ll first have to setup some dependencies.

Monday, December 9, 2019

Deep Learning, AI/ML, Computer Vision, and Data Science Gift Buying Guide - 2019

It’s the holiday season! This is the season of the year we like to celebrate the most. And it is the part of the year that we'd like to give, and receive, gifts.

While it's easy to pick a gift (relatively speaking) for some people, the interests of some others might make it hard nail down a gift for. (Take an AI, ML, Data Science and programming enthusiast like me for an example)

Now, you might have a family member, colleague, or a friend that is into AI, Deep Learning, and Machine Learning. Or, they might be working on or interested in Data Science or Computer Vision. You might be wondering what sort of gifts to get them.

Or simply as an enthusiast in those areas yourself, you're thinking of buying a gift for yourself this season. (I know that I’m thinking the same)

So, how do you select a gift for someone with interest in such vast and technical fields?

Well today I’m going to give you some gift ideas that just might work.

AI, ML, Deep Learning, Computer Vision, and Data Science Gift Guide 2019


When thinking of gifts relating to the AI/ML, CV, Data Science fields, we can consider three categories of gifts,

  1. Items to Improve their ability to perform tasks in those areas
  2. Give them new tech toys to play around in those areas
  3. Help them improve their knowledge in those areas

Let’s see what items we can select for each of those categories.


Tuesday, October 1, 2019

TensorFlow 2.0 Released!

After months in the Alpha state, Google has now released the final stable version of TensorFlow 2.0.
TensorFlow 2.0 aims at providing a easy to use yet flexible and powerful machine learning platform.

TensorFlow 2.0 Logo

The new version also hopes to simplify deployment of TF models to any platform by standardizing the model formats. You will be able to run TensorFlow models on a variety of runtimes, such as using TensorFlow Serving - a flexible, high-performance serving system for machine learning models, designed for production environments -, on browser or through Node.js using TensorFlow.js, and on mobile through TensorFlow Lite.

Sunday, June 16, 2019

Bird Watch: Our First Public Deep Learning Computer Vision Product

Codes of Interest is proud to present Bird Watch, a Deep Learning Computer Vision tool to identify bird species from images. It was built for wildlife photographers, bird and nature lovers, researchers, and academics alike.

Bird Watch is now in v0.3.0 Beta and is available for anyone to use free of charge at,


Bird Watch in action
Bird Watch in action

The system was built using transfer learning, with the InceptionV3 model. It uses Keras, TensorFlow, and OpenCV for its underlying features. The web frontend is built using Flask.

Monday, May 20, 2019

Installing OpenCV got easier

OpenCV is undoubtedly the unmatched de facto standard library for computer vision. Not only does it provide a near complete set of vision algorithms, the set of primitive graphics functions it provides to manipulate images makes it essential to many of our projects.

OpenCV being used when building a Keras CNN model
OpenCV being used when building a Keras CNN model

Installing the latest version of OpenCV used to be hard. The pre-built binaries available was never up to the tasks we wanted. Compiling from source was an option, but was tedious and time consuming.

Then, we got the anaconda versions of OpenCV from Conda-Forge, which we could simply install using,

conda install -c conda-forge opencv

Now, things are going to be simpler, as Anaconda native OpenCV packages are now available.