Skip to content

This project implements an automated brain tumor detection system using the YOLOv10 deep learning model. It utilizes a robust MRI dataset for training, enabling accurate tumor identification and annotation. An interactive Gradio interface allows users to upload images for real-time predictions, enhancing diagnostic efficiency in medical imaging.

License

Notifications You must be signed in to change notification settings

kknani24/Automated-Brain-Tumor-Detection-Using-YOLOv10-A-Deep-Learning-Approach

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Brain Tumor Detection using YOLOv10

Python Jupyter Notebook YOLOv10 Gradio OpenCV Roboflow

This project demonstrates how to use the YOLOv10 model for brain tumor detection using MRI images. The model has been trained and fine-tuned on a dataset to detect brain tumors efficiently.


Table of Contents


Overview

This project uses YOLOv10 for detecting brain tumors from MRI scans. We employ Roboflow for dataset management and Gradio for creating a web-based interface.

Tools and Libraries Used:

  • YOLOv10
  • Roboflow
  • Gradio
  • Matplotlib
  • OpenCV

Installation and Setup

YOLOv10 Installation

  1. Install YOLOv10 from the official GitHub repository:

    !pip install -q git+https://github.com/THU-MIG/yolov10.git
  2. Download the pre-trained YOLOv10n model weights:

    !wget -P -q https://github.com/jameslahm/yolov10/releases/download/v1.0/yolov10n.pt
  3. Install Roboflow for dataset handling:

    !pip install -q roboflow

Roboflow Integration

  1. Install and set up Roboflow to manage and download the dataset:

    from roboflow import Roboflow
    rf = Roboflow(api_key="2A2n8FdjhCq768GBy1Yw")
    project = rf.workspace("brain-mri").project("mri-rskcu")
    version = project.version(3)
    dataset = version.download("yolov9")

Training the Model

  1. Start training the YOLOv10 model with the following command. You can modify parameters such as epochs, batch, and model:

    !yolo task=detect mode=train epochs=25 batch=32 plots=True \
    model=/content/yolov10n.pt \
    data=/content/MRI-3/data.yaml

Model Inference

  1. Load the trained model:

    from ultralytics import YOLOv10
    
    model_path = "/content/runs/detect/train9/weights/best.pt"
    model = YOLOv10(model_path)
  2. Run inference on the dataset with a confidence threshold:

    result = model(source="/content/MRI-3/train/images", conf=0.25, save=True)

Visualization

  1. Visualize predictions from multiple images using Matplotlib:

    import glob
    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg
    
    images = glob.glob("/content/runs/detect/predict/*.jpg")
    images_to_display = images[:10]
    
    fig, axes = plt.subplots(2, 5, figsize=(20, 10))
    
    for i, ax in enumerate(axes.flat):
        if i < len(images_to_display):
            img = mpimg.imread(images_to_display[i])
            ax.imshow(img)
            ax.axis('off')
        else:
            ax.axis('off')
    plt.tight_layout()
    plt.show()
  2. Visualize predictions on a single image:

    result = model.predict(source="/content/MRI-3/valid/images/Tr-gl_0228_jpg.rf.b9ecef834d39f770e41b0585b63bdc1a.jpg", imgsz=640, conf=0.25)
    annotated_img = result[0].plot()
    annotated_img[:, :, ::-1]

Web Application

  1. Install Gradio:

    !pip install gradio
  2. Define the predict() function and launch the app:

    import gradio as gr
    import cv2
    import numpy as np
    
    def predict(image):
        result = model.predict(source=image, imgsz=640, conf=0.25)
        annotated_img = result[0].plot()
        annotated_img = annotated_img[:, :, ::-1]
        return annotated_img
    
    app = gr.Interface(
        fn=predict,
        inputs=gr.Image(type="numpy", label="Upload an image"),
        outputs=gr.Image(type="numpy", label="Detect Brain Tumor"),
        title="Brain Tumor Detection Using YOLOv10",
        description="Upload an image and the YOLOv10 model will detect and annotate the brain tumor."
    )
    
    app.launch()

Results


License

This project is licensed under the MIT License.


References

Feel free to contribute or suggest improvements!


Note: Replace the images/ paths with the actual paths to the images used in your project. If you don't have these images, you might need to create or capture them based on your project's outputs.

About

This project implements an automated brain tumor detection system using the YOLOv10 deep learning model. It utilizes a robust MRI dataset for training, enabling accurate tumor identification and annotation. An interactive Gradio interface allows users to upload images for real-time predictions, enhancing diagnostic efficiency in medical imaging.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published