Computer Vision - Identifying Blurry Photos using a CNN

My goal here is to classify good and bad quality photos using a neural network. The idea for a tool like this hit me when I uploaded several hundred photos from my digital SLR camera and needed to sort through them all. In particular, just getting all the blurry, dark, or overexposed photos out of the way would be a big help.

Transfer learning, or training from scratch?

My initial experimentation involved applying transfer learning to the “Inception” architecture, which is pre-trained on thousands of images for the specific purpose of photo classification. However, I quickly realized that since my primary goal was to identify and separate blurry photos from a library of images, I needed a convolutional neural network (CNN) architecture that simply did well with edge detection. The “Inception” architecture has over 200 layers, but understanding edges is what happens in the initial layers. Thus, I switched gears to the much simpler LeNet architecture, often considered a good starting point for a basic CNN. This architecture has 5 layers: 2 convolutional layers and 3 dense (fully-connected) layers.

The training dataset

I wasn’t initially sure how many images I’d need to train on, but I wanted to start with a reasonably large set that included distinctly clear images and distinctly blurry images. I am thankful to have found the CERTH Image Blur Dataset, which contains 1200 images that the researchers already marked as clear, good-quality images. I applied an artifical blur (Gaussian blurring using OpenCV) to these images, so I had a total of 2400 images: half clear and half blurry. The researchers did also provide both artificially blurred photos and blurry photos taken by an actual camera. However, I chose not use these photos for model training as I wanted to control the level of blurring myself. Instead, I used their naturally blurry images (1000 provided) as a test set for my model.

Results

As a quick test, I trained my model on just 300 photos over 5 epochs and got a pretty impressive 98% accuracy (train/validation split). Clearly the neural network was already able to capture the presence of edges, which is what I had intended. On the test set from the researchers of blurry photos from an actual camera, it correctly labeled around 50% of them (the blurriest 50%), while it missed some of the more subtle blurring effects that a human would have noticed. I later retrained it on 3000 images per epoch and test set accuracy improved to 65%. There’s definitely some opportunity to improve here by continuing to retrain this model for better blur detection, or to adjust the classification threshold depending on individual tolerance for false positives vs. false negatives.

Bonus Results

One additional positive result from my model is the example of a clear subject with blurry background. Here’s a picture of me at a track day: M3_photo

I was happy to find that my trained neural network classified images like these as CLEAR - without me ever actually training it on images like these! In fact, I found this dataset of stock photos that contains 1000 such images, and it classified them as clear with 90% accuracy. Overall, that’s really great news for my purposes because these are the kinds of images that I would want to keep.

More Details

You can see my neural net architecture, which I built using Keras and Tensorflow, here.

You can see my presentation on this topic here.

Written on April 1, 2019