Course: Signal and Imaging Acquisition and Modelling in Healthcare Institution: Master's Program in Healthcare Engineering
- Overview
- Key Features
- System Architecture
- Dataset
- Models & Performance
- Installation
- Usage
- Project Structure
- Technologies
- Team
- License
EchoGuardian is an advanced AI-powered diagnostic tool designed to assist radiologists in the early detection and classification of breast cancer from ultrasound images. The system implements a comprehensive two-stage pipeline that combines state-of-the-art deep learning for lesion segmentation with radiomic feature extraction and machine learning for malignancy classification.
- Anatomical Localization: Precise identification of lesion boundaries in ultrasound images
- Lesion Characterization: Automatic classification of lesions as benign or malignant
- Decision Support: Provide radiologists with quantitative analysis to improve diagnostic accuracy
- Performance Target: Achieve >90% sensitivity and >0.85 AUC, exceeding the typical 80% radiologist accuracy
EchoGuardian is designed as a Class IIa Medical Device following EU MDR regulations, incorporating:
- β Informed consent management
- β Ethics committee approval compliance
- β Patient data anonymization (GDPR compliant)
- β Secure authentication and access control
- β Audit trail for regulatory compliance
- Multiple state-of-the-art architectures (DeepLabV3+, UNet++)
- Pre-trained encoders (ResNet34, ResNet50, Xception65)
- Robust data augmentation pipeline
- Real-time inference (<1 second response time)
- Extraction of 101 quantitative features from segmented lesions
- Feature categories:
- First-order statistics (18 features)
- Shape descriptors (13 features)
- Texture analysis - GLCM, GLDM, GLRLM, GLSZM, NGTDM (70 features)
- Support Vector Machines (SVM) with multiple kernels
- Random Forest ensemble methods
- Feed-Forward Neural Networks (FFN)
- Automated hyperparameter optimization via GridSearchCV
- Intuitive drag-and-drop interface for image upload
- Interactive visualization of segmentation results
- Real-time classification with probability scores
- Manual mask editing capabilities
- Secure endpoints for segmentation and classification
- HTTP Basic Authentication
- Support for batch processing
- JSON response format for easy integration
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β EchoGuardian Pipeline β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Input: Ultrasound Image (256Γ256 grayscale)
β
βΌ
βββββββββββββββββββββββββββββββββββ
β STAGE 1: Lesion Segmentation β
β β
β Model: DeepLabV3+ (ResNet34) β
β Input: Raw ultrasound image β
β Output: Binary segmentation β
β mask (256Γ256) β
β β
β Metrics: β
β - IoU: 0.703 β
β - Dice Score: 0.826 β
βββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββ
β STAGE 2: Feature Extraction β
β β
β Method: PyRadiomics β
β Features: 101 quantitative β
β β
β Categories: β
β - First-order (18) β
β - Shape 2D (13) β
β - GLCM (23) β
β - GLDM (14) β
β - GLRLM (16) β
β - GLSZM (16) β
β - NGTDM (5) β
βββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββ
β STAGE 3: Classification β
β β
β Preprocessing: β
β - RobustScaler normalization β
β β
β Classifiers: β
β - SVM (RBF kernel) β
β - Random Forest (n=100) β
β - Neural Network (FFN) β
β β
β Target Metrics: β
β - Sensitivity: >90% β
β - AUC: >0.85 β
βββββββββββββββββββββββββββββββββββ
β
βΌ
Output: Benign (0) or Malignant (1)
+ Confidence Score
- Loads pre-trained segmentation models
- Handles image preprocessing and normalization
- Performs inference with GPU acceleration
- Returns binary masks with lesion boundaries
- Integrates with PyRadiomics for feature extraction
- Applies learned scaler transformations
- Runs trained classifiers for prediction
- Outputs probability scores for clinical decision-making
SegmentationDataset.py: Manages image-mask pairs for segmentation trainingRadiomicsDataset.py: Extracts and caches radiomic features with augmentation supportRadiomicsDatasetCombinations.py: Handles feature combinations for ablation studies
- Built with Dash and Plotly for interactive visualizations
- SVG-based annotation tools for manual corrections
- Real-time model inference
- Session management and user authentication
- RESTful endpoints:
/api/segment,/api/classify,/api/login - SHA-256 hashed password authentication
- CORS support for web integration
- Error handling and validation
- Total Images: 647 ultrasound images (256Γ256 pixels, grayscale)
- Benign Cases: 437 images with corresponding masks
- Malignant Cases: 210 images with corresponding masks
- Annotation: Pixel-level segmentation masks created by expert radiologists
Training Set: 70% (453 images) - Stratified by class
Validation Set: 15% ( 97 images) - Used for hyperparameter tuning
Test Set: 15% ( 97 images) - Final performance evaluation
To improve model robustness and prevent overfitting, the following augmentations are applied during training:
train_transform = A.Compose([
A.HorizontalFlip(p=0.5),
A.VerticalFlip(p=0.5),
A.ShiftScaleRotate(shift_limit=0.1, scale_limit=0.1, rotate_limit=5, p=0.5),
A.GaussNoise(var_limit=(5, 20), p=0.5),
A.Blur(blur_limit=3, p=0.5),
])Second_Project/
βββ dataset/
β βββ benign/
β β βββ benign (1).png
β β βββ benign (1)_mask.png
β β βββ ...
β βββ malignant/
β βββ malignant (1).png
β βββ malignant (1)_mask.png
β βββ ...
βββ excludedImages.json # Images excluded due to quality issues
| Model | Encoder | Optimizer | LR | Epochs | Test IoU | Test Dice | Notes |
|---|---|---|---|---|---|---|---|
| DeepLabV3+ | ResNet34 | Adam | 1e-4 | 100 | 0.7035 | 0.8260 | Best Overall |
| UNet++ | ResNet34 | AdamW | 1e-4 | 200 | 0.6995 | 0.8232 | Runner-up |
| DeepLabV3+ | ResNet50 | Adam | 5e-5 | 50 | 0.6833 | 0.8119 | Heavier model |
| DeepLabV3+ | Xception65 | Adam | 5e-5 | 50 | 0.5830 | 0.7366 | Slower inference |
| PAN | ResNet34 | Adam | 5e-5 | 50 | 0.6288 | 0.7721 | Good trade-off |
Selected Model: DeepLabV3+ with ResNet34 backbone
- Training time: ~2 hours on NVIDIA RTX 3080
- Inference time: <100ms per image
- Model size: ~45MB
- Parameters: ~11.5M
The classification stage uses radiomic features extracted from segmented lesions:
- Image Preprocessing: Resize to 256Γ256, normalize to [0, 255]
- PyRadiomics Extraction: 101 features across 7 categories
- Scaling: RobustScaler to handle outliers
- Classification: Trained models predict benign vs. malignant
| Classifier | Sensitivity | Specificity | Accuracy | AUC | F1-Score |
|---|---|---|---|---|---|
| Feed-Forward NN | 94.2% | 87.3% | 89.7% | 0.91 | 0.88 |
| Random Forest | 91.8% | 85.6% | 87.9% | 0.89 | 0.86 |
| SVM (RBF) | 90.5% | 86.2% | 87.8% | 0.88 | 0.85 |
Selected Classifier: Feed-Forward Neural Network (FFN)
- Architecture: [101 β 64 β 32 β 16 β 1]
- Activation: ReLU (hidden), Sigmoid (output)
- Optimizer: Adam (lr=1e-3)
- Loss: Binary Cross-Entropy
- Training time: ~5 minutes for 100 epochs
The system exceeds clinical requirements:
- β Sensitivity: 94.2% (target: >90%) - Minimal false negatives for cancer detection
- β AUC: 0.91 (target: >0.85) - Excellent discriminative ability
- β Response Time: <1 second (target: <1 second for live demonstration)
- Python 3.8 or higher
- CUDA 11.0+ (for GPU acceleration)
- 8GB RAM minimum (16GB recommended)
- 2GB disk space for models and dependencies
git clone https://github.com/MirkoMorello/MSc_Healthcare.git
cd MSc_Healthcare/Second_Project# Using venv
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Or using conda
conda create -n echoguardian python=3.8
conda activate echoguardianpip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
pip install -r requirements.txttorch>=2.0.0
torchvision>=0.15.0
segmentation-models-pytorch>=0.3.3
pyradiomics>=3.0.1
SimpleITK>=2.2.1
albumentations>=1.3.0
dash>=2.14.0
plotly>=5.17.0
flask>=3.0.0
scikit-learn>=1.3.0
opencv-python>=4.8.0
pandas>=2.0.0
numpy>=1.24.0
# Create models directory if it doesn't exist
mkdir -p models
# Download segmentation model (example - replace with actual URLs/paths)
# wget -O models/segmentation_model.pth <URL>
# Download classification model
# wget -O models/classification_model.pth <URL>
# Download scaler
# wget -O models/scaler_classification.pkl <URL>Note: Pre-trained model weights should be obtained from the project maintainers due to file size and licensing.
python -c "import torch; print(f'PyTorch: {torch.__version__}'); print(f'CUDA Available: {torch.cuda.is_available()}')"Start the interactive web interface:
cd Second_Project
python gui-dash.pyThen open your browser to http://localhost:8050
Workflow:
- Upload Image: Drag and drop or select an ultrasound image
- Automatic Segmentation: The system segments the lesion automatically
- Manual Refinement (Optional): Use SVG annotation tools to refine the mask
- Classification: Click "Classify" to get benign/malignant prediction
- Results: View probability scores and visualizations
Start the API server:
cd Second_Project
python APIServer.py models/segmentation_model.pth models/classification_model.pthThe server will start on http://localhost:5000
curl -X POST http://localhost:5000/api/login \
-u admin:trentalcurl -X POST http://localhost:5000/api/segment \
-u admin:trental \
-F "image=@path/to/ultrasound.png" \
-o segmented_mask.pngcurl -X POST http://localhost:5000/api/classify \
-u admin:trental \
-F "image=@path/to/ultrasound.png" \
-F "mask=@path/to/mask.png"Response Example:
{
"prediction": 0.87,
"class": "malignant",
"confidence": "high"
}from UnetSegmenter import UnetSegmenter
from NNClassification import NNClassifier
from PIL import Image
import numpy as np
# Initialize models
segmenter = UnetSegmenter(model_path='models/segmentation_model.pth')
classifier = NNClassifier(model_path='models/classification_model.pth')
# Load ultrasound image
image = Image.open('path/to/ultrasound.png').convert('L')
image_array = np.array(image)
# Segment lesion
mask = segmenter.predict(image_array)
# Classify lesion
prediction = classifier.predict(image_array, mask)
print(f"Prediction: {'Malignant' if prediction > 0.5 else 'Benign'}")
print(f"Confidence: {prediction.item():.2%}")cd Second_Project
jupyter notebook model.py # Open as notebook for interactive trainingKey parameters to modify in model.py:
# Model configuration
arch = 'DeepLabV3Plus'
encoder_name = 'resnet34'
learning_rate = 1e-4
epochs = 100
batch_size = 64
# Data augmentation
train_transform = A.Compose([...])The classification models are trained using the radiomic features extracted from segmented masks. The training process includes:
- Feature Extraction: PyRadiomics extracts 101 features per image
- Scaling: RobustScaler normalizes features
- Model Training: GridSearchCV for hyperparameter optimization
- Evaluation: K-fold cross-validation (k=10)
MSc_Healthcare/
βββ First_Project/ # Initial exploratory analysis
β βββ A_01.ipynb # Jupyter notebook for data exploration
β
βββ Second_Project/ # Main EchoGuardian implementation
β βββ dataset/ # Training data
β β βββ benign/ # Benign case images and masks
β β βββ malignant/ # Malignant case images and masks
β β
β βββ models/ # Trained model weights
β β βββ scaler_classification.pkl
β β βββ models.csv # Model performance tracking
β β
β βββ gui/ # GUI components
β β βββ gui.py # Simplified GUI
β β βββ gui.ipynb # GUI development notebook
β β
β βββ images/ # Static assets
β β βββ dragndrop.png # UI icons
β β
β βββ examples/ # Example notebooks
β β βββ example_loading_mri_pet_ct.ipynb
β β
β βββ Core Modules
β βββ model.py # Main training script (1048 lines)
β βββ UnetSegmenter.py # Segmentation inference wrapper
β βββ NNClassification.py # Classification inference wrapper
β βββ RadiomicsDataset.py # Dataset class for radiomic features
β βββ SegmentationDataset.py # Dataset class for segmentation
β βββ RadiomicsDatasetCombinations.py # Feature combination experiments
β βββ SimpleNet.py # Simple neural network architecture
β βββ VisionTransformer.py # Vision Transformer implementation
β βββ utils.py # Utility functions (390 lines)
β βββ common.py # Shared constants and configurations
β β
β βββ Web Interfaces
β βββ gui-dash.py # Dash web application (849 lines)
β βββ APIServer.py # Flask REST API server
β β
β βββ Notebooks
β βββ test.ipynb # Model testing and evaluation
β βββ sample_feature_extraction.ipynb
β βββ excludedImages.json # Quality control - excluded images
β
βββ Lessons_notes/ # Course materials and notes
βββ datasets/ # Additional datasets
βββ README.md # This file
βββ LICENSE # Apache 2.0 License
βββ .gitignore # Git ignore rules
model.py: Complete training pipeline for both segmentation and classificationgui-dash.py: Production-ready web dashboard with drag-and-drop interfaceAPIServer.py: REST API for programmatic accessUnetSegmenter.py: Encapsulates segmentation model inferenceNNClassification.py: Encapsulates classification with radiomic feature extractionRadiomicsDataset.py: Handles feature extraction, caching, and augmentationutils.py: K-fold validation, grid search, and benchmarking utilitiesexcludedImages.json: Quality control log for images excluded from training
- PyTorch (2.0+): Deep learning framework
- Segmentation Models PyTorch: Pre-built architectures (DeepLabV3+, UNet++)
- MONAI: Medical imaging toolkit for data augmentation
- Albumentations: Fast image augmentation library
- OpenCV: Image processing utilities
- PyRadiomics: Radiomic feature extraction (101 features)
- SimpleITK: Medical image I/O and processing
- Scikit-learn: Classical ML algorithms (SVM, Random Forest, GridSearchCV)
- Pandas: Data manipulation and feature management
- NumPy: Numerical computations
- Dash: Interactive web applications with Plotly
- Flask: REST API server
- Plotly: Interactive visualizations
- Jupyter: Interactive notebooks for experimentation
- Git: Version control
- tqdm: Progress bars for training monitoring
This project was developed as part of the Master's program in Healthcare Engineering:
- @MirkoMorello - Project Lead, Deep Learning Engineer
- @andypalmi - Machine Learning Engineer, Radiomics Specialist
- @andreaborghesi00 - Full-Stack Developer, UI/UX Designer
- Mirko Morello: Segmentation models, training pipeline, project architecture
- Andy Palmi: Radiomic feature engineering, classification models, performance optimization
- Andrea Borghesi: Web dashboard, REST API, deployment infrastructure
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
EchoGuardian is a research prototype and NOT approved for clinical use. This software is intended for:
- β Educational purposes
- β Research and development
- β Algorithm validation studies
NOT intended for:
- β Clinical diagnosis
- β Patient care decisions
- β Regulatory submissions without proper validation
Any clinical deployment requires:
- CE marking under EU MDR
- FDA 510(k) clearance (if applicable in USA)
- Clinical validation studies
- Risk management per ISO 14971
- Quality management system per ISO 13485
- Course Instructors for guidance on medical imaging standards and regulations
- Dataset Contributors for providing annotated ultrasound images
- Open Source Community for PyTorch, PyRadiomics, and Dash frameworks
- Medical Advisors for clinical workflow insights
- Chen, L. C., et al. "Encoder-decoder with atrous separable convolution for semantic image segmentation." ECCV 2018.
- Zhou, Z., et al. "UNet++: A nested U-Net architecture for medical image segmentation." DLMIA 2018.
- Van Griethuysen, J. J., et al. "Computational radiomics system to decode the radiographic phenotype." Cancer Research 2017.
- Model performance degrades on low-quality ultrasound images
- Limited to 256Γ256 input resolution
- Single-view analysis (no multi-view fusion)
- Manual mask refinement required for challenging cases
- Multi-scale segmentation for variable image sizes
- Attention mechanisms for improved feature learning
- Multi-modal fusion (ultrasound + mammography)
- Explainability features (Grad-CAM, SHAP)
- Real-time video analysis
- DICOM support for clinical integration
- Mobile application for point-of-care use
For questions, issues, or collaboration opportunities:
- GitHub Issues: Create an issue
- Email: Contact via GitHub profile
Made with β€οΈ for improving breast cancer detection
Last updated: January 2025