Oral Cancer Detection
Oral cancer is a serious health condition where early identification can play an important role in further medical evaluation and treatment. With the growth of Artificial Intelligence and Deep Learning, image-based classification systems are increasingly being explored for research and educational applications in medical image analysis.
Oral Cancer Detection Using Deep Learning is a Python-based project that uses a custom XceptionNet convolutional neural network to classify oral histopathological images. The trained model processes an uploaded image and produces one of two results: Cancer Detected or No Cancer Detected. The application also provides a confidence percentage and Grad-CAM visualization to highlight image regions that influenced the model’s prediction.
The complete system is integrated with a Flask web application, making the deep learning model accessible through a responsive browser-based interface. The project is designed for educational and research purposes and should not be considered a replacement for professional medical diagnosis.
Table of Contents
Project Overview
| Project Detail | Information |
|---|---|
| Project Name | Oral Cancer Detection Using Deep Learning |
| Primary Language | Python |
| Framework | Flask |
| Deep Learning | TensorFlow / Keras |
| Model | Custom XceptionNet |
| Classification | Binary Classification |
| Image Processing | Pillow, OpenCV |
| Machine Learning | scikit-learn |
| Frontend | HTML5, CSS3, Bootstrap 5, JavaScript |
| Visualization | Grad-CAM, Matplotlib |
| Testing | pytest |
| Deployment | Docker |
| Developer | UPDATEGADH |
Key Features
Image Upload
Users can upload histopathological images through the web interface. The application supports drag-and-drop or normal file browsing and provides an instant client-side preview before prediction.
Image Validation
The application validates uploaded files before sending them to the prediction pipeline. Validation includes file extension checking, image decoding, file-size limits, and image-dimension checks.
Custom XceptionNet Model
The project implements a custom XceptionNet architecture using depthwise separable convolutions. The architecture contains entry, middle, and exit flows followed by global average pooling and classification layers.
Binary Cancer Classification
The trained network performs binary classification and returns either Cancer Detected or No Cancer Detected, along with a confidence percentage.
Grad-CAM Visualization
Grad-CAM is used to create a heat-map overlay showing the regions of the image that contributed to the model’s decision. This provides an additional visual explanation of the prediction.
Out-of-Distribution Image Rejection
The project includes an OOD guard that can reject images that do not resemble the expected histopathological input. This helps prevent ordinary photos, screenshots, or unrelated graphics from receiving an inappropriate cancer classification.
Tiled Inference
Large histopathological images can be divided into smaller 299×299 tiles at native resolution. The individual tile predictions are then aggregated to produce the final result.
REST API
The application exposes a REST endpoint at POST /api/v1/predict, allowing other applications or services to submit images programmatically.
Responsive Web Interface
The frontend uses Bootstrap 5 and is designed to work across desktop, tablet, and mobile screen sizes.
Evaluation and Reporting
The training pipeline generates several evaluation metrics, including accuracy, precision, recall, F1 score, specificity, ROC AUC, average precision, and a confusion matrix.
Dataset Used in the Project
The project documentation provides a downloader for an openly licensed oral histopathology dataset. The default 400x subset contains 696 images, consisting of 201 normal epithelial images and 495 OSCC images. The dataset contains H&E-stained slides from 230 patients.
The dataset is organized into two directories:
dataset/
├── cancer/
│ ├── image1.jpg
│ └── ...
└── non_cancer/
├── image1.jpg
└── ...
The preprocessing pipeline resizes images to 299×299 pixels. The dataset split is stratified, with the default distribution being 70% training, 15% validation, and 15% testing.
The project documentation identifies the source as Rahman, Tabassum Yesmin (2019), Histopathological imaging database for Oral Cancer analysis, Mendeley Data V2, under CC BY 4.0.
How to Download
Get This Project
The complete package is available so you can run, study, and submit it with confidence. It includes:
- Full Source Code
- Project Report
- Synopsis
- PPT Presentation
For any queries or a quick response, reach out on WhatsApp: +91 79834 34684
Screenshot and Demo Video






