Update README.md
Browse files
README.md
CHANGED
|
@@ -9,4 +9,74 @@ tags:
|
|
| 9 |
- medical
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
- medical
|
| 10 |
---
|
| 11 |
|
| 12 |
+
## Installation
|
| 13 |
+
|
| 14 |
+
First, clone the repository:
|
| 15 |
+
|
| 16 |
+
```bash
|
| 17 |
+
git clone https://github.com/ethicalabs-ai/SkinCancerViT.git
|
| 18 |
+
cd SkinCancerViT
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
Then, install the package in editable mode using uv (or pip):
|
| 22 |
+
|
| 23 |
+
```bash
|
| 24 |
+
uv sync # Recommended if you use uv
|
| 25 |
+
# Or, if using pip:
|
| 26 |
+
# pip install -e .
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
## Quick Start / Usage
|
| 30 |
+
|
| 31 |
+
This package allows you to load and use a pre-trained SkinCancerViT model for prediction.
|
| 32 |
+
|
| 33 |
+
```python
|
| 34 |
+
import torch
|
| 35 |
+
from skincancer_vit.model import SkinCancerViTModel
|
| 36 |
+
from PIL import Image
|
| 37 |
+
from datasets import load_dataset # To get a random sample
|
| 38 |
+
|
| 39 |
+
# Load the model from Hugging Face Hub
|
| 40 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 41 |
+
model = SkinCancerViTModel.from_pretrained("ethicalabs/SkinCancerViT")
|
| 42 |
+
model.to(device) # Move model to the desired device
|
| 43 |
+
model.eval() # Set model to evaluation mode
|
| 44 |
+
|
| 45 |
+
# Example Prediction from a Specific Image File
|
| 46 |
+
image_file_path = "images/patient-001.jpg" # Specify your image file path here
|
| 47 |
+
specific_image = Image.open(image_file_path).convert("RGB")
|
| 48 |
+
|
| 49 |
+
# Example tabular data for this prediction
|
| 50 |
+
specific_age = 42
|
| 51 |
+
specific_localization = "face" # Ensure this matches one of your trained localization categories
|
| 52 |
+
|
| 53 |
+
predicted_dx, confidence = model.full_predict(
|
| 54 |
+
raw_image=specific_image,
|
| 55 |
+
raw_age=specific_age,
|
| 56 |
+
raw_localization=specific_localization,
|
| 57 |
+
device=device
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
print(f"Predicted Diagnosis: {predicted_dx}")
|
| 61 |
+
print(f"Confidence: {confidence:.4f}")
|
| 62 |
+
|
| 63 |
+
# Example Prediction from a Random Validation Sample from the Dataset
|
| 64 |
+
dataset = load_dataset("marmal88/skin_cancer", split="test")
|
| 65 |
+
random_sample = dataset.shuffle(seed=42).select(range(1))[0] # Get the first shuffled sample
|
| 66 |
+
|
| 67 |
+
sample_image = random_sample["image"]
|
| 68 |
+
sample_age = random_sample["age"]
|
| 69 |
+
sample_localization = random_sample["localization"]
|
| 70 |
+
sample_true_dx = random_sample["dx"]
|
| 71 |
+
|
| 72 |
+
predicted_dx_sample, confidence_sample = model.full_predict(
|
| 73 |
+
raw_image=sample_image,
|
| 74 |
+
raw_age=sample_age,
|
| 75 |
+
raw_localization=sample_localization,
|
| 76 |
+
device=device
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
print(f"Predicted Diagnosis: {predicted_dx_sample}")
|
| 80 |
+
print(f"Confidence: {confidence_sample:.4f}")
|
| 81 |
+
print(f"Correct Prediction: {predicted_dx_sample == sample_true_dx}")
|
| 82 |
+
```
|