Downloads · 30 days
0
Arga23/dementia-cgan-mri
dementia-cgan-mri is a machine learning model from Arga23. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
This is a Conditional Deep Convolutional GAN (DCGAN) trained to generate synthetic brain MRI images for different Alzheimer's dementia severity stages.
Downloads · 30 days
0
Access
Public
Updated Dec 25, 2025
Repo size
14.6 MB
Likes
0
Public
Click a slice to open those files.
.pth14.6 MB · 100%
From the Hugging Face model README
This is a Conditional Deep Convolutional GAN (DCGAN) trained to generate synthetic brain MRI images for different Alzheimer's dementia severity stages.
Approach: noise + stage_label → synthetic_brain_MRI
Model evaluation is conducted qualitatively through visual inspection.
# Install dependencies
pip install torch torchvision huggingface_hub pillow
# Download model_architecture.py and inference.py from this repo
# Then run:
python inference.py
The script will automatically:
generated_stage_0.png, generated_stage_1.png, etc.import torch
from huggingface_hub import hf_hub_download
from PIL import Image
# Download model architecture first
# (Get model_architecture.py from this repo)
from model_architecture import Generator
# Download generator checkpoint from HuggingFace
model_path = hf_hub_download(
repo_id="Arga23/dementia-cgan-mri",
filename="cDCGAN_generator.pth"
)
# Load checkpoint
device = "cuda" if torch.cuda.is_available() else "cpu"
checkpoint = torch.load(model_path, map_location=device)
# Initialize Generator
G = Generator(
z_dim=checkpoint['z_dim'],
num_classes=checkpoint['num_classes'],
img_channels=1
).to(device)
G.load_state_dict(checkpoint['model'])
G.eval()
# Generate image for specific dementia stage
def generate_sample(stage):
with torch.no_grad():
z = torch.randn(1, checkpoint['z_dim'], 1, 1).to(device)
label = torch.tensor([stage]).to(device)
img = G(z, label)
img = (img.squeeze().cpu() + 1) / 2
img = torch.clamp(img, 0, 1)
return Image.fromarray((img.numpy() * 255).astype('uint8'), mode='L')
# Example: Generate Stage 2 (Mild Dementia)
img = generate_sample(stage=2)
img.save('generated_mild_dementia.png')
cDCGAN_generator.pth: Generator weights (inference-ready)model_architecture.py: PyTorch Generator architectureinference.py: Ready-to-use inference script (downloads from HuggingFace)torch>=2.0.0
torchvision
huggingface_hub
pillow
⚠️ FOR RESEARCH AND EDUCATIONAL PURPOSES ONLY
Generated images should NOT be used for clinical diagnosis or medical decisions. This model is trained on the OASIS dataset for research purposes only.