This project implements an AI-powered system for detecting Ulcerative Colitis (UC) from colonoscopy images using deep learning. The system consists of a ResNet-18 based classifier trained on colonoscopy images and a Flask web application for easy image analysis. This is used as a demonstrative project in collaboration with a physical tool developed for a health exhibition.
The classification model is built on ResNet-18 with transfer learning:
- Pre-trained on ImageNet weights
- Fine-tuned on colonoscopy images with layers 3 and 4 unfrozen
- Binary classification: Normal vs Ulcerative Colitis
- Uses data augmentation and weighted sampling for class imbalance handling
The Flask web interface provides:
- Multi-image upload support
- Real-time AI analysis of colonoscopy images
- Comprehensive medical report generation
- Risk assessment with visual progress indicators
- Responsive design optimized for medical use
Below are the instructions for setting up the local development environment should anyone be interested in modifying the code.
- Python 3.8 or higher
- CUDA-compatible GPU (recommended)
-
Clone the repository
git clone https://github.com/linusc9516/UC_Classifier cd UC_Classifier -
Install dependencies
pip install -r requirements.txt
-
Download and prepare dataset
- Download the colonoscopy images dataset (zip file named
patient_based_classified_images.zip) - Extract the images to the project directory
- Run the data preparation script:
split_directories.bat
- Download the colonoscopy images dataset (zip file named
-
Train the model
- Modify training parameters in
model.pyif needed - Run the training script:
python model.py
- The trained model will be saved as
2classifier_rn18_layer3_4_unfreeze.pt, or whatever you wish to rename it to.
- Modify training parameters in
-
Launch the web application
python app.py
- Open your browser and navigate to
http://localhost:5000 - Upload colonoscopy images for analysis
- Open your browser and navigate to
- Access the web interface at
http://localhost:5000 - Upload one or multiple colonoscopy images
- Click "Analyze Images" to process the images
- Review the AI-generated medical report with risk assessment
app.py- Flask web applicationmodel.py- Model training and architecturetemplates/- HTML templates for the web interfacestatic/- CSS styles and static assets2class/- Training dataset directorytest/- Sample test images
This AI system is for research and educational purposes only. It should not replace professional medical diagnosis or consultation with qualified practicioners. Credit also goes to the owner of the dataset used in this project.