Views
No views yet

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)

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


1from huggingface_hub import snapshot_download
2
3# Download entire model directory (MLflow Model)
4model_dir = snapshot_download(repo_id="KaiSKX/Alzheimer_ConvNeXtCNN", repo_type="model")
5
6# or download specific format (.onnx)
7from huggingface_hub import hf_hub_download
8onnx_path = hf_hub_download(repo_id="KaiSKX/Alzheimer_ConvNeXtCNN", filename="onnx/convnext_model.onnx", repo_type="model")
9
10# or download specific format (.pth)
11from huggingface_hub import hf_hub_download
12onnx_path = hf_hub_download(repo_id="KaiSKX/Alzheimer_ConvNeXtCNN", filename="data/model.pth", repo_type="model")1import mlflow.pytorch
2import torch
3from PIL import Image
4import torchvision.transforms as transforms
5import time
6
7# Load MLflow model
8model = mlflow.pytorch.load_model("Alzheimer_ConvNeXtCNN")
9model.eval()
10
11# Define class names for mapping
12class_names = ["Mild Demented", "Moderate Demented", "Non Demented", "Very Mild Demented"]
13
14# Prepare input
15transform = transforms.Compose([
16 transforms.Resize((224, 224)),
17 transforms.ToTensor(),
18 transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
19])
20
21image = Image.open("C:/Users/dream/Downloads/test_dataset/ModerateDemented/moderateDem39.jpg").convert("RGB")
22input_data = transform(image).unsqueeze(0)
23
24# Inference with timing [optional for time]
25with torch.no_grad():
26 start_time = time.time()
27 output = model(input_data)
28 end_time = time.time()
29
30predicted_class = torch.argmax(output, dim=1).item()
31inference_time = (end_time - start_time) * 1000
32
33print(f"Predicted class: {class_names[predicted_class]}")
34print(f"Inference time: {inference_time:.2f} ms")1import onnxruntime as ort
2import numpy as np
3from PIL import Image
4import torchvision.transforms as transforms
5import time
6
7# Load ONNX model
8session = ort.InferenceSession("onnx/convnext_model.onnx")
9input_name = session.get_inputs()[0].name
10
11# Define class names for mapping
12class_names = ["Mild Demented", "Moderate Demented", "Non Demented", "Very Mild Demented"]
13
14# Prepare input
15transform = transforms.Compose([
16 transforms.Resize((224, 224)),
17 transforms.ToTensor(),
18 transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
19])
20
21image = Image.open("C:/Users/dream/Downloads/test_dataset/ModerateDemented/moderateDem39.jpg").convert("RGB")
22input_data = transform(image).unsqueeze(0).numpy().astype(np.float32)
23
24# Inference with timing [optional for time]
25start_time = time.time()
26output = session.run(None, {input_name: input_data})[0]
27end_time = time.time()
28
29inference_time = (end_time - start_time) * 1000
30predicted_class = np.argmax(output, axis=1)[0]
31
32print(f"Predicted class: {class_names[predicted_class]}")
33print(f"Inference time: {inference_time:.2f} ms")timmNVIDIA T4 * 2Databricks MLflow integration for experiment tracking and model registry