Deep Learning Oral Cancer Detection

Avatar of Ajeng Dwi Jayanti.
Avatar of Ajeng Dwi Jayanti.

Deep Learning Oral Cancer Detection

Data Scientist
Boyolali Regency, Central Java, Indonesia

DEEP LEARNING  "Oral Cancer Detection Using CNN Based On Android Application"


Oral cancer is a type of cancer that grows and develops around the mouth to the oral cavity or oropharynx. At present, the level of public awareness and concern for oral cancer is still low, this is due to a lack of education about the dangers of oral cancer. In addition, the cost of screening for oral cancer is still relatively expensive. In addition, the use of Android applications has expanded today, involving various age groups from teenagers to adults. Through this android application, all activities that are usually carried out through the website can run more practically. One of them is the development of an android-based early detection of oral cancer application called OralVision which is useful for early detection of oral cancer for the general public. Where with this application, it is hoped that the public can perform early oral cancer screening without incurring high costs. The application used in developing this research is Android Studio and uses Deep Learning in its development. In this article, we will discuss the deep learning code utilized in oral cancer detection.


First, I used an oral cancer dataset from Kaggle. Then, I will discuss the steps in writing the code to create a deep learning model.


The next step is to :


  • Open Google Colaboratory and Access the dataset file on Google Drive


from google.colab import drive

drive.mount('/content/drive')


  • Import the required modules and classes (code attached) and create a directory for the training data.


train_dir = '/content/drive/MyDrive/Data/Dataset'


  • Classifying the classes into two


Labels = ['cancer', 'non_cancer']

print ("class : ")

for i in range(len(Labels)):

   print (i, end = " ")

   print (Labels[i])

print('Number of classes:',len(Labels))


  • Selecting the TensorFlow module to be used and specifying the image size.


module_selection = ("mobilenet_v2", 224, 1280)

handle_base, pixels, FV_SIZE = module_selection

MODULE_HANDLE = "https://tfhub.dev/google/tf2preview/{}/feature_vector/2".format(handle_base)

IMAGE_SIZE = (pixels, pixels)

BATCH_SIZE = 16


  • Building training and validation generators that generate batches of augmented image data according to the specified configuration using an image data generator.


  • Utilizing feature extractor layers from TensorFlow Hub.


feature_extractor = hub.KerasLayer(

MODULE_HANDLE,input_shape=IMAGE_SIZE+(3,),

output_shape=[FV_SIZE])


  • Updating the weights of the feature extractor layers based on the dataset using fine-tuning.

do_fine_tuning = False

if do_fine_tuning:

feature_extractor.trainable = True

  for layer in base_model.layers[-30:]:

   layer.trainable =True

 

else:

  feature_extractor.trainable = False


  • Constructing a neural network model using the specified layers. This model will be used to train and predict image classes based on the provided dataset.


  • The neural network model is compiled with the Adam optimizer configured with a specific learning rate, using the categorical cross-entropy loss function, and accuracy as the evaluation metric. The model is ready to be trained and evaluated using training and validation data.


LEARNING_RATE = 0.001

model.compile(

  optimizer=tf.keras.optimizers.Adam(learning_rate=LEARNING_RATE),

   loss='categorical_crossentropy',

   metrics=['accuracy'])


  • Using the OS module and setting the environment variable TF_XLA_FLAGS to configure TensorFlow XLA.


import os

os.environ['TF_XLA_FLAGS'] = '--tf_xla_enable_xla_devices=false'


  • Configuring the model for training using the Adam optimizer, categorical cross-entropy loss function, and accuracy as the evaluation metric.


model.compile(optimizer='adam',

loss='categorical_crossentropy', metrics=['accuracy'])


  • Training the model by running it through 15 epochs.

EPOCHS=15

history = model.fit(

     train_generator,

     steps_per_epoch=train_generator.samples//train_generator.batch_size,

     epochs=EPOCHS,

     validation_data=validation_generator,

    validation_steps=validation_generator.samples//validation_generator.batch_ size)


  • Visualizing graphs to illustrate the changes in accuracy and loss on training and validation data during each step of the model training


  • Loading random images from the validation dataset, processing them, making predictions using the previously trained model, and displaying the images along with their predictions in a graph.


  • Obtaining a classification report that presents evaluation metrics for each class on the validation data.


  • Visualizing using a Confusion Matrix.


  • Saving the trained model to a file by combining the predefined storage path with a timestamp.

import time

t = time.time()

  export_path = "/tmp/saved_models/{}".format(int(t))

tf.keras.models.save_model(model, export_path)


  • Loading the saved model and confirming whether the loaded model is the same as the initially saved model.


export_path

reloaded = tf.keras.models.load_model(export_path, custom_objects= {'KerasLayer':hub.KerasLayer})


  • Making predictions on images using the model that has been reloaded after being saved previously.


def predict_reload(image):

   probabilities = reloaded.predict(np.asarray([img]))[0]

   class_idx = np.argmax(probabilities)

  return {Labels[class_idx]: probabilities[class_idx]}


  • Selecting a few random images from the validation dataset, making predictions using the reloaded model, and displaying the images along with the results in a graph.


  • The reloaded model will be converted into a Tensorflow Lite (tflite) model.


The deep learning code will generate a usable TFLite model for Android applications in detecting oral cancer. The functionality of this deep learning code involves detecting images stored on the phone or images captured directly. The code will output accuracy in percentage form. For users, this indicates whether oral cancer is detected with a high or low level of confidence.


For the complete code of this deep learning project, you can view it on the GitHub link

https://github.com/ajengdwija/Deep-Learning---Oral-Cancer-Detection


Thank You !




 


"Contains deep learning code for creating an Oral Cancer Detection application using CNN (Convolutional Neural Network)."
Avatar of the user.
Please login to comment.

Published: Nov 13th 2023
43
6
0

Tools

python
Python
github
GitHub

Share