Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,146 @@
|
|
1 |
-
---
|
2 |
-
license: mit
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
---
|
4 |
+
ViT-Base-Patch16-224-in21k Fine-tuned on Skin Disease Image Dataset
|
5 |
+
Model Description
|
6 |
+
This model is a fine-tuned version of the google/vit-base-patch16-224-in21k Vision Transformer model for image classification tasks. It has been fine-tuned on a custom skin disease image dataset containing 10 classes of skin diseases.
|
7 |
+
Intended Use
|
8 |
+
The model is designed to classify images of skin lesions into one of 10 categories of skin diseases. It can be used for educational purposes, research, or as a starting point for further fine-tuning.
|
9 |
+
Note: This model is not intended for clinical or diagnostic use. Always consult a qualified healthcare professional for medical advice.
|
10 |
+
How to Use
|
11 |
+
Installation
|
12 |
+
Ensure you have the following packages installed:
|
13 |
+
bash
|
14 |
+
|
15 |
+
|
16 |
+
pip install transformers
|
17 |
+
pip install torch
|
18 |
+
pip install torchvision
|
19 |
+
pip install Pillow
|
20 |
+
Loading the Model
|
21 |
+
python
|
22 |
+
|
23 |
+
|
24 |
+
import torch
|
25 |
+
from transformers import ViTForImageClassification, ViTImageProcessor
|
26 |
+
from PIL import Image
|
27 |
+
|
28 |
+
# Load the fine-tuned model
|
29 |
+
model_name = 'your_username/your_model_name' # Replace with your actual model path on Hugging Face Hub
|
30 |
+
model = ViTForImageClassification.from_pretrained(model_name)
|
31 |
+
model.eval()
|
32 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
33 |
+
model.to(device)
|
34 |
+
|
35 |
+
# Load the image processor
|
36 |
+
image_processor = ViTImageProcessor.from_pretrained(model_name)
|
37 |
+
Making Predictions
|
38 |
+
python
|
39 |
+
|
40 |
+
|
41 |
+
def predict(image_path):
|
42 |
+
# Load and preprocess the image
|
43 |
+
image = Image.open(image_path).convert('RGB')
|
44 |
+
inputs = image_processor(images=image, return_tensors="pt")
|
45 |
+
inputs = {k: v.to(device) for k, v in inputs.items()}
|
46 |
+
|
47 |
+
# Perform inference
|
48 |
+
with torch.no_grad():
|
49 |
+
outputs = model(**inputs)
|
50 |
+
logits = outputs.logits
|
51 |
+
predicted_class_idx = logits.argmax(-1).item()
|
52 |
+
predicted_class = model.config.id2label[str(predicted_class_idx)]
|
53 |
+
return predicted_class
|
54 |
+
|
55 |
+
# Example usage
|
56 |
+
image_path = 'path/to/your/image.jpg' # Replace with the path to your image
|
57 |
+
predicted_class = predict(image_path)
|
58 |
+
print(f"Predicted class: {predicted_class}")
|
59 |
+
Labels
|
60 |
+
The model predicts one of the following classes:
|
61 |
+
Eczema
|
62 |
+
Warts
|
63 |
+
Melanoma
|
64 |
+
Atopic Dermatitis
|
65 |
+
Basal Cell Carcinoma
|
66 |
+
Melanocytic Nevi
|
67 |
+
Benign Keratosis-like Lesions
|
68 |
+
Psoriasis
|
69 |
+
Seborrheic Keratoses
|
70 |
+
Fungal Infections
|
71 |
+
Dataset
|
72 |
+
The model was trained on the Skin Diseases Image Dataset available on Kaggle.
|
73 |
+
Dataset Details
|
74 |
+
Number of Classes: 10
|
75 |
+
Total Images: Approximately 40,000
|
76 |
+
Classes Included:
|
77 |
+
Eczema
|
78 |
+
Warts, Molluscum, and other Viral Infections
|
79 |
+
Melanoma
|
80 |
+
Atopic Dermatitis
|
81 |
+
Basal Cell Carcinoma
|
82 |
+
Melanocytic Nevi
|
83 |
+
Benign Keratosis-like Lesions
|
84 |
+
Psoriasis, Lichen Planus, and related diseases
|
85 |
+
Seborrheic Keratoses and other Benign Tumors
|
86 |
+
Tinea, Ringworm, Candidiasis, and other Fungal Infections
|
87 |
+
Data Preprocessing
|
88 |
+
Image Size: Resized to 224x224 pixels
|
89 |
+
Normalization: Images are normalized using ImageNet statistics:
|
90 |
+
Mean: [0.485, 0.456, 0.406]
|
91 |
+
Standard Deviation: [0.229, 0.224, 0.225]
|
92 |
+
Data Splits
|
93 |
+
Training Set: 70%
|
94 |
+
Validation Set: 15%
|
95 |
+
Test Set: 15%
|
96 |
+
The data was split in a stratified manner to maintain the class distribution across all splits.
|
97 |
+
Training Procedure
|
98 |
+
Base Model: google/vit-base-patch16-224-in21k
|
99 |
+
Framework: PyTorch with Hugging Face Transformers
|
100 |
+
Optimizer: AdamW
|
101 |
+
Learning Rate: 5e-5
|
102 |
+
Batch Size: 16
|
103 |
+
Number of Epochs: 5
|
104 |
+
Loss Function: Cross-Entropy Loss
|
105 |
+
Training Steps
|
106 |
+
Model Initialization:
|
107 |
+
Loaded the pre-trained ViT model.
|
108 |
+
Adjusted the classifier head to match the number of classes.
|
109 |
+
Data Loading:
|
110 |
+
Created custom datasets for training, validation, and testing.
|
111 |
+
Used DataLoader with appropriate batch sizes.
|
112 |
+
Training Loop:
|
113 |
+
For each epoch:
|
114 |
+
Training Phase:
|
115 |
+
Processed batches of images and labels.
|
116 |
+
Computed loss and performed backpropagation.
|
117 |
+
Validation Phase:
|
118 |
+
Evaluated model performance on the validation set.
|
119 |
+
Evaluation Results
|
120 |
+
Validation Accuracy: Approximately 70%
|
121 |
+
Test Accuracy: Approximately 71%
|
122 |
+
Performance Observations
|
123 |
+
The model shows reasonable performance given the complexity of the task and the number of classes.
|
124 |
+
Further training, hyperparameter tuning, or data augmentation may improve results.
|
125 |
+
Limitations
|
126 |
+
Non-Clinical Use: The model is not suitable for clinical diagnostics.
|
127 |
+
Data Bias: Potential biases due to class imbalance in the dataset.
|
128 |
+
Generalization: The model may not perform well on images outside the dataset domain (e.g., different lighting conditions, image quality).
|
129 |
+
Ethical Considerations
|
130 |
+
Privacy: Ensure that any images used with this model comply with privacy regulations and that patients cannot be identified.
|
131 |
+
Responsibility: Use the model responsibly, acknowledging its limitations and the potential consequences of misclassification.
|
132 |
+
Citation
|
133 |
+
If you use this model, please cite it as:
|
134 |
+
bibtex
|
135 |
+
|
136 |
+
|
137 |
+
@misc{vit_skin_disease_model,
|
138 |
+
title={ViT Fine-tuned on Skin Disease Image Dataset},
|
139 |
+
author={Your Name},
|
140 |
+
year={2023},
|
141 |
+
publisher={Hugging Face},
|
142 |
+
howpublished={\url{https://huggingface.co/your_username/your_model_name}},
|
143 |
+
}
|
144 |
+
References
|
145 |
+
Vision Transformer (ViT) Paper
|
146 |
+
Hugging Face ViT Documentation
|