Spaces:
Runtime error
Runtime error
Update README.md
Browse files
README.md
CHANGED
|
@@ -7,4 +7,91 @@ sdk: streamlit
|
|
| 7 |
sdk_version: 1.45.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
sdk_version: 1.45.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# ITC 6109 - Machine Vision: Skin Lesion Classification
|
| 14 |
+
## Project: Automated Classification of Dermatoscopy Images (HAM10000) using Classical Computer Vision & Machine Learning.
|
| 15 |
+
### π₯ Team Members
|
| 16 |
+
Kolia Aimilia
|
| 17 |
+
Kontoudakis Nikos
|
| 18 |
+
Skiada Kiki
|
| 19 |
+
Lampropoulou Nancy
|
| 20 |
+
### π Project Structure
|
| 21 |
+
The project is organized into a modular Python package (src) to separate concerns between data handling, computer vision logic, and machine learning.
|
| 22 |
+
ham10000_project/
|
| 23 |
+
β
|
| 24 |
+
βββ data/ # Dataset (Input)
|
| 25 |
+
β βββ images/ # Source dermatoscopy images
|
| 26 |
+
β βββ GroundTruth.csv # Metadata and labels
|
| 27 |
+
β
|
| 28 |
+
βββ models/ # Artifacts (Output)
|
| 29 |
+
β βββ skin_cancer_model.pkl # Trained Random Forest model
|
| 30 |
+
β βββ scaler.pkl # StandardScaler for normalization
|
| 31 |
+
β βββ X_train_sample.npy # Sample data for LIME initialization in App
|
| 32 |
+
β βββ [plots] # ROC curves, Confusion Matrices, LIME plots
|
| 33 |
+
β
|
| 34 |
+
βββ src/ # Core Logic Package
|
| 35 |
+
β βββ __init__.py # Package initializer
|
| 36 |
+
β βββ config.py # Hyperparameters, constants, and paths
|
| 37 |
+
β βββ data.py # CSV parsing and metadata loading
|
| 38 |
+
β βββ features.py # The complete Computer Vision pipeline
|
| 39 |
+
β βββ augmentation.py # Keras-based image augmentation logic
|
| 40 |
+
β βββ model.py # Model training, evaluation, and plotting orchestration
|
| 41 |
+
β βββ plots.py # Visualization logic (ROC, Confusion Matrices)
|
| 42 |
+
β βββ explainability.py # XAI logic (LIME, Feature Importance)
|
| 43 |
+
β
|
| 44 |
+
βββ train_main.py # MAIN SCRIPT: Orchestrates the training pipeline
|
| 45 |
+
βββ app.py # WEB APP: Interactive Streamlit interface
|
| 46 |
+
βββ requirements.txt # Project dependencies
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
### π Sequence of Execution
|
| 50 |
+
When you run python train_main.py, the system follows this strict sequence to ensure data integrity (preventing leakage) and robust training.
|
| 51 |
+
Phase 1: Data Preparation
|
| 52 |
+
Load Metadata (src.data):
|
| 53 |
+
The script reads GroundTruth.csv.
|
| 54 |
+
It parses the one-hot encoded labels into a single target class (e.g., 'MEL', 'NV').
|
| 55 |
+
It constructs valid file paths for every image.
|
| 56 |
+
Train/Test Split:
|
| 57 |
+
CRITICAL STEP: The data is split into Training (80%) and Test (20%) sets before any image processing or augmentation occurs. This guarantees that no augmented version of a test image ever leaks into the training set.
|
| 58 |
+
Phase 2: Feature Extraction & Augmentation
|
| 59 |
+
The script processes the Test set and Training set differently:
|
| 60 |
+
Test Set Processing:
|
| 61 |
+
Iterates through test images.
|
| 62 |
+
Passes each image through the CV Pipeline (src.features) to extract a 1D feature vector (Color, Shape, Texture).
|
| 63 |
+
No augmentation is applied.
|
| 64 |
+
Training Set Processing (With Augmentation):
|
| 65 |
+
Iterates through training images.
|
| 66 |
+
Class Check: Checks if the image belongs to a minority class.
|
| 67 |
+
On-the-fly Augmentation (src.augmentation): If it's a minority class, Keras generates rotated, zoomed, or shifted versions of the image to balance the dataset.
|
| 68 |
+
Feature Extraction: Features are extracted for the original image and all generated augmented versions.
|
| 69 |
+
Phase 3: The Computer Vision Pipeline (src.features)
|
| 70 |
+
Every image (original or augmented) goes through these steps to generate numbers for the AI:
|
| 71 |
+
Preprocessing: Resize with padding (to keep aspect ratio), Grayscale conversion, CLAHE (Smart Contrast), and Gaussian Blur.
|
| 72 |
+
Segmentation: Otsu's Thresholding finds the lesion. Morphological operations (Opening/Dilation) clean noise and connect fragmented parts.
|
| 73 |
+
Shape Analysis: Calculates Area, Perimeter, and Compactness of the largest object.
|
| 74 |
+
Color Analysis: Calculates Mean/Std/Skew for RGB channels and a Color Histogram, strictly within the lesion mask.
|
| 75 |
+
Texture Analysis: Uses Canny Edge Detection to measure edge density inside the lesion.
|
| 76 |
+
Phase 4: Training & Evaluation (src.model)
|
| 77 |
+
Scaling: A StandardScaler is fit on the Training features and applied to Test features.
|
| 78 |
+
Training: Random Forest and SVM models are trained on the balanced feature set.
|
| 79 |
+
Evaluation:
|
| 80 |
+
Predictions are made on the Test Set.
|
| 81 |
+
Confusion Matrices (Raw and Normalized) are generated.
|
| 82 |
+
Multi-class ROC Curves are plotted.
|
| 83 |
+
Explainable AI (XAI):
|
| 84 |
+
Global: Feature Importance plot is generated for Random Forest.
|
| 85 |
+
Local (LIME): Individual explanations are generated for sample test instances to show why specific decisions were made.
|
| 86 |
+
Artifact Saving: The best model, scaler, class names, and a training sample (for the App) are saved to models/.
|
| 87 |
+
### π How to Run
|
| 88 |
+
Install Requirements:
|
| 89 |
+
pip install -r requirements.txt
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
### Train the System:
|
| 93 |
+
python train_main.py
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
### Launch the Web App:
|
| 97 |
+
streamlit run app.py
|