File size: 4,240 Bytes
d80736e
 
 
 
43fd7a2
d80736e
 
 
 
 
 
 
 
 
43fd7a2
 
d80736e
 
43fd7a2
 
 
 
 
 
 
 
 
 
 
 
d80736e
 
 
3a386f4
 
 
 
 
 
 
 
4b0d140
 
43fd7a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
tags:
- autotrain
- image-classification
- vision
widget:
- src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/tiger.jpg
  example_title: Tiger
- src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/teapot.jpg
  example_title: Teapot
- src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/palace.jpg
  example_title: Palace
datasets:
- mujammil131/eyeDiseasDdetectionModel
license: apache-2.0
pipeline_tag: image-classification
---

## EyeDiseaseClassifier(Small-Sized model)

It is a fine tuned version of [BEiT-base-path-16](https://huggingface.co/microsoft/beit-base-patch16-224-pt22k-ft22k). It is trained on this [dataset](https://huggingface.co/datasets/mujammil131/eyeDiseasDdetectionModel).

## Model description

The BEiT model is a Vision Transformer (ViT), which is a transformer encoder model (BERT-like). In contrast to the original ViT model, BEiT is pretrained on a large collection of images in a self-supervised fashion, namely ImageNet-21k, at a resolution of 224x224 pixels. The pre-training objective for the model is to predict visual tokens from the encoder of OpenAI's DALL-E's VQ-VAE, based on masked patches.
Next, the model was fine-tuned in a supervised fashion on ImageNet (also referred to as ILSVRC2012), a dataset comprising 1 million images and 1,000 classes, also at resolution 224x224.

Images are presented to the model as a sequence of fixed-size patches (resolution 16x16), which are linearly embedded. Contrary to the original ViT models, BEiT models do use relative position embeddings (similar to T5) instead of absolute position embeddings, and perform classification of images by mean-pooling the final hidden states of the patches, instead of placing a linear layer on top of the final hidden state of the [CLS] token.

By pre-training the model, it learns an inner representation of images that can then be used to extract features useful for downstream tasks: if you have a dataset of labeled images for instance, you can train a standard classifier by placing a linear layer on top of the pre-trained encoder. One typically places a linear layer on top of the [CLS] token, as the last hidden state of this token can be seen as a representation of an entire image. Alternatively, one can mean-pool the final hidden states of the patch embeddings, and place a linear layer on top of that.


## Validation Metrics
loss: 0.1152728122006607

f1: 0.9755686604886269

precision: 0.9780405405405406

recall: 0.973109243697479

auc: 0.9916270580630442

accuracy: 0.9644607843137255

### How to use

Here is how to use this model to identify from the image of the patient's retina:

```python
from transformers import AutoImageProcessor, AutoModelForImageClassification
from PIL import Image
import requests

processor = AutoImageProcessor.from_pretrained("NeuronZero/EyeDiseaseClassifier")
model = AutoModelForImageClassification.from_pretrained("NeuronZero/EyeDiseaseClassifier")

#dataset URL: "https://www.kaggle.com/code/abdallahwagih/eye-diseases-classification-acc-93-8"

image_url = "https://storage.googleapis.com/kagglesdsdata/datasets/2440665/4130910/dataset/glaucoma/1212_left.jpg?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=databundle-worker-v2%40kaggle-161607.iam.gserviceaccount.com%2F20240404%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20240404T083818Z&X-Goog-Expires=345600&X-Goog-SignedHeaders=host&X-Goog-Signature=1cff9e2a92a0c7c95480fe62cf34997660823af8e0191daac8d80cbe3bfc4cc719e64e6510a128eba87fa3753836214920bd44ba2ede9ba9991b0cc31f60813d9db185245055b72672016d7d2a4ff70bc4684d5756ac445aa3899d63998eee62067b7f4022697dd2baf9222f77b0b27e30f16310f3dafc3cc0249251006a4c48bf6d36ad37d7ca07b89c32f71482f71d62e6ae26b81af3678a9e3a76c1555d30e921cc721f6b72080c25d86d8a28b4f4b2530896a89dc00668c4f01ec960e5d4eb372c9aef85e85dd072d94178ef8fb4e494ae4cea4348717213954bdfa3f239c7cc92415bf4c6e01d497f479944d63844f1cd97d01c63c4651c0c7514ecfe4a"
image = Image.open(requests.get(image_url, stream=True).raw)

inputs = processor(images=image, return_tensors="pt")
outputs = model(**inputs)
logits = outputs.logits
predicted_class_idx = logits.argmax(-1).item()
print("Predicted class:", model.config.id2label[predicted_class_idx])
```