An open API service indexing awesome lists of open source software.

https://github.com/dhou22/3d-nodule-detection

3D Dual Path Network for Lung CT Analysis: Implementation of the 3D DPN from the DeepLung framework for automated pulmonary nodule detection and classification, combining residual and dense connections for efficient, accurate cancer diagnosis on CT scans.
https://github.com/dhou22/3d-nodule-detection

3d-cnn-architecture computer-vision deep-neural-networks lung-cancer-detection

Last synced: 3 months ago
JSON representation

3D Dual Path Network for Lung CT Analysis: Implementation of the 3D DPN from the DeepLung framework for automated pulmonary nodule detection and classification, combining residual and dense connections for efficient, accurate cancer diagnosis on CT scans.

Awesome Lists containing this project

README

          

# ๐Ÿซ Lung Nodule Detection System

Welcome to the **Lung Nodule Detection System**, an advanced deep learning-based framework for detecting and classifying pulmonary nodules in CT scans. This system leverages the 3D Dual Path Network (DPN) architecture, inspired by the DeepLung framework detailed in ["DeepLung: Deep 3D Dual Path Nets for Automated Pulmonary Nodule Detection and Classification"](https://arxiv.org/abs/1801.09555).
![image](https://github.com/user-attachments/assets/3140d0d4-41d8-4c92-82c5-c373a481a717)

---

## ๐Ÿš€ Project Overview

This repository provides a comprehensive pipeline for automating lung nodule detection and classification, encompassing:

1. **Nodule Detection** ๐Ÿ”: Using a 3D Faster R-CNN with dual path blocks for identifying lung nodules in CT scans.
2. **Nodule Classification** ๐Ÿ”ฌ: Leveraging a 3D DPN combined with Gradient Boosting Machines (GBM) for malignancy prediction.

### ๐Ÿง  Key Features

โœ… **3D Dual Path Networks**: Combines residual learning and dense connections for efficient feature extraction.
โœ… **Modular Codebase**: Clean structure for preprocessing, model loading, and inference.
โœ… **Web Application**: Flask-based UI for uploading scans and viewing predictions.
โœ… **Monitoring & Observability**: Prometheus and Grafana for performance tracking.
โœ… **Containerization**: Dockerized deployment for consistent runtime environments.
โœ… **Comprehensive Testing**: Includes unit and integration tests for reliability.

---

## ๐Ÿ—๏ธ Project Architecture

```plaintext
๐Ÿ“‚ lung-nodule-detection/
โ”œโ”€โ”€ ๐Ÿ“‚ app/ # Main application code
โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ static/ # Static assets (CSS, JS)
โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ templates/ # HTML templates for web UI
โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ models/ # Trained model storage
โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ utils/ # Utility scripts (preprocessing, inference)
โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ monitoring/ # Monitoring and metrics
โ”‚ โ”œโ”€โ”€ ๐Ÿ“œ __init__.py # Flask app initialization
โ”‚ โ”œโ”€โ”€ ๐Ÿ“œ routes.py # API routes and logic
โ”œโ”€โ”€ ๐Ÿ“‚ tests/ # Unit and integration tests
โ”œโ”€โ”€ ๐Ÿ“œ requirements.txt # Python dependencies
โ”œโ”€โ”€ ๐Ÿ“œ Dockerfile # Container definition
โ”œโ”€โ”€ ๐Ÿ“œ docker-compose.yml # Multi-service orchestration
โ”œโ”€โ”€ ๐Ÿ“œ Makefile # Automation commands
โ”œโ”€โ”€ ๐Ÿ“œ README.md # Project documentation
```

---

## ๐Ÿ“Œ Project Phases

### 1๏ธโƒฃ Environment Setup

#### Project Initialization
```bash
# Create project directory and virtual environment
mkdir lung-nodule-detection
cd lung-nodule-detection
python -m venv venv
source venv/bin/activate
```

#### Install Dependencies
```bash
pip install flask torch torchvision numpy pandas matplotlib scikit-image scipy opencv-python prometheus-client gunicorn flask-wtf flask-cors
pip install -U mlflow tensorboard pytest pytest-cov
pip freeze > requirements.txt
```

---

### 2๏ธโƒฃ Model Handling

#### Model Loading
- Utility to load the 3D DPN model from `.pth` files.
- Ensures compatibility with the model architecture.

#### Preprocessing CT Scans
- Steps include:
- **Normalization**: Adjust pixel intensity to a standard scale.
- **Resizing**: Ensure input dimensions match the model's expected size.
- **Dimensionality Addition**: Add batch and channel dimensions.

#### Inference
- Run predictions on preprocessed scans to classify nodules as benign or malignant.

---

### 3๏ธโƒฃ Web Application

#### Flask-based UI
- **File Uploads**: Upload `.raw` CT scan files for analysis.
- **Results Visualization**: View predictions, confidence levels, and download detailed reports.

![image](https://github.com/user-attachments/assets/e75df5f1-40ae-4255-8e9d-991a8a10ac24)

---

### 4๏ธโƒฃ Monitoring & Observability

#### Prometheus & Grafana Integration
- **Metrics Tracked**:
- Total inference requests.
- Inference duration and errors.
- Active requests and model load time.
- **Dashboards**: Visualize system performance and application health.

![Monitoring Dashboard](https://github.com/user-attachments/assets/cfb919a0-e4e9-4155-b9f0-fd1f83f91298)

---

### 5๏ธโƒฃ Containerization

#### Dockerized Deployment
- **Dockerfile**: Encapsulates the application and dependencies.
- **docker-compose.yml**: Orchestrates multi-container setups (web app, Prometheus, Grafana).

![Docker Deployment](https://github.com/user-attachments/assets/6ae5d485-b98b-4d1d-a983-8cac76c298c9)

---

### 6๏ธโƒฃ Testing

#### Unit Tests
- Verify preprocessing utilities and model loading.

#### Integration Tests
- Validate API endpoints and end-to-end workflows.

---

## ๐Ÿ“ฆ Setup Instructions

### 1๏ธโƒฃ Clone the Repository
```bash
git clone https://github.com/dhou22/Lung-Nodule-Detection.git
cd lung-nodule-detection
```

### 2๏ธโƒฃ Environment Setup
```bash
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt
```

### 3๏ธโƒฃ Run Flask App
```bash
# Start the Flask application
python app/__init__.py
```

Visit the web app at [http://localhost:5000](http://localhost:5000).

### ๐Ÿงช Run Tests
```bash
pytest tests/
```

---

## ๐Ÿณ Docker Deployment

### Build and Run Containers
```bash
docker-compose up --build
```

- Web App: [http://localhost:5000](http://localhost:5000)
- Monitoring Dashboard: [http://localhost:3000](http://localhost:3000)

---

## ๐Ÿ“ก API Endpoints

| Method | Endpoint | Description |
|--------|----------------|-------------------------------|
| GET | `/health` | Check API status |
| POST | `/upload` | Upload CT scan for prediction |
| GET | `/report/` | Download prediction report |

---

## ๐Ÿ› ๏ธ Makefile Commands

| Command | Description |
|--------------------|------------------------------------|
| `make install` | Install dependencies |
| `make test` | Run unit tests |
| `make run` | Start Flask app |
| `make docker-build`| Build Docker image |
| `make docker-run` | Run Docker container |
| `make monitor` | Start monitoring services |

---

## ๐Ÿ“ˆ Model Performance

- **Accuracy**: Achieves radiologist-level detection rates.
- **Efficiency**: Optimized for high-resolution CT scans with reduced computational overhead.

![Model Metrics Dashboard](https://github.com/user-attachments/assets/4bc0340f-5af5-428d-a965-0dd1fdb3c789)

---

## ๐Ÿ“œ License

Licensed under **MIT License**.
ยฉ 2025 **Dhouha Meliane**
Email: [dhouhameliane@esprit.tn](mailto:dhouhameliane@esprit.tn)