This is an end-to-end deep learning project focusing on developing a tool to predict the presence of brain tumors from MRI scans, adhering to MLOps best practices. It involves data collection and preprocessing with TensorFlow datasets, model training with TensorFlow, model serving and version management using TensorFlow Serving, and deployment through a FastAPI endpoint with a React.js front-end for user interaction. The end-to-end pipeling is shown in the architecture diagram below.
Figure 1: End-to-End Architecture.
Before discussing the problem and methodology, here’s a quick look at how the system works. The images below show the interface for uploading MRI scans and the model’s prediction results
Figure 2: Interface for uploading MRI scans for tumor detection.
Figure 3: Prediction of Meningioma Tumor with confidence score.
Interpreting MRI scans to detect brain tumors can be challenging because different brain diseases may appear similar. For example, an aggressive glioblastoma might resemble cancer that has spread to the brain from another part of the body. This is a problem because early and accurate diagnosis is crucial for ensuring proper treatment and improving patient outcomes. Therefore, a system that can accurately detect brain tumors from these scans can serve as a decision support tool, streamlining the diagnostic process and enabling faster, more informed treatment decisions.
The dataset used is available on Kaggle: Brain Tumor Classification (MRI). It contains MRI scans of brain tumors, divided into training and testing sets, each with four classes:
- No Tumor
- Pituitary Tumor
- Meningioma Tumor
- Glioma Tumor
- Preparing Images for Modeling: Images were transformed into tensors and converted to RGB format.
- Data Augmentation: To improve generalization, random rotations and contrast adjustments were applied, generating artificial samples to handle different image orientations and contrasts.
- Normalization: All pixel values were scaled by dividing by 255, ensuring values fell between 0 and 1.
A convolutional neural network with the following architecture was trained on the training data:
- Four convolutional layers to capture complex patterns in MRI images.
- One fully connected layer for classification, with a dropout rate of 0.5 to reduce overfitting.
The model currently achieves a 61% accuracy on the test dataset obtained from Kaggle, which was held out during model training for unbiased evaluation.
Multiple versions of the model were saved throughout experimentation, and TensorFlow Serving was used to manage and serve them. The system was configured to automatically mount the latest model version within a TensorFlow Serving Docker container, ensuring seamless updates without manual intervention.
A FastAPI endpoint was created, allowing users to upload MRI images for inference and receive predictions from the trained model. The API supports batch processing, enabling efficient handling of multiple user requests simultaneously. This helps in scenarios where many users interact with the model at the same time. A user-friendly web interface built with React.js was integrated with the FastAPI endpoint. It enables users to easily upload MRI scans via their web browsers. Once the images are uploaded, the model predictions are displayed alongside the confidence scores.
Model Improvements
- Exploring Advanced Architectures: To improve the current model accuracy (61%), established architectures such as ResNet could be explored. These architectures have achieved good performance in similar tasks by allowing deeper models to extract more complex features without suffering from degradation in performance. Implementing such architectures could significantly improve feature extraction and classification accuracy.
- Hyperparameter Tuning: Experimenting with hyperparameters like learning rates, batch sizes, and dropout rates may enhance both model performance and generalization.
- Transfer Learning: Leveraging pre-trained models and fine-tuning them on the specific dataset may not only accelerate training but also improve accuracy by utilizing the learned features from larger datasets.
-
Clone the Repository
git clone https://github.com/Abdul-AA/Brain-Tumor-Classifier.git cd Brain-Tumor-Classifier
-
Run TensorFlow Serving with Docker after downloading its Docker image. Run the following commands:
docker pull tensorflow/serving docker run -t --rm -p 8501:8501 \ -v "/<your-root-path>/Brain-Tumor-Classifier:/Brain-Tumor-Classifier" \ tensorflow/serving --rest_api_port=8501 --model_base_path=/Brain-Tumor-Classifier/saved_models
Make sure the TensorFlow Serving instance is running on
http://localhost:8501
. -
Install Backend Dependencies and Run FastAPI
pip3 install -r api/requirements.txt cd api uvicorn main:app --reload --host localhost --port 8000
-
Set Up and Run the Frontend
Navigate to the frontend directory, install dependencies, fix potential issues, and start the frontend server:
cd ../frontend npm install --from-lock-json npm audit fix npm run start
This will start the frontend on
http://localhost:3000
. -
Upload MRI Scans for Prediction
Once the application is running, you can drag and drop MRI images into the app to get a tumor classification prediction. The results, including the predicted tumor type and confidence level, will be displayed in the app.
- Replace
<your-root-path>
with the absolute path to the project directory on your machine wherever applicable. - Make sure TensorFlow Serving is running on
http://localhost:8501
and the FastAPI backend is running onhttp://localhost:8000
before interacting with the frontend.