Views
No views yet
1from transformers import AutoModel
2
3model = AutoModel.from_pretrained(
4 "Digital-Dermatology/SkinMap",
5 trust_remote_code=True,
6 device="cuda", # "cpu" also works
7)
8
9# 1) Encode an image into the 1024-d SkinMap space (L2-normalized)
10img_emb = model.encode_image("lesion.jpg") # np.ndarray, shape (1024,)
11
12# 2) Encode a text query into the same space
13txt_emb = model.encode_text("melanoma on the back") # np.ndarray, shape (1024,)
14
15# 3) Predict clinical metadata from the image
16meta = model.predict_meta("lesion.jpg")
17# {'fitzpatrick': 3, 'fitzpatrick_grouped': '3-4', 'age': 42.1,
18# 'gender': 'female', 'origin': ..., 'body_region': ..., ...}
19
20import numpy as np
21sim = float(np.dot(img_emb, txt_emb)) # cosine in the shared spaceencode_image accepts a file path, raw bytes, or a PIL.Image. encode_text
expands the query into clinical prompt templates and averages the results; pass
templates=["{}"] to encode the raw text as-is.predict_meta applies bundled linear probes to the SkinMap embedding to estimate
Fitzpatrick skin type, age, sex, geographic origin, body region and more. By
default it uses global probes, which reproduce the demographic estimates
reported in the paper. If you know the imaging modality, pass it to switch the
Fitzpatrick prediction to a modality-specific probe (more accurate when the
modality is known); the other attributes stay global:meta = model.predict_meta("lesion.jpg", modality="dermoscopy") # clinical | dermoscopy | TBPpredict_meta also accepts a precomputed 1024-d vector instead of an image, and a
subset via attributes=[...].indices, distances = model.search("lesion.jpg", k=10)search() raises a clear error. Encoding still works.| Component | Role |
|---|---|
| 9 multi-modal teachers (CLIP & SigLIP; ViT-L/14 & ViT-B/32) | image + text features |
| 3 self-supervised teachers (DINO, iBOT, MAE; ViT-B/16) | dermatology image features |
Per-teacher whitening (whitening_stats.npz) | decorrelate before fusion |
Trained projector (projector_model.pth) | fuse to 1024-d image/text heads |
Metadata probes (probes/) | linear probes for predict_meta |