CoolFace
Modelpublic

ethicalabs/SkinCancerViT

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
1likes93downloads
README.md82 linesDownload Raw Back to root
1---2license: apache-2.03datasets:4- marmal88/skin_cancer5base_model:6- google/vit-base-patch16-224-in21k7pipeline_tag: image-classification8tags:9- medical10---11 12## Installation13 14First, clone the repository:15 16```bash17git clone https://github.com/ethicalabs-ai/SkinCancerViT.git18cd SkinCancerViT19```20 21Then, install the package in editable mode using uv (or pip):22 23```bash24uv sync   # Recommended if you use uv25# Or, if using pip:26# pip install -e .27```28 29## Quick Start / Usage30 31This package allows you to load and use a pre-trained SkinCancerViT model for prediction.32 33```python34import torch35from skincancer_vit.model import SkinCancerViTModel36from PIL import Image37from datasets import load_dataset   # To get a random sample38 39# Load the model from Hugging Face Hub40device = torch.device("cuda" if torch.cuda.is_available() else "cpu")41model = SkinCancerViTModel.from_pretrained("ethicalabs/SkinCancerViT")42model.to(device)   # Move model to the desired device43model.eval()   # Set model to evaluation mode44 45# Example Prediction from a Specific Image File46image_file_path = "images/patient-001.jpg"   # Specify your image file path here47specific_image = Image.open(image_file_path).convert("RGB")48 49# Example tabular data for this prediction50specific_age = 4251specific_localization = "face"   # Ensure this matches one of your trained localization categories52 53predicted_dx, confidence = model.full_predict(54    raw_image=specific_image,55    raw_age=specific_age,56    raw_localization=specific_localization,57    device=device58)59 60print(f"Predicted Diagnosis: {predicted_dx}")61print(f"Confidence: {confidence:.4f}")62 63# Example Prediction from a Random Test Sample from the Dataset64dataset = load_dataset("marmal88/skin_cancer", split="test")65random_sample = dataset.shuffle(seed=42).select(range(1))[0] # Get the first shuffled sample66 67sample_image = random_sample["image"]68sample_age = random_sample["age"]69sample_localization = random_sample["localization"]70sample_true_dx = random_sample["dx"]71 72predicted_dx_sample, confidence_sample = model.full_predict(73    raw_image=sample_image,74    raw_age=sample_age,75    raw_localization=sample_localization,76    device=device77)78 79print(f"Predicted Diagnosis: {predicted_dx_sample}")80print(f"Confidence: {confidence_sample:.4f}")81print(f"Correct Prediction: {predicted_dx_sample == sample_true_dx}")82```