File size: 2,296 Bytes
9078a66
 
4adfae5
 
 
 
9078a66
4adfae5
 
e12b046
4adfae5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---
license: mit
inference: false
tags:
- medical
- code
---
# EfficientNet Parkinson's Prediction Model 🤗

This repository contains the Hugging Face EfficientNet model for predicting Parkinson's disease using patient drawings with an accuracy of around 83%.
Made w/ EfficientNet and Torch.

## Overview

Parkinson's disease is a progressive nervous system disorder that affects movement. Symptoms start gradually, sometimes starting with a barely noticeable tremor in just one hand. Tremors are common, but the disorder also commonly causes stiffness or slowing of movement.

My model uses the EfficientNet architecture to predict the likelihood of Parkinson's disease in patients by analysing their drawings. 
Feel free to open a pull request and contribute if you want to.

## Dataset

The dataset used to train this model was provided by [Kaggle](https://www.kaggle.com/datasets/kmader/parkinsons-drawings).

## Usage

```python
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}')