Blindness detection with Artificial Intelligence

Huseyn Gasimov
Intelec AI
Published in
6 min readJun 30, 2020
Majority of US adults have eye problems but don’t see a doctor to correct them [Source]

One of the leading cause of blindness among working aged adults is Diabetic retinopathy (DR). It is an eye disease associated with long-standing diabetes. This happens when high blood sugar levels cause damage to blood vessels in the retina. These blood vessels can swell and leak. Or they can close, stopping blood from passing through. Sometimes abnormal new blood vessels grow on the retina. All of these changes can steal your vision. You can follow this link to find more about it.

Explanation of Diabetic Retinopathy [Source]

What is the problem?

Diabetic retinopathy is treatable if it is detected early. Currently, detecting DR is a manual process, which requires a trained clinician to evaluate color fundus photographs of retina. I see 2 problems here:

  1. Highly educated clinicians with up-to-date knowledge are not so many and they are mostly concentrated in big cities with high quality of life. People who live in rural areas usually don’t have access to well trained clinicians or to any clinics at all.
  2. Since there are not so many well educated doctors, they are usually well know in their area and their expertise is very well needed. Even people from rural areas come to their practice. They stand in queue for weeks in order to be in their consultation. You can see that even the highly educated clinicians would be happy if someone could automate some part of their job in order to free them up from some part of the burden.

As number of population in the world grow, more people in the rural areas will need help of well trained doctors and clinics in big cities will become even more overloaded.

How can we help?

Automation of DR screening can help us detect and prevent this disease among people living in rural areas, where help of trained clinicians is missed most. Imagine installing a medical instrument in a pharmacy in a remote area, which can take a photo of retina of a patient and diagnose whether he/she has DR, if yes, how severe the disease is in the eye.

In this blog post, I will show you how I trained a machine learning model to detect DR from retinal image of an eye automatically and also rate its severity. You can watch the following video, if you would like to see the step-by-step video demo:

Install machine learning tools

I used Intelec AI to train a diabetic retinopathy detector. You can download and install it from here for free.

Data

I used the data from the recent APTOS 2019 Blindness Detection challenge on Kaggle. It contains a large set of high-resolution retina images taken under a variety of imaging conditions. Clinicians had rated the presence of diabetic retinopathy in each image between 0 and 4, according to the following scale:

0 — No DR
1 — Mild
2 — Moderate
3 — Severe
4 — Proliferative DR

So I downloaded the dataset from the Data page of the competition, uploaded it to Intelec AI and extracted it.

Download data from Kaggle

Let’s see what our dataset looked like:

Images from class 0 (no DR)

Above you see images of class ‘0’ (no DR). Retina seems clear without any visible artifacts. We can also see that different classes have different number of images; while class 0 has 1805 images, class 3 has only 193.

The following images are from class 3 (severe DR). There you can see many yellow spots (hard exudates) and some dark red spots near vessels (blood leaks).

Images from class 3 (severe DR)

Training first model

After the data exploration, I created a training using “Deep image classifier”. “Deep image classifier” is a big neural network, hence it can take some time to train it but it will achieve a good accuracy.

But there was a problem, images were big (average resolution 2100x1500), which, if used as given, might have slowed down our training significantly. I solved this problem by shrinking all images 10 times. Shrinking the training images can decrease accuracy of final model but it is usually a good idea to start working on small images, before using the original images to get best accuracy.

Create training

Then I started the training and waited until it finished. I could the the training progress live and see how the accuracy increased and the loss decreased.

Live statistics about training metrics

After the training finished, I checked the training summary to see the final statistics about the training and model performance.

Training summary

As you can see, the training ran 23 hours 3 minutes 15 seconds and achieved 80% accuracy.

Improving accuracy

Could I do better? I knew that some of the artifacts in the images were tiny (for example, small blood leaks and yellow spots). They might have disappeared when I shrinked the images too much. So I hoped that if I shrinked the images less, I could restore some of the information, which I lost by shrinking the images 10 times. Hence I went ahead and decreased the shrink factor to 5, then I let the training run more. The result was as expected, it took more time for the training to finish but it achieved a higher accuracy.

Final training loss and accuracy
Additional statistics about the trained model

Test final model

85.4% accuracy seemed good to me. So I deployed it to test how it works on the test images. One of the results from the test set looked like this:

The above image was rated as class 3 (severe DR). You can also see the activation map, which shows which parts of the image the model gave more attention to while evaluating the severety of DR — the bright spots got more attention than the dark ones.

Summary

I was able to train a diabetic retinopathy detector, which achieved 85.4% accuracy. I also learned that increasing the image resolution can improve the model accuracy considerably if the spots of interest on the image are small.

That’s it from my side. I hope you found the blog post interesting and hopefully also learned something. Take care, until the next time.

References

  1. Installation of Intelec AI
  2. APTOS 2019 Blindness Detection on Kaggle
  3. Majority of US adults have eye problems but don’t see a doctor to correct them

--

--