Update README.md
Browse files
README.md
CHANGED
|
@@ -1,59 +1,79 @@
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
---
|
|
|
|
| 4 |
# Conditional Diffusion Model for Medical Image Generation
|
| 5 |
|
| 6 |
-
This repository contains a conditional diffusion model trained to generate 3D medical CT scan images based on segmentation masks.
|
|
|
|
|
|
|
|
|
|
| 7 |
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
<p>
|
| 11 |
<img src="assets/real_fake.png" alt="Sample real vs fake medical CT" width="600"/>
|
| 12 |
</p>
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
The model was trained on medical CT scan data with corresponding segmentation masks. The dataset contains 3,346 training examples with 80-20 train/validation split.
|
| 17 |
-

|
| 18 |
-
1. [Kaggle Pancreas CT](https://www.kaggle.com/datasets/salihayesilyurt/pancreas-ct)
|
| 19 |
-
2. [Cancer Imaging Archive Pancreatic CT](https://nbia.cancerimagingarchive.net/nbia-search/)
|
| 20 |
-
3. [A large annotated medical image dataset for the development and evaluation of segmentation algorithms](https://drive.google.com/drive/folders/1HqEgzS8BV2c7xYNrZdEAnrHk7osJJ--2)
|
| 21 |
|
| 22 |
## <a href="https://archietan.com/synthetic-ct-demo" style="color:blue; text-decoration:underline;">Live Interactive Demo</a>
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
| 25 |
</p>
|
| 26 |
|
|
|
|
| 27 |
|
| 28 |
## Model Architecture
|
| 29 |
|
| 30 |
-
- **Base Model**: U-Net with 5-level encoder
|
| 31 |
-
- **Input**: 4-channel
|
| 32 |
-
- **Conditioning**: Segmentation masks (4-channel
|
| 33 |
-
- **Output**: 4-channel
|
| 34 |
-
- **Sampling**: Euler
|
| 35 |
-
- **Training**: Score matching loss with conditional generation
|
|
|
|
|
|
|
| 36 |
|
| 37 |
## Model Details
|
| 38 |
|
| 39 |
-
- **Training Data**: 3,346
|
| 40 |
-
- **Lambda Parameter**: 25.0 (diffusion coefficient)
|
| 41 |
-
- **Embedding Dimension**: 256
|
| 42 |
-
- **Channels**: [32, 64, 128, 256, 512]
|
| 43 |
-
- **Activation**: SiLU (Swish)
|
| 44 |
|
| 45 |
-
|
| 46 |
|
| 47 |
-
|
| 48 |
-
- You have a **limited dataset size** (e.g., only a few hundred scans).
|
| 49 |
-
- You want to **balance underrepresented anatomical variations** or rare conditions.
|
| 50 |
-
- You need **synthetic augmentation** for training deep learning models in tasks such as segmentation, detection, or classification.
|
| 51 |
|
| 52 |
-
|
| 53 |
-
-
|
| 54 |
-
-
|
| 55 |
-
-
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
### Using the Hugging Face API
|
| 59 |
|
|
@@ -67,7 +87,7 @@ model = AutoModelForImageGeneration.from_pretrained("your-username/your-model-na
|
|
| 67 |
# Generate images
|
| 68 |
conditioning_mask = torch.randn(1, 4, 256, 256) # Your segmentation mask
|
| 69 |
generated_image = model.generate(conditioning_mask)
|
| 70 |
-
|
| 71 |
|
| 72 |
### Local Usage
|
| 73 |
|
|
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
---
|
| 4 |
+
|
| 5 |
# Conditional Diffusion Model for Medical Image Generation
|
| 6 |
|
| 7 |
+
This repository contains a conditional diffusion model trained to generate **3D medical CT scan images** based on segmentation masks.
|
| 8 |
+
The model uses a **U-Net architecture with score-based diffusion** for high-quality medical image synthesis.
|
| 9 |
+
|
| 10 |
+
---
|
| 11 |
|
| 12 |
+
## Real or Fake Image?
|
| 13 |
|
| 14 |
+
<p align="center">
|
|
|
|
| 15 |
<img src="assets/real_fake.png" alt="Sample real vs fake medical CT" width="600"/>
|
| 16 |
</p>
|
| 17 |
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
## Training Dataset
|
| 21 |
+
|
| 22 |
+
The model was trained on **3,346 CT scan examples** with corresponding segmentation masks (80/20 train–validation split).
|
| 23 |
+
|
| 24 |
+
<p align="center">
|
| 25 |
+
<img src="assets/dataset.png" alt="Sample dataset" width="600"/>
|
| 26 |
+
</p>
|
| 27 |
+
|
| 28 |
+
**Sources:**
|
| 29 |
+
1. [Kaggle Pancreas CT](https://www.kaggle.com/datasets/salihayesilyurt/pancreas-ct)
|
| 30 |
+
2. [Cancer Imaging Archive Pancreatic CT](https://nbia.cancerimagingarchive.net/nbia-search/)
|
| 31 |
+
3. [Annotated Medical Image Dataset for Segmentation Algorithms](https://drive.google.com/drive/folders/1HqEgzS8BV2c7xYNrZdEAnrHk7osJJ--2)
|
| 32 |
|
| 33 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
## <a href="https://archietan.com/synthetic-ct-demo" style="color:blue; text-decoration:underline;">Live Interactive Demo</a>
|
| 36 |
+
|
| 37 |
+
<p align="center">
|
| 38 |
+
<a href="https://archietan.com/synthetic-ct-demo">
|
| 39 |
+
<img src="assets/livedemo.png" alt="Sample input and output" width="600"/>
|
| 40 |
+
</a>
|
| 41 |
</p>
|
| 42 |
|
| 43 |
+
---
|
| 44 |
|
| 45 |
## Model Architecture
|
| 46 |
|
| 47 |
+
- **Base Model**: U-Net with 5-level encoder–decoder
|
| 48 |
+
- **Input**: 4-channel 256×256 CT scan images
|
| 49 |
+
- **Conditioning**: Segmentation masks (4-channel 256×256)
|
| 50 |
+
- **Output**: 4-channel 256×256 generated images
|
| 51 |
+
- **Sampling**: Euler–Maruyama sampler (250 steps)
|
| 52 |
+
- **Training**: Score matching loss with conditional generation
|
| 53 |
+
|
| 54 |
+
---
|
| 55 |
|
| 56 |
## Model Details
|
| 57 |
|
| 58 |
+
- **Training Data**: 3,346 CT scan examples
|
| 59 |
+
- **Lambda Parameter**: 25.0 (diffusion coefficient)
|
| 60 |
+
- **Embedding Dimension**: 256
|
| 61 |
+
- **Channels**: [32, 64, 128, 256, 512]
|
| 62 |
+
- **Activation**: SiLU (Swish)
|
| 63 |
|
| 64 |
+
---
|
| 65 |
|
| 66 |
+
## Usage
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
This model can be used to **add more diversity to your CT-scan dataset**, especially when:
|
| 69 |
+
- You have a **limited dataset size** (e.g., only a few hundred scans).
|
| 70 |
+
- You want to **balance underrepresented anatomical variations** or rare conditions.
|
| 71 |
+
- You need **synthetic augmentation** for training deep learning models in segmentation, detection, or classification.
|
| 72 |
|
| 73 |
+
**Example Applications**
|
| 74 |
+
- Generate training samples from segmentation masks to **reduce overfitting**.
|
| 75 |
+
- Create synthetic CT images with controlled variations to **test robustness**.
|
| 76 |
+
- Improve representation of minority cases to **reduce bias in medical AI**.
|
| 77 |
|
| 78 |
### Using the Hugging Face API
|
| 79 |
|
|
|
|
| 87 |
# Generate images
|
| 88 |
conditioning_mask = torch.randn(1, 4, 256, 256) # Your segmentation mask
|
| 89 |
generated_image = model.generate(conditioning_mask)
|
| 90 |
+
|
| 91 |
|
| 92 |
### Local Usage
|
| 93 |
|