Diagnosis Models
Collection
Diagnosis with brain MRI or fMRI image. By Neurazum.
•
6 items
•
Updated
•
1
Vbai-DPA 2.0 (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 modelleri tamamen öncelik olarak hastaneler, sağlık merkezleri ve bilim merkezleri için geliştirilmiştir.
import torch
import torch.nn as nn
from torchvision import transforms
from PIL import Image
import matplotlib.pyplot as plt
import os
class SimpleCNN(nn.Module):
def __init__(self, num_classes=6):
super(SimpleCNN, self).__init__()
self.conv1 = nn.Conv2d(3, 32, kernel_size=3, stride=1, padding=1)
self.conv2 = nn.Conv2d(32, 64, kernel_size=3, stride=1, padding=1)
self.conv3 = nn.Conv2d(64, 128, kernel_size=3, stride=1, padding=1)
self.pool = nn.MaxPool2d(kernel_size=2, stride=2, padding=0)
self.fc1 = nn.Linear(128 * 28 * 28, 512)
self.fc2 = nn.Linear(512, num_classes)
self.relu = nn.ReLU()
self.dropout = nn.Dropout(0.5)
def forward(self, x):
x = self.pool(self.relu(self.conv1(x)))
x = self.pool(self.relu(self.conv2(x)))
x = self.pool(self.relu(self.conv3(x)))
x = x.view(-1, 128 * 28 * 28)
x = self.relu(self.fc1(x))
x = self.dropout(x)
x = self.fc2(x)
return x
def predict_image(model, image_path, transform, device):
image = Image.open(image_path).convert('RGB')
image = transform(image)
image = image.unsqueeze(0)
model.eval()
with torch.no_grad():
image = image.to(device)
outputs = model(image)
_, predicted = torch.max(outputs, 1)
probabilities = torch.nn.functional.softmax(outputs, dim=1)
confidence = probabilities[0, predicted].item() * 100
return predicted.item(), confidence, image
def main():
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])
])
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = SimpleCNN(num_classes=6).to(device)
model.load_state_dict(
torch.load('Vbai-DPA 2.0/model/yolu',
map_location=device))
image_path = 'test/görüntüsü/yolu'
predicted_class, confidence, image = predict_image(model, image_path, transform, device)
class_names = ['Alzheimer Hastası', 'Hafif Alzheimer Riski', 'Ortalama Alzheimer Riski', 'Çok Hafif Alzheimer Riski',
'Risk Yok', 'Parkinson Hastası']
print(f'Tahmin edilen sınıf: {class_names[predicted_class]}')
print(f'Doğruluk: {confidence}%')
total_params = sum(p.numel() for p in model.parameters())
print(f'Parametre sayısı: {total_params}')
plt.imshow(image.squeeze(0).permute(1, 2, 0))
plt.title(f'Tahmin: {class_names[predicted_class]} \nDoğruluk: {confidence:.2f}%')
plt.axis('off')
plt.show()
if __name__ == '__main__':
main()
Vbai-DPA 2.0 (Dementia, Parkinson, Alzheimer) model is trained and developed to diagnose brain diseases through MRI or fMRI images. It shows whether the patient has Parkinson's disease, dementia status and Alzheimer's risk with high accuracy.
Vbai models are developed entirely for hospitals, health centres and science centres as a priority.
import torch
import torch.nn as nn
from torchvision import transforms
from PIL import Image
import matplotlib.pyplot as plt
import os
class SimpleCNN(nn.Module):
def __init__(self, num_classes=6):
super(SimpleCNN, self).__init__()
self.conv1 = nn.Conv2d(3, 32, kernel_size=3, stride=1, padding=1)
self.conv2 = nn.Conv2d(32, 64, kernel_size=3, stride=1, padding=1)
self.conv3 = nn.Conv2d(64, 128, kernel_size=3, stride=1, padding=1)
self.pool = nn.MaxPool2d(kernel_size=2, stride=2, padding=0)
self.fc1 = nn.Linear(128 * 28 * 28, 512)
self.fc2 = nn.Linear(512, num_classes)
self.relu = nn.ReLU()
self.dropout = nn.Dropout(0.5)
def forward(self, x):
x = self.pool(self.relu(self.conv1(x)))
x = self.pool(self.relu(self.conv2(x)))
x = self.pool(self.relu(self.conv3(x)))
x = x.view(-1, 128 * 28 * 28)
x = self.relu(self.fc1(x))
x = self.dropout(x)
x = self.fc2(x)
return x
def predict_image(model, image_path, transform, device):
image = Image.open(image_path).convert('RGB')
image = transform(image)
image = image.unsqueeze(0)
model.eval()
with torch.no_grad():
image = image.to(device)
outputs = model(image)
_, predicted = torch.max(outputs, 1)
probabilities = torch.nn.functional.softmax(outputs, dim=1)
confidence = probabilities[0, predicted].item() * 100
return predicted.item(), confidence, image
def main():
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])
])
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = SimpleCNN(num_classes=6).to(device)
model.load_state_dict(
torch.load('Vbai-DPA 2.0/model/path',
map_location=device))
image_path = 'test/image/path'
predicted_class, confidence, image = predict_image(model, image_path, transform, device)
class_names = ['Alzheimer Disease', 'Mild Alzheimer Risk', 'Moderate Alzheimer Risk', 'Very Mild Alzheimer Risk',
'No Risk', 'Parkinson Disease']
print(f'Predicted Class: {class_names[predicted_class]}')
print(f'Accuracy: {confidence}%')
total_params = sum(p.numel() for p in model.parameters())
print(f'Params: {total_params}')
plt.imshow(image.squeeze(0).permute(1, 2, 0))
plt.title(f'Prediction: {class_names[predicted_class]} \nAccuracy: {confidence:.2f}%')
plt.axis('off')
plt.show()
if __name__ == '__main__':
main()