Downloads · 30 days
9
1% of all-time downloads
EnDevSols/Vision_Transformer_FineTuned
Vision_Transformer_FineTuned is a image classification model from EnDevSols. Use it when you need a label for an image. It is set up for transformers.
This repository hosts a Vision Transformer (ViT) model fine-tuned on the OASIS MRI dataset for the classification of brain MRI images based on the progression of Alzheimer's disease. The model categorizes images into…
Downloads · 30 days
9
1% of all-time downloads
All-time downloads
683
Public
Parameters
85.8M
343 MB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors343 MB · 100%
From the Hugging Face model README
This repository hosts a Vision Transformer (ViT) model fine-tuned on the OASIS MRI dataset for the classification of brain MRI images based on the progression of Alzheimer's disease. The model categorizes images into four classes: demented, very mild demented, mild demented, and non-demented.
The Vision Transformer has been adapted to tackle the challenging task of medical image analysis by leveraging its powerful attention mechanisms that capture complex patterns in image data. It has been fine-tuned to classify MRI images into stages of Alzheimer's disease, demonstrating the model's applicability to medical diagnostics.
The OASIS MRI dataset consists of 80,000 brain MRI images from 461 patients, formatted in Nifti (.nii) and converted to JPEG for model training. The images represent various stages of Alzheimer's disease as follows:
This dataset conversion involved standardizing image formats for machine learning applications, ensuring that each image is suitable for deep learning models.
During preprocessing:
You can use this model directly with a pipeline for image classification:
```python
import torch from transformers import ViTForImageClassification from PIL import Image import numpy as np from torchvision.transforms import Compose, Resize, ToTensor, Normalize
id2label = { 0: "Non-Demented", 1: "Very Mild Demented", 2: "Mild Demented", 3: "Demented" }
import torch from transformers import ViTForImageClassification from PIL import Image import numpy as np from torchvision.transforms import Compose, Resize, ToTensor, Normalize import matplotlib.pyplot as plt
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = ViTForImageClassification.from_pretrained('fawadkhan/ViT_FineTuned_on_ImagesOASIS') model.to(device) model.eval()
image_path = 'your image path.jpg' image = Image.open(image_path).convert("RGB")
transform = Compose([ Resize((224, 224)), # or the original input size of your model ToTensor(), Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) # Standard normalization for ImageNet ])
input_tensor = transform(image).unsqueeze(0) # Create a mini-batch as expected by the model input_tensor = input_tensor.to(device)
with torch.no_grad(): outputs = model(input_tensor) _, predicted = torch.max(outputs.logits, 1)
predicted_class = id2label[predicted[0].item()] print("Predicted class:", predicted_class)
plt.imshow(image) plt.title(f'Predicted class: {predicted_class}') plt.axis('off') # Turn off axis numbers and ticks plt.show()
```
The model was trained using the AdamW optimizer with a learning rate of 5e-5 for 10 epochs, balancing the need for accuracy with the risk of overfitting.
Upon evaluation on a validation set, the model achieved an accuracy of 99%, showcasing its effectiveness in identifying different stages of Alzheimer's disease based on MRI scans.