API
thunder.benchmark.benchmark(model, dataset, task, loading_mode='online_loading', lora=False, ckpt_save_all=False, online_wandb=False, recomp_embs=False, retrain_model=False, **kwargs)
Runs a benchmark for a pretrained model on a dataset with a task-specific approach.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
str
|
The name of the pretrained model to use. |
required |
dataset
|
str
|
The name of the dataset to use. |
required |
task
|
str
|
The name of the task to perform. |
required |
loading_mode
|
str
|
The type of data loading to use. |
'online_loading'
|
lora
|
bool
|
Whether to use LoRA (Low-Rank Adaptation) for model adaptation. Default is False. |
False
|
ckpt_save_all
|
bool
|
Whether to save all checkpoints during training. Default is False which means that only the best is saved. |
False
|
online_wandb
|
bool
|
Whether to use online mode for Weights & Biases (wandb) logging. Default is False which means offline mode. |
False
|
recomp_embs
|
bool
|
Whether to recompute embeddings if already saved. |
False
|
retrain_model
|
bool
|
Whether to retrain model if already trained and saved ckpts. |
False
|
Source code in src/thunder/benchmark.py
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
thunder.download_datasets(datasets, make_splits=False)
Downloads the benchmark datasets specified in the list of dataset names.
This function requires the $THUNDER_BASE_DATA_FOLDER
environment variable to be set,
which indicates the base directory where the datasets will be downloaded.
The list of all available datasets
- bach
- bracs
- break_his
- ccrcc
- crc
- esca
- mhist
- ocelot
- pannuke
- patch_camelyon
- segpath_epithelial
- segpath_lymphocytes
- tcga_crc_msi
- tcga_tils
- tcga_uniform
- wilds
Parameters:
Name | Type | Description | Default |
---|---|---|---|
datasets
|
List[str] or str
|
A dataset name string or a List of dataset names to download or one of the following aliases: |
required |
make_splits
|
bool
|
Whether to generate data splits for the datasets. Defaults to False. |
False
|
Source code in src/thunder/datasets/download.py
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
thunder.download_models(models)
Download model checkpoints from Hugging Face.
The list of all available models
- uni
- uni2h
- virchow
- virchow2
- hoptimus0
- hoptimus1
- conch
- titan
- phikon
- phikon2
- hiboub
- hiboul
- midnight
- keep
- quiltb32
- plip
- musk
- dinov2base
- dinov2large
- vitbasepatch16224in21k
- vitlargepatch16224in21k
- clipvitbasepatch32
- clipvitlargepatch14
Parameters:
Name | Type | Description | Default |
---|---|---|---|
models
|
List[str] or str
|
a list of model names or single a model name str. |
required |
Source code in src/thunder/models/download.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
|
thunder.generate_splits(datasets)
Generates the data splits for all datasets in input list.
This function requires the $THUNDER_BASE_DATA_FOLDER
environment variable to be set,
which indicates the base directory where the datasets will be downloaded.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
datasets
|
List[str]
|
List of dataset names to generate splits for or one of the following aliases: |
required |
Source code in src/thunder/datasets/data_splits.py
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 69 70 71 72 |
|
thunder.models.PretrainedModel
Bases: Module
, ABC
Abstract class to be inherited by custom pretrained models.
Source code in src/thunder/models/pretrained_models.py
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 |
|
get_linear_probing_embeddings(x)
abstractmethod
Returns the embeddings for linear probing.
Source code in src/thunder/models/pretrained_models.py
21 22 23 24 |
|
get_segmentation_embeddings(x)
abstractmethod
Returns the pixel dense embeddings for segmentation.
Source code in src/thunder/models/pretrained_models.py
26 27 28 29 |
|
get_transform()
abstractmethod
Returns the transform function to be applied to the input images.
Source code in src/thunder/models/pretrained_models.py
16 17 18 19 |
|
thunder.models.get_model_from_name(model_name, device)
Loading pretrained model from input name.
The list of all available models
- uni
- uni2h
- virchow
- virchow2
- hoptimus0
- hoptimus1
- conch
- titan
- phikon
- phikon2
- hiboub
- hiboul
- midnight
- keep
- quiltb32
- plip
- musk
- dinov2base
- dinov2large
- vitbasepatch16224in21k
- vitlargepatch16224in21k
- clipvitbasepatch32
- clipvitlargepatch14
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_name
|
str
|
The name of the model to use. |
required |
device
|
str
|
Device to use (cpu, cuda). |
required |
Returns:
Name | Type | Description |
---|---|---|
model |
Module
|
Pytorch model instance. |
transform |
Compose
|
Transform to apply to input image. |
get_embeddings |
Callable
|
Function to extract embeddings. |
output function get_embeddings
signature.
- src (torch.Tensor): Batch of transformed images with shape (B, 3, H, W).
- pretrained_model (torch.nn.Module): Model to extract embeddings with.
- pooled_emb (bool): Whether to output pooled (True) or spatial (False) embeddings.
Source code in src/thunder/models/pretrained_models.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|