This project includes a Flask-based web application for detecting brain tumors using a pre-trained TensorFlow Lite model and a training pipeline for training the model using MRI scan images.
The web application allows users to upload MRI scans of their brains, and the application predicts whether a tumor is present or not.
- Upload MRI scans of brain images.
- Predict whether a brain tumor is present or not.
- Display prediction results to the user.
-
Clone the repository:
git clone https://github.com/danieletukudo/Brain_Tumor_Detection.git
-
Install the required dependencies:
pip install -r requirements.txt
-
Download the pre-trained TensorFlow Lite model and place it in the project directory.
-
Run the Flask application:
python app.py
-
Open your web browser and navigate to
http://localhost:7017
. -
Upload an MRI scan image of a brain.
-
Click the "Upload" button to make the detection.
-
Wait for the prediction result to be displayed.
The training pipeline includes data augmentation, model training, and quantization steps.
The model is implemented using the VGG16 architecture, pre-trained on the ImageNet dataset. It consists of convolutional layers followed by fully connected layers. The model outputs probabilities for two classes: "No Brain Tumor Detected" and "Brain Tumor Detected".
-
Data Augmentation: Data augmentation is performed using the
ImageDataGenerator
class from TensorFlow. It includes random transformations such as rotation, horizontal and vertical flips, shear, and shift. -
Model Training: The model is trained using the augmented data generated by the
ImageDataGenerator
. Training is performed using thefit
method of the model, with specified number of epochs and batch size. -
Model Quantization: After training, the model can be quantized to reduce its size while preserving accuracy. Quantization is performed using TensorFlow Lite, which converts the model to a quantized TensorFlow Lite format.
To train the model and perform quantization, execute the training
class:
if __name__ == "__main__":
trained_model_name = "1model.h5"
train = training()
training = False # Set to True to perform training
if training:
train.training(epochs=100, train_path="dataset/train",
val_path="dataset/val",
input_shape=(100, 100, 3),
trained_model_name="trained_model_name")
train.quantize_model(trained_model_name)
- The TensorFlow Lite model was trained using TensorFlow and converted to the TensorFlow Lite format.
- The model and Flask web application developed by me (Daniel Etukudo).