Vbai-DPA 2.4 Sürümü (TR)

Python PyTorch License

Model Boyut Parametre mAPᵛᵃᴵ APᵛᵃᴵ CPU b1 V100 b1 V100 b32
Vbai-DPA 2.4f 224 38.68M %56.66 %53.80 28.8ms 14.4ms 3.64ms
Vbai-DPA 2.4c 224 77.52M %62.87 %60.54 40.33ms 20.16ms 4.03ms
Vbai-DPA 2.4q 224 131.30M %82.93 %87.45 85.48ms 42.74ms 8.55ms

Tanım

Vbai-DPA 2.4 (Dementia, Parkinson, Alzheimer) modeli, MRI veya fMRI görüntüsü üzerinden beyin hastalıklarını teşhis etmek amacıyla eğitilmiş ve geliştirilmiştir. Hastanın parkinson olup olmadığını, demans durumunu ve alzheimer riskini yüksek doğruluk oranı ile göstermektedir. Vbai-DPA 2.3'e göre görüntüde işaretleme yapma özelliği eklenip, ince ayar ve daha fazla veri ile eğitilmiş versiyonlarıdır.

Kitle / Hedef

Vbai modelleri tamamen öncelik olarak hastaneler, sağlık merkezleri ve bilim merkezleri için geliştirilmiştir.

Sınıflar

  • Alzheimer Hastası: Hasta kişi, kesinlikle alzheimer hastasıdır.
  • Ortalama Alzheimer Riski: Hasta kişi, yakın bir zamanda alzheimer olabilir.
  • Hafif Alzheimer Riski: Hasta kişinin, alzheimer olması için biraz daha zamanı vardır.
  • Çok Hafif Alzheimer Riski: Hasta kişinin, alzheimer seviyesine gelmesine zaman vardır.
  • Risk Yok: Kişinin herhangi bir riski bulunmamaktadır.
  • Parkinson Hastası: Kişi, parkinson hastasıdır.

----------------------------------------

Vbai-DPA 2.3 Versions (EN)

Model Test Size Params mAPᵛᵃᴵ APᵛᵃᴵ CPU b1 V100 b1 V100 b32
Vbai-DPA 2.4f 224 38.68M 56.66% 53.80% 28.8ms 14.4ms 3.64ms
Vbai-DPA 2.4c 224 77.52M 62.87% 60.54% 40.33ms 20.16ms 4.03ms
Vbai-DPA 2.4q 224 131.30M 82.93% 87.45% 85.48ms 42.74ms 8.55ms

Description

The Vbai-DPA 2.4 (Dementia, Parkinson's, Alzheimer's) model has been trained and developed to diagnose brain diseases using MRI or fMRI images. It indicates whether the patient has Parkinson's disease, dementia, and Alzheimer's risk with a high accuracy rate. Compared to Vbai-DPA 2.3, it features image annotation capabilities and has been trained with fine-tuning and additional data.

Audience / Target

Vbai models are developed exclusively for hospitals, health centres and science centres.

Classes

  • Alzheimer's disease: The sick person definitely has Alzheimer's disease.
  • Average Risk of Alzheimer's Disease: The sick person may develop Alzheimer's disease in the near future.
  • Mild Alzheimer's Risk: The sick person has a little more time to develop Alzheimer's disease.
  • Very Mild Alzheimer's Risk: The sick person has time to reach the level of Alzheimer's disease.
  • No Risk: The person does not have any risk.
  • Parkinson's Disease: The person has Parkinson's disease.

Kullanım / Usage

import os
import torch
import torch.nn.functional as F
from torchvision import transforms
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
import cv2
from pytorch_grad_cam import GradCAM
from pytorch_grad_cam.utils.model_targets import ClassifierOutputTarget
from checkpoint_model import CheckpointVbaiDPA24

TEST_IMAGE = "test/image/path"

MODEL = 'c' # Model type | f => fast, c => classic, q => quality

MODEL_PATHS = {
    'f': 'Vbai-DPA 2.4f.pt/model/path',
    'c': 'Vbai-DPA 2.4c.pt/model/path',
    'q': 'Vbai-DPA 2.4q.pt/model/path',
}

CLASS_NAMES = [
    'AD Alzheimer Diseases',
    'AD Mild Demented',
    'AD Moderate Demented',
    'AD Very Mild Demented',
    'CN Non Demented',
    'PD Parkinson Diseases'
]

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])
])

edge_transform = transforms.Compose([
    transforms.Resize((224, 224)),
    transforms.Grayscale(num_output_channels=1),
    transforms.ToTensor(),
])


