模型:

dhhd255/EfficientNet_ParkinsonsPred

英文

高效可信的帕金森病预测模型 🤗

该存储库包含使用患者绘图预测帕金森病的Hugging Face EfficientNet模型,准确率约为83%。使用EfficientNet和Torch制作。

概述

帕金森病是一种影响运动的进行性神经系统疾病。症状逐渐开始,有时只在一只手上出现轻微的震颤。震颤是常见的症状,但该疾病也常导致僵硬或运动减缓。

我的模型使用EfficientNet架构通过分析患者的绘图来预测患帕金森病的可能性。如果您愿意,可以随时发起拉取请求并进行贡献。

数据集

用于训练此模型的数据集由 Kaggle 提供。

用法

import torch
from transformers import AutoModel
from torch import nn
from PIL import Image
import numpy as np

# Set the device
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

# Load the trained model
model = AutoModel.from_pretrained('/content/final')

# Move the model to the device
model = model.to(device)

# Load and resize new image(s)
image_size = (224, 224)
new_image = Image.open('/content/health.png').convert('RGB').resize(image_size)
new_image = np.array(new_image)
new_image = torch.from_numpy(new_image).transpose(0, 2).float().unsqueeze(0)

# Move the data to the device
new_image = new_image.to(device)

# Make predictions using the trained model
with torch.no_grad():
    predictions = model(new_image)
    logits = predictions.last_hidden_state
    logits = logits.view(logits.shape[0], -1)
    num_classes=2
    feature_reducer = nn.Linear(logits.shape[1], num_classes)

    logits = logits.to(device)
    feature_reducer = feature_reducer.to(device)

    logits = feature_reducer(logits)
    predicted_class = torch.argmax(logits, dim=1).item()
    confidence = torch.softmax(logits, dim=1)[0][predicted_class].item()
    if(predicted_class == 0):
        print(f'Predicted class: Parkinson\'s with confidence {confidence:.2f}')
    else:
        print(f'Predicted class: Healthy with confidence {confidence:.2f}')