Why Tiled Inference Is Important
One of the interesting parts of this project is its tiled inference approach. Histopathological images can contain fine cellular details that may be lost when an entire high-resolution image is directly resized to the model’s 299×299 input size.
The project therefore supports dividing larger images into 299×299 tiles while maintaining native-resolution information. Individual tiles are classified and their predictions are aggregated.
The documentation recommends splitting tiles according to their original source image rather than randomly distributing tiles across training and testing datasets. This reduces the possibility of nearly identical tissue regions appearing in different dataset splits.
For aggregation, the default top-k approach considers the most suspicious tiles instead of simply averaging every tile. This is useful for the project’s intended scenario because abnormal tissue may occupy only a small region of a larger image.
Deep Learning Architecture
The project uses a custom XceptionNet-inspired architecture. The input image has a size of 299×299×3.
The network is divided into three major flows:
- Entry Flow: Initial convolution layers followed by separable convolution blocks and residual connections.
- Middle Flow: Repeated separable convolution blocks with residual connections.
- Exit Flow: Higher-level feature extraction followed by global average pooling and classification layers.
The final layers include global average pooling, dropout, a dense layer, batch normalization, another dropout layer, and a single sigmoid output.
The model output represents the probability of the non_cancer class. The application then uses the configured decision threshold to determine the displayed result.
Image Preprocessing
Consistency between training and prediction is important in any machine learning application. This project uses a single preprocessing module shared by the training pipeline and Flask inference service.
Load Image
↓
EXIF Correction
↓
Convert to RGB
↓
Resize to 299×299
↓
Convert to float32
↓
Scale to [-1, 1]
↓
Create Batch
The project also contains a test that checks whether the TensorFlow training pipeline and Pillow-based inference pipeline generate near-identical processed arrays.
Training the Model
The training pipeline is provided through a command-line script. Transfer learning is recommended for the relatively small medical image dataset.
python training/train_model.py --arch transfer --lr 1e-4 --epochs 30 --cache
The training system supports configurable epochs, batch size, learning rate, dropout, model width, middle-flow blocks, data augmentation, class weighting, fine-tuning, grouped splitting, and image caching.
During training, augmentation can include image flips, rotations, zoom, translation, and brightness or contrast variations. Class weighting can also be used to compensate for class imbalance.
Evaluation
After training, the project can evaluate the model using:
python training/evaluate.py --model model/oral_cancer_model.h5
The evaluation pipeline reports accuracy, precision, recall, F1 score, specificity, ROC AUC, average precision, and confusion-matrix results. It also reports cancer recall, representing the proportion of true cancer cases identified by the model.
These metrics are useful for understanding model performance during development and research. They should not be interpreted as evidence that the system is clinically validated.
Flask Web Application
The trained model is connected to a Flask application that provides a simple browser-based workflow.
The main routes include:
| Route | Purpose |
|---|---|
/ | Project introduction, features, and workflow |
/predict | Image upload and prediction interface |
POST /predict | Processes the uploaded image and displays the result |
/about | Project objective, architecture, technologies, and model information |
The result page displays the uploaded image, prediction, confidence percentage, class probabilities, Grad-CAM visualization, and a medical disclaimer.
REST API
The project also provides an API endpoint for programmatic image prediction.
curl -F "image=@slide.jpg" http://localhost:5000/api/v1/predict
A successful response contains the prediction label, confidence, cancer and non-cancer probabilities, decision threshold, image information, and inference time.
The application also provides health and information endpoints:
GET /api/v1/health– Checks whether the application and model are available.GET /api/v1/info– Provides information about the input/output contract and limits.
Project Setup in VS Code
To run the project locally, first open the project folder in Visual Studio Code and create a Python virtual environment.
python -m venv .venv
Activate the environment on Windows:
.venv\Scripts\activate
Install the required dependencies:
pip install -r requirements.txt
Download the project dataset:
python training/download_dataset.py
Train the model using transfer learning:
python training/train_model.py --arch transfer --lr 1e-4 --epochs 30 --cache
Calibrate the domain guard:
python training/calibrate_domain_guard.py
Finally, start the Flask application:
python app.py
Once the server starts, open http://127.0.0.1:5000 in your browser.
Testing
The project includes a pytest-based testing suite covering preprocessing, upload validation, model services, prediction behavior, Grad-CAM, Flask routes, and REST API functionality.
pytest
For faster testing without slow network-building tests:
pytest -m "not slow"
Coverage can be generated using:
pytest --cov=app --cov=training --cov-report=html
Deployment with Docker
The project includes Docker configuration for deployment. A production secret key can be generated before starting the containers.
echo "SECRET_KEY=$(python -c 'import secrets; print(secrets.token_hex(32))')" > .env
docker compose up --build
The trained model is mounted separately from the Docker image, allowing a new model to be deployed without rebuilding the complete application.
Technologies Used
- Python
- Flask
- TensorFlow / Keras
- Custom XceptionNet
- NumPy
- Pillow
- OpenCV
- scikit-learn
- Matplotlib
- HTML5
- CSS3
- Bootstrap 5
- JavaScript
- pytest
- Docker
Final Thoughts
Oral Cancer Detection Using Deep Learning is a strong example of combining deep learning with a real web-based workflow. Instead of stopping at model training, the project connects a custom XceptionNet architecture with Flask, image validation, Grad-CAM explanations, tiled inference, OOD rejection, evaluation reports, REST APIs, automated tests, and Docker deployment.
From a student’s perspective, this project provides practical exposure to both Deep Learning and Full-Stack AI application development. It can help learners understand the complete journey from preparing an image dataset and training a CNN to serving predictions through a responsive web application.
The project should remain within its documented educational and research scope, particularly because medical image classification requires considerably more validation before it can be considered for real-world clinical decision-making.
Keywords
Oral Cancer Detection Using Deep Learning, Oral Cancer Detection Project, Oral Cancer Detection Using Python, Deep Learning Medical Image Classification, XceptionNet Project, Oral Histopathology Image Classification, Cancer Detection Using CNN, TensorFlow Oral Cancer Detection, Keras Deep Learning Project, Flask Deep Learning Project, Grad-CAM Cancer Detection, Medical Image Analysis Project, AI Cancer Detection Project, Python Deep Learning Project Oral Cancer Detection Using Deep Learning, Oral Cancer Detection Project, Oral Cancer Detection Using Python, Deep Learning Oral Cancer Detection, Oral Cancer Classification, Oral Cancer Detection Using CNN, XceptionNet Oral Cancer Detection, Custom XceptionNet, Oral Histopathology Image Classification, Histopathological Image Classification, Cancer Detection Using Deep Learning, TensorFlow Cancer Detection, Keras Cancer Detection Project, Flask Deep Learning Project, Grad-CAM Cancer Detection, Medical Image Analysis Using AI, AI Based Cancer Detection, Deep Learning Medical Project, Python AI Project, Oral Cancer Prediction System