def detect_brain_edges(edge_tensor):
    edge_np = edge_tensor.squeeze().cpu().numpy()
    edge_np = ((edge_np - edge_np.min()) / (edge_np.max() - edge_np.min() + 1e-8) * 255).astype(np.uint8)
    edges = cv2.Canny(edge_np, 50, 150)

    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
    edges_closed = cv2.morphologyEx(edges, cv2.MORPH_CLOSE, kernel)
    contours, _ = cv2.findContours(edges_closed, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    contours = sorted(contours, key=cv2.contourArea, reverse=True)[:3]

    return edges, contours


def main():
    print("\n" + "="*70)
    print("Vbai-DPA 2.4")
    print("="*70)

    device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
    print(f"✓ Device: {device}")

    print(f"✓ Loading model: Vbai-DPA 2.4{MODEL.upper()}")
    model = CheckpointVbaiDPA24(model_type=MODEL, num_classes=6).to(device)
    checkpoint = torch.load(MODEL_PATHS[MODEL], map_location=device, weights_only=False)
    model.load_state_dict(checkpoint.get('model_state_dict', checkpoint))
    model.eval()

    target_layer = model.conv_layers[12] if MODEL == 'q' else model.conv_layers[8]
    cam = GradCAM(model=model, target_layers=[target_layer])

    print(f"✓ Loading image: {os.path.basename(TEST_IMAGE)}")
    img = Image.open(TEST_IMAGE).convert('RGB')
    inp = transform(img).unsqueeze(0).to(device)
    edge_tensor = edge_transform(img).unsqueeze(0).to(device)

    print(f"✓ Prediction...")
    with torch.no_grad():
        output, attention_map = model(inp, edge_tensor)
        probs = F.softmax(output, dim=1)
        pred = output.argmax(1).item()
        conf = probs[0, pred].item() * 100
        top3_probs, top3_indices = torch.topk(probs[0], 3)

    print("\n" + "="*70)
    print("RESULTS:")
    print("="*70)
    print(f"✓ Main Pred: {CLASS_NAMES[pred]}")
    print(f"✓ Confidence Score: {conf:.2f}%")
    print(f"\nTop-3 Predictions:")
    for i, (idx, prob) in enumerate(zip(top3_indices, top3_probs), 1):
        print(f"  {i}. {CLASS_NAMES[idx.item()]}: {prob.item()*100:.2f}%")
    print("="*70)

    print(f"\n✓ Analysing brain structure...")
    edges, contours = detect_brain_edges(edge_tensor)

    print(f"✓ Calculating Grad-CAM...")
    cam_mask = cam(input_tensor=inp, targets=[ClassifierOutputTarget(pred)])[0]
    cam_mask = np.squeeze(cam_mask)

    att_np = attention_map[0].mean(0).cpu().numpy()
    att_np = (att_np - att_np.min()) / (att_np.max() - att_np.min() + 1e-8)
    att_np = cv2.resize(att_np, (224, 224))

    print(f"✓ Creating visualization...")
    fig, axes = plt.subplots(2, 3, figsize=(18, 12))

    axes[0, 0].imshow(img)
    axes[0, 0].set_title('Original MRI', fontsize=14, fontweight='bold')
    axes[0, 0].axis('off')

    axes[0, 1].imshow(edges, cmap='gray')
    axes[0, 1].set_title('Brain Edges', fontsize=14, fontweight='bold')
    axes[0, 1].axis('off')

    img_contours = np.array(img.resize((224, 224)))
    img_contours = cv2.cvtColor(img_contours, cv2.COLOR_RGB2BGR)
    if contours:
        cv2.drawContours(img_contours, contours, -1, (0, 255, 0), 2)
        for i, cnt in enumerate(contours):
            M = cv2.moments(cnt)
            if M['m00'] != 0:
                cx, cy = int(M['m10']/M['m00']), int(M['m01']/M['m00'])
                cv2.circle(img_contours, (cx, cy), 5, (255, 0, 0), -1)
                cv2.putText(img_contours, f"{i+1}", (cx+10, cy),
                          cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 0, 0), 2)
    img_contours = cv2.cvtColor(img_contours, cv2.COLOR_BGR2RGB)
    axes[0, 2].imshow(img_contours)
    axes[0, 2].set_title('Brain Structure Signs', fontsize=14, fontweight='bold')
    axes[0, 2].axis('off')

    im = axes[1, 0].imshow(att_np, cmap='hot')
    axes[1, 0].set_title('Attention Map', fontsize=14, fontweight='bold')
    axes[1, 0].axis('off')
    plt.colorbar(im, ax=axes[1, 0], fraction=0.046)

    im2 = axes[1, 1].imshow(cam_mask, cmap='jet')
    axes[1, 1].set_title('Grad-CAM', fontsize=14, fontweight='bold')
    axes[1, 1].axis('off')
    plt.colorbar(im2, ax=axes[1, 1], fraction=0.046)

    rgb_np = inp[0].permute(1, 2, 0).cpu().numpy()
    rgb_np = (rgb_np - rgb_np.min()) / (rgb_np.max() - rgb_np.min())
    cam_colored = cv2.applyColorMap(np.uint8(cam_mask * 255), cv2.COLORMAP_JET)
    cam_colored = cv2.cvtColor(cam_colored, cv2.COLOR_BGR2RGB) / 255.0
    overlay = cam_colored * 0.5 + rgb_np * 0.5
    overlay = np.clip(overlay, 0, 1)
    axes[1, 2].imshow(overlay)
    axes[1, 2].set_title(f'Prediction: {CLASS_NAMES[pred]}\nConfidence: {conf:.1f}%',
                        fontsize=14, fontweight='bold')
    axes[1, 2].axis('off')

    fig.suptitle(f'Vbai-DPA 2.4{MODEL.upper()} - {os.path.basename(TEST_IMAGE)}',
                fontsize=16, fontweight='bold', y=0.98)

    plt.tight_layout()

    output_file = f'quick_test_result_{MODEL}.png'
    plt.savefig(output_file, dpi=150, bbox_inches='tight')
    print(f"✓ Results saved: {output_file}")

    plt.show()

    print("\n✓ Test Completed!")
    print("="*70 + "\n")


if __name__ == '__main__':
    try:
        main()
    except Exception as e:
        print(f"\n✗ ERROR: {str(e)}")
        import traceback
        traceback.print_exc()
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Collection including Neurazum/Vbai-DPA-2.4