|
1 |
| -# how to run this app. |
2 |
| -- clone the repo |
3 |
| -- move to folder BRAIN TUMOR DETECTION, |
4 |
| -- create a virtual env using `virtualenv 'envirnoment name'.` |
5 |
| -- Now type `. \Scripts\activate` to activate your virtualenv venv |
6 |
| -- install packages required by the app by running the command `pip install -r requirments.txt` if you found error of torch or torch-vision libraries so your can download it from below commands. |
7 |
| -<b><i>for windows cpu torch library command with conda</i></b>: conda install pytorch torchvision cpuonly -c pytorch |
8 |
| -<b><i>for windows cpu torch library command with pip</i></b>: pip install torch==1.6.0+cpu torchvision==0.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.html |
| 1 | +# Brain Tumor Detection (End-to-End) |
9 | 2 |
|
10 |
| -For Linux, Mac,CUDA version for windows and much more you can visit <a href = "https://pytorch.org/">Link</a> |
11 |
| -- now run the app using `flask run`. |
12 |
| -- if all things works fine so you can view running web application in your browser at port 5000. |
| 3 | +## Introduction |
13 | 4 |
|
| 5 | +This project is a **Flask web application** for detecting brain tumors from MRI images using a deep learning model built with **PyTorch**. Users can upload MRI images through the app, and the model will classify them as either tumor or non-tumor. The goal of this project is to provide an intuitive interface for medical professionals to quickly identify potential brain tumors. |
14 | 6 |
|
15 |
| -# Download the model file from [https://drive.google.com/file/d/1LJG_ITCWWtriLC5NPrWxIDwekWbhU_Rj/view?usp=sharing](https://drive.google.com/file/d/1LJG_ITCWWtriLC5NPrWxIDwekWbhU_Rj/view?usp=sharing) and add to model directory in order to run the project. |
| 7 | +### Dataset: |
| 8 | +- The dataset contains MRI images, divided into two categories: **tumor** and **non-tumor**. |
| 9 | +- Preprocessing techniques are applied to the dataset to ensure optimal model performance. |
| 10 | + |
| 11 | +## Project Overview |
| 12 | + |
| 13 | +This end-to-end project consists of: |
| 14 | +1. **Data Loading**: Load MRI images for training, validation, and testing. |
| 15 | +2. **Data Preprocessing**: Apply normalization, resizing, and augmentation techniques. |
| 16 | +3. **Model Building**: Build a Convolutional Neural Network (CNN) using **PyTorch** to classify the MRI images. |
| 17 | +4. **Model Training**: Train the model on GPU (if available) to detect brain tumors. |
| 18 | +5. **Flask Web Application**: Develop a Flask app for user interaction, allowing image uploads for tumor detection. |
| 19 | +6. **Model Deployment**: Deploy the trained model within the Flask app. |
| 20 | +7. **Prediction**: Provide real-time predictions through the Flask web app. |
| 21 | + |
| 22 | +## Model Download and Directory Structure |
| 23 | + |
| 24 | +### Pretrained Model: |
| 25 | +You can download the pretrained model from the following link: |
| 26 | +[Brain Tumor Detection Model](https://drive.google.com/file/d/1LJG_ITCWWtriLC5NPrWxIDwekWbhU_Rj/view?usp=sharing) |
| 27 | + |
| 28 | +### Directory Structure: |
| 29 | +``` |
| 30 | +Brain-Tumor-Detection/ |
| 31 | +│ |
| 32 | +├── app/ |
| 33 | +│ ├── static/ # CSS, JS, and images for the Flask web app |
| 34 | +│ ├── templates/ # HTML templates for the Flask app |
| 35 | +│ └── app.py # Main Flask application |
| 36 | +│ |
| 37 | +├── model/ |
| 38 | +│ └── brain_tumor_model.pth # Pretrained PyTorch model |
| 39 | +│ |
| 40 | +├── data/ |
| 41 | +│ ├── train/ # Training MRI images |
| 42 | +│ ├── test/ # Testing MRI images |
| 43 | +│ |
| 44 | +├── src/ |
| 45 | +│ ├── dataset.py # Script to load and preprocess the dataset |
| 46 | +│ ├── model.py # CNN model architecture using PyTorch |
| 47 | +│ └── train.py # Script to train the model |
| 48 | +│ |
| 49 | +├── README.md # Project documentation |
| 50 | +└── requirements.txt # List of required Python packages |
| 51 | +``` |
| 52 | + |
| 53 | +## Setup Instructions |
| 54 | + |
| 55 | +### Step 1: Create a Virtual Environment |
| 56 | + |
| 57 | +Create a virtual environment to isolate the dependencies for this project. |
| 58 | + |
| 59 | +```bash |
| 60 | +# For Windows |
| 61 | +python -m venv venv |
| 62 | +venv\Scripts\activate |
| 63 | + |
| 64 | +# For macOS/Linux |
| 65 | +python3 -m venv venv |
| 66 | +source venv/bin/activate |
| 67 | +``` |
| 68 | + |
| 69 | +### Step 2: Install Required Libraries |
| 70 | + |
| 71 | +Install the dependencies listed in `requirements.txt`: |
| 72 | + |
| 73 | +```bash |
| 74 | +pip install -r requirements.txt |
| 75 | +``` |
| 76 | + |
| 77 | +### Step 3: Download the Pretrained Model |
| 78 | + |
| 79 | +Download the pretrained model from [this link](https://drive.google.com/file/d/1LJG_ITCWWtriLC5NPrWxIDwekWbhU_Rj/view?usp=sharing) and place it in the `model/` directory as `brain_tumor_model.pth`. |
| 80 | + |
| 81 | +### Step 4: Running the Flask App |
| 82 | + |
| 83 | +To start the Flask web app, navigate to the `app/` directory and run the `app.py` file: |
| 84 | + |
| 85 | +```bash |
| 86 | +cd app/ |
| 87 | +python app.py |
| 88 | +``` |
| 89 | + |
| 90 | +The app will be hosted at `http://127.0.0.1:5000/`. You can open the URL in your browser and upload MRI images to receive predictions. |
| 91 | + |
| 92 | +## Flask Web Application Features |
| 93 | + |
| 94 | +- **Image Upload**: Users can upload MRI images through the web interface. |
| 95 | +- **Tumor Detection**: The uploaded image is fed into the model to predict whether a tumor is present. |
| 96 | +- **Result Display**: The result is displayed on the same page with either a "Tumor" or "Non-Tumor" label. |
| 97 | + |
| 98 | +## Model Architecture |
| 99 | + |
| 100 | +The model used in this project is a **Convolutional Neural Network (CNN)** built using **PyTorch**. The architecture has been optimized for image classification tasks and consists of several layers: |
| 101 | + |
| 102 | +### Key Layers: |
| 103 | +- **Convolutional Layers**: For feature extraction from MRI images. |
| 104 | +- **Max Pooling Layers**: For downsampling and reducing spatial dimensions. |
| 105 | +- **Fully Connected Layers**: For classification. |
| 106 | +- **Softmax Activation**: To produce the output probability of each class (Tumor/Non-Tumor). |
| 107 | + |
| 108 | +## Data Preprocessing |
| 109 | + |
| 110 | +To ensure the CNN model performs optimally, the following preprocessing steps are applied: |
| 111 | +- **Grayscale Conversion**: All MRI images are converted to grayscale. |
| 112 | +- **Resizing**: Images are resized to 64x64 pixels for uniformity. |
| 113 | +- **Normalization**: Each pixel value is normalized to a range of [0, 1]. |
| 114 | +- **Data Augmentation**: Techniques like random rotation, flipping, and zooming are applied to expand the dataset and prevent overfitting. |
| 115 | + |
| 116 | +## Conclusion |
| 117 | + |
| 118 | +This Flask web app provides an end-to-end solution for detecting brain tumors using MRI images. With a simple user interface and a powerful backend, it can serve as a diagnostic tool for medical professionals. The project can be further enhanced by incorporating additional data, improving model accuracy, or deploying the app to a cloud platform like Heroku. |
| 119 | + |
| 120 | +## Future Enhancements |
| 121 | + |
| 122 | +- **Integration with Cloud Platforms**: Deploy the app on Heroku or AWS for wider accessibility. |
| 123 | +- **Mobile Application**: Develop a mobile app to upload MRI images and get predictions on the go. |
| 124 | +- **Transfer Learning**: Incorporate pre-trained models like ResNet to further improve accuracy. |
| 125 | + |
| 126 | +--- |
0 commit comments