Computer Vision in healthcare: Detection of fractures

Vishnu Nandakumar
Analytics Vidhya
Published in
4 min readMay 16, 2021

Since the emergence of machine learning the world has evolved a lot to accommodate AI systems in almost all sectors. One of the major sector that has seen tremendous improvements in the health care sector where machine learning has helped in solving some of the critical scenarios. Be it from analysing an x-ray to detection of tumours in vital organs, computer vision has helped a lot in the healthcare sector. In this article we will look at how we can leverage object detection to analyse fractures in human hands. If you see an x-ray sometimes you might not be able to detect the fractures correctly unless you are a trained physician or a doctor. So here let us see if we can try to detect them using deep learning methods.

Detecto:

For this experiment, I have used a python library named “detecto” which is a wrapper to implement object detection algorithm in few lines of codes. The backend of this library is written in PyTorch and for now only FasterRCNN is available on for detection and training purposes. Please read through various blogs for more information on different object detection models and their differences.

I retrieved the dataset for this experiment from kaggle. Let us look at some of the images to see for ourselves if we can detect the fractures in those images.

To be honest on the naked eye, I could not actually see any fractures on the first go, it might take some time to actually detect for me. But by leveraging deep learning methods we can actually easily detect the fractures efficiently and quickly without spending time and straining our eyes.

The annotations for the dataset is in Pascal VOC format which can be converted in csv format for training the model. Once we have converted the annotations we can start training the model in just 4 lines of code as follows.

In the above gist, first I have converted the XML annotations to csv format for it to be consumable to the library. Then created the datasets with training and validation images. And as the final step create a dataloader for the datasets, define the classes for the model and train it without any further hassle. Easy one right? I have also plotted the losses incurred while training to monitor if the model is learning or not.

Loss vs Epoch

As we can see above the model has trained well and the loss is observed to be in decline with increase in each epoch. Okay then, lets go and analyse our model on different images.

Below are some results that I gathered from inferencing the model by keeping a threshold of 0.4. We can easily see that the model has trained well and it is able to catch the fractured location precisely. The model can be further fine tuned using augmentation of training data and we can keep a higher degree of confidence score rather than 0.4.

So I had a little thought on if this model can be further checked on other x-ray images with fractures, for eg: be it leg, arm or any other bone region in our body. I have this thought because all the x-rays have similar feature sets like they all are grayscale, has intensive bright regions for bone while the background will be black, so I think it could work also on other x-rays also. Why can’t we check for ourselves then once.

Below is image with fracture in the lower leg region, here it is easily detectable for the naked eye, and also our model was able to detect it without any issue

Below is an x-ray image of arm with fracture on the middle region of arm. Again it was captured by the model

But the limitation here is I have kept the threshold to a lesser number, 0.2 in this case. Adding more data and choosing another algorithm could yield better results. You can look into this notebook on how it is implemented and please do give suggestions.

So guys, thanks for reading the post and I hope it has been a good one for you.

Stay safe during this pandemic and let us get over this very soon.

--

--

Vishnu Nandakumar
Analytics Vidhya

Machine Learning Engineer, Cloud Computing (AWS), Arsenal Fan. Have a look at my page: https://bit.ly/m/vishnunandakumar