ONNX Model Zoo

KaiSKX/Alzheimer_ConvNeXtCNN

By KaiSKX · ↓ 0 · ♥ 0 · Updated 2025-09-28

What's in this repo

This page lists the files in KaiSKX/Alzheimer_ConvNeXtCNN, including convnext_model.onnx.

  • 1 ONNX models (.onnx files)
  • 16 files, including 4 .png, 2 .yaml, 2 .txt, 2 .json, 1 .md, 1 .pth
  • Last updated 2025-09-28

ONNX files

File Size Download
onnx/convnext_model.onnx — Download

How to use

These ONNX files can be loaded with ONNX Runtime. To inspect a model graph, upload the file to the Netron viewer. Download links point to the original files on Hugging Face.

README

ConvNeXt CNN classification for Alzheimer disease 🧠

PyTorch timm ONNX MLflow Databricks

ConvNeXt-based CNN for Alzheimer's disease classification from MRI images


🎯 Model Overview

A pre-trained ConvNeXt CNN model is fine-tuned for classifying Alzheimer's disease stages from brain MRI scans. The model distinguishes between 4 classes:

Classes:

  • Non-Demented
  • Very Mild Demented
  • Mild Demented
  • Moderate Demented

🏗️ Architecture & Approach

Backbone Model: ConvNeXt (Meta AI, 2022) - A modern SOTA CNN architecture inspired by Vision Transformers but built purely on convolutions.

Transfer Learning Strategy: Progressive unfreezing approach with ImageNet-pretrained weights:

Step 1: Train classification head only (10 epochs)
                        ↓
Step 2: Unfreeze stage 3 + head (5 epochs, reduced LR)
                        ↓
Step 3: Unfreeze stage 2 + stage 3 + head (5 epochs, further reduced LR)

📊 Dataset & Performance

Training Dataset Sample Sample of Alzheimer's MRI dataset used for training

⚡ Confusion Matrix & Accuracy

CMatrix Confusion Matrix for Alzheimer classification

Test Accuracy: 98.78% across 4 classes.

⚡ Inference Speed Benchmark (CPU)

Format Inference Time Relative Speed
PyTorch (.pth) 148.16 ms/image Baseline
ONNX (.onnx) 132.48 ms/image 1.12x faster

benchmark

benchmark

NOTE: The result is based on Kaggle notebook CPU environment. Different environment will have different effect but normally ONNX runtime engine has a better inference speed.


🚀 Quick Start

Download Models

from huggingface_hub import snapshot_download

# Download entire model directory (MLflow Model)
model_dir = snapshot_download(repo_id="KaiSKX/Alzheimer_ConvNeXtCNN", repo_type="model")

# or download specific format (.onnx)
from huggingface_hub import hf_hub_download
onnx_path = hf_hub_download(repo_id="KaiSKX/Alzheimer_ConvNeXtCNN", filename="onnx/convnext_model.onnx", repo_type="model")

# or download specific format (.pth)
from huggingface_hub import hf_hub_download
onnx_path = hf_hub_download(repo_id="KaiSKX/Alzheimer_ConvNeXtCNN", filename="data/model.pth", repo_type="model")

💻 Usage

MLflow Model (PyTorch flavor)

Best for: MLflow/Databricks deployment or inference

import mlflow.pytorch
import torch
from PIL import Image
import torchvision.transforms as transforms
import time

# Load MLflow model
model = mlflow.pytorch.load_model("Alzheimer_ConvNeXtCNN")
model.eval()

# Define class names for mapping
class_names = ["Mild Demented", "Moderate Demented", "Non Demented", "Very Mild Demented"]

# Prepare input
transform = transforms.Compose([
    transforms.Resize((224, 224)),
    transforms.ToTensor(),
    transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])

image = Image.open("C:/Users/dream/Downloads/test_dataset/ModerateDemented/moderateDem39.jpg").convert("RGB")
input_data = transform(image).unsqueeze(0)

# Inference with timing [optional for time]
with torch.no_grad():
    start_time = time.time()
    output = model(input_data)
    end_time = time.time()

predicted_class = torch.argmax(output, dim=1).item()
inference_time = (end_time - start_time) * 1000

print(f"Predicted class: {class_names[predicted_class]}")
print(f"Inference time: {inference_time:.2f} ms")

ONNX Runtime

Best for: Cross-platform compatibility and faster CPU inference

import onnxruntime as ort
import numpy as np
from PIL import Image
import torchvision.transforms as transforms
import time

# Load ONNX model
session = ort.InferenceSession("onnx/convnext_model.onnx")
input_name = session.get_inputs()[0].name

# Define class names for mapping
class_names = ["Mild Demented", "Moderate Demented", "Non Demented", "Very Mild Demented"]

# Prepare input
transform = transforms.Compose([
    transforms.Resize((224, 224)),
    transforms.ToTensor(),
    transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])

image = Image.open("C:/Users/dream/Downloads/test_dataset/ModerateDemented/moderateDem39.jpg").convert("RGB")
input_data = transform(image).unsqueeze(0).numpy().astype(np.float32)

# Inference with timing [optional for time]
start_time = time.time()
output = session.run(None, {input_name: input_data})[0]
end_time = time.time()

inference_time = (end_time - start_time) * 1000
predicted_class = np.argmax(output, axis=1)[0]

print(f"Predicted class: {class_names[predicted_class]}")
print(f"Inference time: {inference_time:.2f} ms")

🔧 Training Details

  • Dataset: Public Alzheimer's MRI dataset (see Kaggle Dataset)
  • Pretraining: ImageNet-pretrained ConvNeXt weights via timm
  • Multi-GPU: Parallel training acceleration via NVIDIA T4 * 2
  • MLOps: Databricks MLflow integration for experiment tracking and model registry

⚠️ Important Notice

Research & Portfolio Use Only: This model is developed for educational and portfolio demonstration purposes. It is NOT intended for professional clinical diagnosis, medical decision-making, or any real-world medical applications**.

For detailed training methodology and MLOps implementation, please refer to the Kaggle notebook.

Model info

onnx medical image-classification license:apache-2.0 region:us
↓ 0 ♥ 0

Created: 2025-09-25

Updated: 2025-09-28

View on Hugging Face

Files (16)

.gitattributes
MLmodel
README.md
Screenshot 2025-09-26 170634.png
Screenshot 2025-09-26 170726.png
Screenshot 2025-09-26 170736.png
Screenshot 2025-09-26 170746.png
conda.yaml
data/model.pth
data/pickle_module_info.txt
input_example.json
onnx/convnext_model.onnx ONNX
python_env.yaml
registered_model_meta
requirements.txt
serving_input_example.json

Related models