Dave Gill

Building an Image Classifier

If you read any articles on building an image classifier (for whatever reasons) you would get the impression that it is realtively easy. The truth is not so simple. The trivial examples that most of those articles refer to provide a false sense of confidence. I understand why they are used because it gives you a clear example and a path to your own work. But when you have to classify images from your own problem domain you can hit several issues.

This article is to reflect my own problems with attempting to build an image classifier with specific domain images. For commercial reasons I will not reveal the actual problem domain but the different attempt I have made move the AI model from a cloud based provider (with all of the subsequent costs) to our own trained AI model.

One of the issues that slowly dawns on you (after many failed attempts) is that the images you use for training have to be a good quality. The fact that I had forgotten one of the basic tenents of computing, garbage in = garbage out. I had been battling to get anywhere near decent results with the training data by just taking the images I could obtain from a running system and try and train with them. Needless to say that did not work and I ended up with models with a low accuracy and high loss.

So I decided I would build a quick and nasty web page that would allow me to scan through all of the images and press a button on each image if it was suitable or not. I did initially think i could train a different model to do this for me, but I would still need someone/something to provide the training material to say what was usable. I started working y wy through the thousands of images only to find it the most boring work I have ever done. But I have some readily availble kids who might have wanted to earn some extra pocket money. So I gave them the criteria to review the images and set them off at a decent hourly rate. I then had a good set of images that I could use for training.

I then started to build several models, some from scratch and some transfer learning with the weights from various sources. I have several different computers doing little round the house so distributed the workload around them. One of the first things you realise is that fine tuning the parameters for your training is tedious and needs a way of recording what you have done so you do not repeat yourself. So I put all of the results into a spreadsheet. Which although it helps does not remove the tedium. It is very time consuming to converge on the best hyper parameters for your training model. So I lookeed for alternatives. I thought the best approach might be to use a Genetic Algorithm (Or Evolutionary Algorithm depending on who you talk to and probably how old they are).

My first attempt was to use DEAP to work its way through the parameters and provide me with the perfect parameters on my various models. So with hope and little experience of these things I set that off to do all the hard work for me. Well it ran for an age (at least 24 hours) and then the OOM service on my machine killed it. After several attempts at tweaking the process I decided I did not have sufficient power on any of computers to do the job. So I looked for an alternative and found the Keras Tuner - I have no idea why my first internet search did not suggest it. This gave me a much impler and faster way of identifying the hyperparameters I needed.

That gave me a base to start my training across multiple models and led to the development of a model that was slightly better than the cloud provider we were initally using. Sounds great, but I am now in the spot of working out how I get the tensorflow model from my machine to a web service that can be consumed by others. Perhaps that is a post for another day - When it is done perhaps. Or perhaps I will simply update this post.