# 🔬 Medical AI System Documentation ## Project Overview This project contains two advanced AI systems for medical imaging and risk assessment: 1. **Pregnancy Risk Prediction Model** - Predicts pregnancy complications using clinical data 2. **Fetal Ultrasound Plane Classification** - Classifies fetal ultrasound images into anatomical planes --- ## 🤱 Pregnancy Risk Prediction Model ### Model Performance - **Algorithm**: Random Forest Classifier - **Accuracy**: 100% on test data - **Features**: 11 clinical parameters - **Classes**: High Risk, Low Risk - **Dataset**: 1,187 patient records ### Key Features - Age, Blood Pressure (Systolic/Diastolic) - Blood Sugar, Body Temperature, BMI - Medical History (Previous Complications, Diabetes) - Mental Health, Heart Rate ### Feature Importance (Top 5) 1. **Blood Sugar (BS)**: 22.8% 2. **Preexisting Diabetes**: 21.6% 3. **Heart Rate**: 16.0% 4. **BMI**: 14.7% 5. **Gestational Diabetes**: 8.5% ### Model Metrics ``` Classification Report: precision recall f1-score support High 1.00 1.00 1.00 95 Low 1.00 1.00 1.00 143 accuracy 1.00 238 macro avg 1.00 1.00 1.00 238 weighted avg 1.00 1.00 1.00 238 ``` --- ## 🔬 Fetal Ultrasound Plane Classification ### Model Performance - **Algorithm**: Vision Transformer (ViT-Base-Patch16-224) - **Validation Accuracy**: 91.69% - **Training Time**: 18.5 minutes (Apple Silicon M4) - **Dataset**: 12,400 ultrasound images - **Classes**: 9 anatomical plane categories ### Training Configuration - **Device**: Apple Silicon MPS (Metal Performance Shaders) - **Batch Size**: 2 (thermal-optimized) - **Epochs**: 2 - **Learning Rate**: 5e-5 - **Architecture**: ARM64 optimized ### Classification Categories #### Fetal Brain Planes (4 types) 1. **Trans-thalamic**: 1,638 images 2. **Trans-cerebellum**: 714 images 3. **Trans-ventricular**: 597 images 4. **Other brain views**: 143 images #### Anatomical Structures (4 types) 1. **Fetal thorax**: 1,718 images 2. **Maternal cervix**: 1,626 images 3. **Fetal femur**: 1,040 images 4. **Fetal abdomen**: 711 images #### Quality Control (1 type) 1. **Other/Unclear**: 4,213 images ### Training Metrics ``` Final Training Loss: 0.21 Validation Loss: 0.316 Training Speed: 4.47 iterations/second System Resources: - CPU Usage: 5.4% (post-training) - Memory Usage: 65.3% - Temperature: Stable (no overheating) ``` ### Apple Silicon Optimizations - **MPS Acceleration**: Full M4 chip utilization - **Thermal Management**: Prevented overheating - **Memory Efficiency**: Optimized batch sizes - **Native Performance**: ARM64 PyTorch builds --- ## 🏗️ System Architecture ### Project Structure ``` hackathon15092025/ ├── src/ # Source code │ ├── app.py # Pregnancy risk Streamlit app │ └── pregnancy_risk_prediction.py ├── fetal_plane_app.py # Fetal plane Streamlit app ├── fetal_plane_classifier.py # Training script ├── models/ # Trained models │ ├── pregnancy_risk_model.pkl │ └── fetal_plane_model/ ├── data/ # Datasets │ └── Dataset - Updated.csv ├── FETAL_PLANES_ZENODO/ # Ultrasound dataset ├── static/css/ # Styling ├── index.html # Main dashboard └── requirements*.txt # Dependencies ``` ### Technology Stack - **Machine Learning**: scikit-learn, PyTorch, Transformers - **Web Framework**: Streamlit - **Frontend**: HTML5, CSS3, JavaScript - **Visualization**: Plotly, Matplotlib - **Deployment**: Apple Silicon optimized --- ## 🚀 Deployment Guide ### Prerequisites - Python 3.9+ - macOS with Apple Silicon (M1/M2/M3/M4) - 8GB+ RAM recommended ### Installation ```bash # Clone repository cd /Users/karthik/Projects/hackathon15092025 # Install dependencies pip install -r requirements.txt pip install -r requirements_fetal.txt # Train models (if needed) python src/pregnancy_risk_prediction.py python train_fetal_model_thermal.py ``` ### Running Applications ```bash # Pregnancy Risk App (Port 8501) streamlit run src/app.py # Fetal Plane App (Port 8502) streamlit run fetal_plane_app.py --server.port 8502 # Main Dashboard open index.html ``` --- ## 📊 Performance Benchmarks ### Pregnancy Risk Model | Metric | Value | |--------|-------| | Training Accuracy | 100% | | Validation Accuracy | 100% | | Inference Time | <1ms | | Model Size | 2.3MB | | Features | 11 | ### Fetal Plane Model | Metric | Value | |--------|-------| | Training Accuracy | 95.4% | | Validation Accuracy | 91.69% | | Inference Time | <100ms | | Model Size | 346MB | | Parameters | 86M | ### System Performance (M4 MacBook) | Resource | Usage | |----------|-------| | CPU | 5.4% (idle) | | Memory | 65.3% | | GPU (MPS) | Active | | Temperature | Stable | --- ## 🔒 Security & Privacy ### Data Protection - **No Data Storage**: Patient data not permanently stored - **Local Processing**: All inference runs locally - **HIPAA Considerations**: Designed for privacy compliance - **Secure Models**: No data leakage in model weights ### Recommendations - Use in controlled medical environments - Implement proper access controls - Regular security audits - Compliance with local regulations --- ## 🎯 Clinical Applications ### Pregnancy Risk Assessment - **Primary Care**: Initial risk screening - **Obstetrics**: Prenatal care planning - **Emergency**: Rapid risk evaluation - **Telemedicine**: Remote consultations ### Ultrasound Classification - **Radiology**: Image quality control - **Training**: Medical education tool - **Workflow**: Automated image sorting - **Research**: Large-scale studies --- ## ⚠️ Limitations & Disclaimers ### Model Limitations - **Educational Purpose**: Not for clinical diagnosis - **Validation Needed**: Requires clinical validation - **Population Bias**: Trained on specific datasets - **Continuous Learning**: Models need regular updates ### Usage Guidelines - Always consult qualified healthcare professionals - Use as decision support, not replacement - Validate results with clinical judgment - Report unusual predictions for review --- ## 📈 Future Enhancements ### Planned Features - **Multi-language Support**: International deployment - **Real-time Monitoring**: Continuous risk assessment - **Integration APIs**: EHR system connectivity - **Advanced Models**: Transformer-based improvements ### Research Directions - **Federated Learning**: Multi-site model training - **Explainable AI**: Enhanced interpretability - **Edge Deployment**: Mobile device optimization - **Clinical Trials**: Prospective validation studies --- ## 📞 Support & Contact ### Technical Support - **Documentation**: This file and README files - **Issues**: Check terminal logs for errors - **Performance**: Monitor system resources - **Updates**: Regular dependency updates ### Development Team - **AI/ML Engineering**: Model development and optimization - **Medical Informatics**: Clinical workflow integration - **Software Engineering**: Application development - **Quality Assurance**: Testing and validation --- *Last Updated: January 2025* *Version: 1.0* *Platform: Apple Silicon Optimized*