A.I. Based Cavity Detection System

Source: Deep Learning on Medium

A.I. Based Cavity Detection System

Here we are implementing the cavity detection system using deep learning techniques

Business problem and Introduction:-

In 21 st century 80–90% peoples are suffered from dental problems and early research shows that the dental problem is related to the cavity. Nowadays peoples are so much busy in their work hence they do not care about themselves this leads to health problems including dental problems.

Image Link is here

Early diagnosis is very important for maintaining dental problems. Dentists use laser-technology for diagnosis of cavity this is very costly and these results are highly negative that dentists do not rely on results instead they relying on visual inspection. Artificial intelligence helps for identifying dental problems and also it predicts better solutions with the help of dentists to the patients.

Artificial intelligence helps for identifying dental problems and also it predicts better solutions with the help of dentists to the patients. dentists to the patients. Artificial Intelligence has more power to save a large amount of data which is useful for individuals need. Artificial Intelligence fill the gap between doctors and laser-techniques

Cavity Types:-

Image is found here

Here We have to classify the the images as per cavities. There are total 6 types of cavities. based on this six type we have to classify or predict the probabilities of per classes

Data Collection :

Data will be collected using the following methods

a.Primary Data:Data regarding teeths and dental disease are collected from various dentists

b.Secondary Data: Data about Artificial intelligence will be collected from research journals and e-resources

The Collected Data can be stored in our own server with there location (path) in csv format. We collected total upto 300 images of cavities

Fig:- Collection of various types of Cavity Images
  • Note:- Here i implemented model only for 2 classes i.e, for class-I and class-II

Techniques Used

  1. Fast.ai (https://www.fast.ai)
  2. CNN (Resnet34)



Fastai library is pretty new, but it’s getting an extraordinary amount of traction. It’s making a lot of things a lot easier, but it’s also making new things possible. So really understanding the fastai software is something which is going to take you a long way.
So how does it compare? There’s only one major other piece of software like fastai that tries to make deep learning easy to use and that’s Keras. Keras is a really terrific piece of software, we actually used it for the previous courses until we switch to fastai. It runs on top of Tensorflow.

Importing Fast.ai :-

from fastai.vision import *
import numpy as np
import pandas as pd

Making folders for each class:-

folders = ['Class-I', 'Class-II']
files = ['Class-I', 'Class-II']
classes = ['Class-I','Class-II']
path = Path('data/Cavity')

Folder Structure must be as followes:-

Fig:- Folder Structure

Getting Image data from folders:-

Getting information from Images
Fig:- Height of image
Fig-Width Of image

Image Data generators in Fast.ai:-

This code generates images and there labels
Fig-Displaying Some random images from above code with there classes

Preprocessed Images:-

Before PreProcessing
After PreProcessing

Model Architecture(resnet34):-

Fig Resnet34 Image link here

One of the problems ResNets solve is the famous known vanishing gradient. This is because when the network is too deep, the gradients from where the loss function is calculated easily shrink to zero after several applications of the chain rule. This result on the weights never updating its values and therefore, no learning is being performed. With ResNets, the gradients can flow directly through the skip connections backwards from later layers to initial filters.

Creating the CNN learner:-(resnet34 model)

learn = create_cnn(data, models.resnet34, metrics=[error_rate, accuracy])

Finding the appropriate learning rate

Fast.ai gives you the functionality for the finding the optimal learning rate. the code for this as

Fig-learning rate vs Loss

Initialization of the model:-

In whole process we are using transfer learning. we are applying the weights of the resnet34 model. so its easier to us for classifying the things

interp = ClassificationInterpretation.from_learner(learn)

Fitting the model:-


here we can say that train loss is decreasing as well as our accuracy is improving per epochs. and also see the time for execution. Fast.ai is very fast as per name and as compared to tensorflow and keras. By using fast.ai we are getting better results than any other techniques. Thats why i am using the fast.ai implementation for blog

Train and validation loss:-

Train and validation loss for per batches

Printing Top Losses/Most confused images:-

interp.plot_top_losses(21, figsize=(15,11), heatmap=False)

Exporting the model:-


Loading the model:-

learn = load_learner(path)

Predicting the single point:-

defaults.device = torch.device(‘cpu’)
img = open_image('Test5.jpg')
pred_class,pred_idx,outputs = learn.predict(img)