kaiko-eva 0.0.1__py3-none-any.whl → 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of kaiko-eva might be problematic. Click here for more details.

Files changed (168) hide show
  1. eva/core/callbacks/__init__.py +3 -2
  2. eva/core/callbacks/config.py +143 -0
  3. eva/core/callbacks/writers/__init__.py +6 -3
  4. eva/core/callbacks/writers/embeddings/__init__.py +6 -0
  5. eva/core/callbacks/writers/embeddings/_manifest.py +71 -0
  6. eva/core/callbacks/writers/embeddings/base.py +192 -0
  7. eva/core/callbacks/writers/embeddings/classification.py +117 -0
  8. eva/core/callbacks/writers/embeddings/segmentation.py +78 -0
  9. eva/core/callbacks/writers/embeddings/typings.py +38 -0
  10. eva/core/data/datasets/__init__.py +10 -2
  11. eva/core/data/datasets/classification/__init__.py +5 -2
  12. eva/core/data/datasets/classification/embeddings.py +15 -135
  13. eva/core/data/datasets/classification/multi_embeddings.py +110 -0
  14. eva/core/data/datasets/embeddings.py +167 -0
  15. eva/core/data/splitting/__init__.py +6 -0
  16. eva/core/data/splitting/random.py +41 -0
  17. eva/core/data/splitting/stratified.py +56 -0
  18. eva/core/data/transforms/__init__.py +3 -1
  19. eva/core/data/transforms/padding/__init__.py +5 -0
  20. eva/core/data/transforms/padding/pad_2d_tensor.py +38 -0
  21. eva/core/data/transforms/sampling/__init__.py +5 -0
  22. eva/core/data/transforms/sampling/sample_from_axis.py +40 -0
  23. eva/core/loggers/__init__.py +7 -0
  24. eva/core/loggers/dummy.py +38 -0
  25. eva/core/loggers/experimental_loggers.py +8 -0
  26. eva/core/loggers/log/__init__.py +6 -0
  27. eva/core/loggers/log/image.py +71 -0
  28. eva/core/loggers/log/parameters.py +74 -0
  29. eva/core/loggers/log/utils.py +13 -0
  30. eva/core/loggers/loggers.py +6 -0
  31. eva/core/metrics/__init__.py +6 -2
  32. eva/core/metrics/defaults/__init__.py +10 -3
  33. eva/core/metrics/defaults/classification/__init__.py +1 -1
  34. eva/core/metrics/defaults/classification/binary.py +0 -9
  35. eva/core/metrics/defaults/classification/multiclass.py +0 -8
  36. eva/core/metrics/defaults/segmentation/__init__.py +5 -0
  37. eva/core/metrics/defaults/segmentation/multiclass.py +43 -0
  38. eva/core/metrics/generalized_dice.py +59 -0
  39. eva/core/metrics/mean_iou.py +120 -0
  40. eva/core/metrics/structs/schemas.py +3 -1
  41. eva/core/models/__init__.py +3 -1
  42. eva/core/models/modules/head.py +16 -15
  43. eva/core/models/modules/module.py +25 -1
  44. eva/core/models/modules/typings.py +14 -1
  45. eva/core/models/modules/utils/batch_postprocess.py +37 -5
  46. eva/core/models/networks/__init__.py +1 -2
  47. eva/core/models/networks/mlp.py +2 -2
  48. eva/core/models/transforms/__init__.py +6 -0
  49. eva/core/models/{networks/transforms → transforms}/extract_cls_features.py +10 -2
  50. eva/core/models/transforms/extract_patch_features.py +47 -0
  51. eva/core/models/wrappers/__init__.py +13 -0
  52. eva/core/models/{networks/wrappers → wrappers}/base.py +3 -2
  53. eva/core/models/{networks/wrappers → wrappers}/from_function.py +5 -12
  54. eva/core/models/{networks/wrappers → wrappers}/huggingface.py +15 -11
  55. eva/core/models/{networks/wrappers → wrappers}/onnx.py +6 -3
  56. eva/core/trainers/_recorder.py +69 -7
  57. eva/core/trainers/functional.py +23 -5
  58. eva/core/trainers/trainer.py +20 -6
  59. eva/core/utils/__init__.py +6 -0
  60. eva/core/utils/clone.py +27 -0
  61. eva/core/utils/memory.py +28 -0
  62. eva/core/utils/operations.py +26 -0
  63. eva/core/utils/parser.py +20 -0
  64. eva/vision/__init__.py +2 -2
  65. eva/vision/callbacks/__init__.py +5 -0
  66. eva/vision/callbacks/loggers/__init__.py +5 -0
  67. eva/vision/callbacks/loggers/batch/__init__.py +5 -0
  68. eva/vision/callbacks/loggers/batch/base.py +130 -0
  69. eva/vision/callbacks/loggers/batch/segmentation.py +188 -0
  70. eva/vision/data/datasets/__init__.py +24 -4
  71. eva/vision/data/datasets/_utils.py +3 -3
  72. eva/vision/data/datasets/_validators.py +15 -2
  73. eva/vision/data/datasets/classification/__init__.py +6 -2
  74. eva/vision/data/datasets/classification/bach.py +10 -15
  75. eva/vision/data/datasets/classification/base.py +17 -24
  76. eva/vision/data/datasets/classification/camelyon16.py +244 -0
  77. eva/vision/data/datasets/classification/crc.py +10 -15
  78. eva/vision/data/datasets/classification/mhist.py +10 -15
  79. eva/vision/data/datasets/classification/panda.py +184 -0
  80. eva/vision/data/datasets/classification/patch_camelyon.py +13 -16
  81. eva/vision/data/datasets/classification/wsi.py +105 -0
  82. eva/vision/data/datasets/segmentation/__init__.py +15 -2
  83. eva/vision/data/datasets/segmentation/_utils.py +38 -0
  84. eva/vision/data/datasets/segmentation/base.py +31 -47
  85. eva/vision/data/datasets/segmentation/bcss.py +236 -0
  86. eva/vision/data/datasets/segmentation/consep.py +156 -0
  87. eva/vision/data/datasets/segmentation/embeddings.py +34 -0
  88. eva/vision/data/datasets/segmentation/lits.py +178 -0
  89. eva/vision/data/datasets/segmentation/monusac.py +236 -0
  90. eva/vision/data/datasets/segmentation/total_segmentator_2d.py +325 -0
  91. eva/vision/data/datasets/wsi.py +187 -0
  92. eva/vision/data/transforms/__init__.py +3 -2
  93. eva/vision/data/transforms/common/__init__.py +2 -1
  94. eva/vision/data/transforms/common/resize_and_clamp.py +51 -0
  95. eva/vision/data/transforms/common/resize_and_crop.py +6 -7
  96. eva/vision/data/transforms/normalization/__init__.py +6 -0
  97. eva/vision/data/transforms/normalization/clamp.py +43 -0
  98. eva/vision/data/transforms/normalization/functional/__init__.py +5 -0
  99. eva/vision/data/transforms/normalization/functional/rescale_intensity.py +28 -0
  100. eva/vision/data/transforms/normalization/rescale_intensity.py +53 -0
  101. eva/vision/data/wsi/__init__.py +16 -0
  102. eva/vision/data/wsi/backends/__init__.py +69 -0
  103. eva/vision/data/wsi/backends/base.py +115 -0
  104. eva/vision/data/wsi/backends/openslide.py +73 -0
  105. eva/vision/data/wsi/backends/pil.py +52 -0
  106. eva/vision/data/wsi/backends/tiffslide.py +42 -0
  107. eva/vision/data/wsi/patching/__init__.py +6 -0
  108. eva/vision/data/wsi/patching/coordinates.py +98 -0
  109. eva/vision/data/wsi/patching/mask.py +123 -0
  110. eva/vision/data/wsi/patching/samplers/__init__.py +14 -0
  111. eva/vision/data/wsi/patching/samplers/_utils.py +50 -0
  112. eva/vision/data/wsi/patching/samplers/base.py +48 -0
  113. eva/vision/data/wsi/patching/samplers/foreground_grid.py +99 -0
  114. eva/vision/data/wsi/patching/samplers/grid.py +47 -0
  115. eva/vision/data/wsi/patching/samplers/random.py +41 -0
  116. eva/vision/losses/__init__.py +5 -0
  117. eva/vision/losses/dice.py +40 -0
  118. eva/vision/models/__init__.py +4 -2
  119. eva/vision/models/modules/__init__.py +5 -0
  120. eva/vision/models/modules/semantic_segmentation.py +161 -0
  121. eva/vision/models/networks/__init__.py +1 -2
  122. eva/vision/models/networks/backbones/__init__.py +6 -0
  123. eva/vision/models/networks/backbones/_utils.py +39 -0
  124. eva/vision/models/networks/backbones/pathology/__init__.py +31 -0
  125. eva/vision/models/networks/backbones/pathology/bioptimus.py +34 -0
  126. eva/vision/models/networks/backbones/pathology/gigapath.py +33 -0
  127. eva/vision/models/networks/backbones/pathology/histai.py +46 -0
  128. eva/vision/models/networks/backbones/pathology/kaiko.py +123 -0
  129. eva/vision/models/networks/backbones/pathology/lunit.py +68 -0
  130. eva/vision/models/networks/backbones/pathology/mahmood.py +62 -0
  131. eva/vision/models/networks/backbones/pathology/owkin.py +22 -0
  132. eva/vision/models/networks/backbones/registry.py +47 -0
  133. eva/vision/models/networks/backbones/timm/__init__.py +5 -0
  134. eva/vision/models/networks/backbones/timm/backbones.py +54 -0
  135. eva/vision/models/networks/backbones/universal/__init__.py +8 -0
  136. eva/vision/models/networks/backbones/universal/vit.py +54 -0
  137. eva/vision/models/networks/decoders/__init__.py +6 -0
  138. eva/vision/models/networks/decoders/decoder.py +7 -0
  139. eva/vision/models/networks/decoders/segmentation/__init__.py +11 -0
  140. eva/vision/models/networks/decoders/segmentation/common.py +74 -0
  141. eva/vision/models/networks/decoders/segmentation/conv2d.py +114 -0
  142. eva/vision/models/networks/decoders/segmentation/linear.py +125 -0
  143. eva/vision/models/wrappers/__init__.py +6 -0
  144. eva/vision/models/wrappers/from_registry.py +48 -0
  145. eva/vision/models/wrappers/from_timm.py +68 -0
  146. eva/vision/utils/colormap.py +77 -0
  147. eva/vision/utils/convert.py +67 -0
  148. eva/vision/utils/io/__init__.py +10 -4
  149. eva/vision/utils/io/image.py +21 -2
  150. eva/vision/utils/io/mat.py +36 -0
  151. eva/vision/utils/io/nifti.py +40 -15
  152. eva/vision/utils/io/text.py +10 -3
  153. kaiko_eva-0.1.0.dist-info/METADATA +553 -0
  154. kaiko_eva-0.1.0.dist-info/RECORD +205 -0
  155. {kaiko_eva-0.0.1.dist-info → kaiko_eva-0.1.0.dist-info}/WHEEL +1 -1
  156. {kaiko_eva-0.0.1.dist-info → kaiko_eva-0.1.0.dist-info}/entry_points.txt +2 -0
  157. eva/core/callbacks/writers/embeddings.py +0 -169
  158. eva/core/callbacks/writers/typings.py +0 -23
  159. eva/core/models/networks/transforms/__init__.py +0 -5
  160. eva/core/models/networks/wrappers/__init__.py +0 -8
  161. eva/vision/data/datasets/classification/total_segmentator.py +0 -213
  162. eva/vision/data/datasets/segmentation/total_segmentator.py +0 -212
  163. eva/vision/models/networks/postprocesses/__init__.py +0 -5
  164. eva/vision/models/networks/postprocesses/cls.py +0 -25
  165. kaiko_eva-0.0.1.dist-info/METADATA +0 -405
  166. kaiko_eva-0.0.1.dist-info/RECORD +0 -110
  167. /eva/core/models/{networks → wrappers}/_utils.py +0 -0
  168. {kaiko_eva-0.0.1.dist-info → kaiko_eva-0.1.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,212 +0,0 @@
1
- """TotalSegmentator 2D segmentation dataset class."""
2
-
3
- import functools
4
- import os
5
- from glob import glob
6
- from typing import Callable, Dict, List, Literal, Tuple
7
-
8
- import numpy as np
9
- from torchvision.datasets import utils
10
- from typing_extensions import override
11
-
12
- from eva.vision.data.datasets import _utils, _validators, structs
13
- from eva.vision.data.datasets.segmentation import base
14
- from eva.vision.utils import io
15
-
16
-
17
- class TotalSegmentator2D(base.ImageSegmentation):
18
- """TotalSegmentator 2D segmentation dataset."""
19
-
20
- _train_index_ranges: List[Tuple[int, int]] = [(0, 83)]
21
- """Train range indices."""
22
-
23
- _val_index_ranges: List[Tuple[int, int]] = [(83, 103)]
24
- """Validation range indices."""
25
-
26
- _n_slices_per_image: int = 20
27
- """The amount of slices to sample per 3D CT scan image."""
28
-
29
- _resources_full: List[structs.DownloadResource] = [
30
- structs.DownloadResource(
31
- filename="Totalsegmentator_dataset_v201.zip",
32
- url="https://zenodo.org/records/10047292/files/Totalsegmentator_dataset_v201.zip",
33
- md5="fe250e5718e0a3b5df4c4ea9d58a62fe",
34
- ),
35
- ]
36
- """Resources for the full dataset version."""
37
-
38
- _resources_small: List[structs.DownloadResource] = [
39
- structs.DownloadResource(
40
- filename="Totalsegmentator_dataset_small_v201.zip",
41
- url="https://zenodo.org/records/10047263/files/Totalsegmentator_dataset_small_v201.zip",
42
- md5="6b5524af4b15e6ba06ef2d700c0c73e0",
43
- ),
44
- ]
45
- """Resources for the small dataset version."""
46
-
47
- def __init__(
48
- self,
49
- root: str,
50
- split: Literal["train", "val"] | None,
51
- version: Literal["small", "full"] = "small",
52
- download: bool = False,
53
- image_transforms: Callable | None = None,
54
- target_transforms: Callable | None = None,
55
- image_target_transforms: Callable | None = None,
56
- ) -> None:
57
- """Initialize dataset.
58
-
59
- Args:
60
- root: Path to the root directory of the dataset. The dataset will
61
- be downloaded and extracted here, if it does not already exist.
62
- split: Dataset split to use. If `None`, the entire dataset is used.
63
- version: The version of the dataset to initialize.
64
- download: Whether to download the data for the specified split.
65
- Note that the download will be executed only by additionally
66
- calling the :meth:`prepare_data` method and if the data does not
67
- exist yet on disk.
68
- image_transforms: A function/transform that takes in an image
69
- and returns a transformed version.
70
- target_transforms: A function/transform that takes in the target
71
- and transforms it.
72
- image_target_transforms: A function/transforms that takes in an
73
- image and a label and returns the transformed versions of both.
74
- This transform happens after the `image_transforms` and
75
- `target_transforms`.
76
- """
77
- super().__init__(
78
- image_transforms=image_transforms,
79
- target_transforms=target_transforms,
80
- image_target_transforms=image_target_transforms,
81
- )
82
-
83
- self._root = root
84
- self._split = split
85
- self._version = version
86
- self._download = download
87
-
88
- self._samples_dirs: List[str] = []
89
- self._indices: List[int] = []
90
-
91
- @functools.cached_property
92
- @override
93
- def classes(self) -> List[str]:
94
- def get_filename(path: str) -> str:
95
- """Returns the filename from the full path."""
96
- return os.path.basename(path).split(".")[0]
97
-
98
- first_sample_labels = os.path.join(
99
- self._root, self._samples_dirs[0], "segmentations", "*.nii.gz"
100
- )
101
- return sorted(map(get_filename, glob(first_sample_labels)))
102
-
103
- @property
104
- @override
105
- def class_to_idx(self) -> Dict[str, int]:
106
- return {label: index for index, label in enumerate(self.classes)}
107
-
108
- @override
109
- def filename(self, index: int) -> str:
110
- sample_dir = self._samples_dirs[self._indices[index]]
111
- return os.path.join(sample_dir, "ct.nii.gz")
112
-
113
- @override
114
- def prepare_data(self) -> None:
115
- if self._download:
116
- self._download_dataset()
117
-
118
- @override
119
- def configure(self) -> None:
120
- self._samples_dirs = self._fetch_samples_dirs()
121
- self._indices = self._create_indices()
122
-
123
- @override
124
- def validate(self) -> None:
125
- _validators.check_dataset_integrity(
126
- self,
127
- length=1660 if self._split == "train" else 400,
128
- n_classes=117,
129
- first_and_last_labels=("adrenal_gland_left", "vertebrae_T9"),
130
- )
131
-
132
- @override
133
- def __len__(self) -> int:
134
- return len(self._indices) * self._n_slices_per_image
135
-
136
- @override
137
- def load_image(self, index: int) -> np.ndarray:
138
- image_path = self._get_image_path(index)
139
- slice_index = self._get_sample_slice_index(index)
140
- image_array = io.read_nifti_slice(image_path, slice_index)
141
- return image_array.repeat(3, axis=2)
142
-
143
- @override
144
- def load_mask(self, index: int) -> np.ndarray:
145
- masks_dir = self._get_masks_dir(index)
146
- slice_index = self._get_sample_slice_index(index)
147
- mask_paths = (os.path.join(masks_dir, label + ".nii.gz") for label in self.classes)
148
- masks = [io.read_nifti_slice(path, slice_index) for path in mask_paths]
149
- return np.concatenate(masks, axis=-1)
150
-
151
- def _get_masks_dir(self, index: int) -> str:
152
- """Returns the directory of the corresponding masks."""
153
- sample_dir = self._get_sample_dir(index)
154
- return os.path.join(self._root, sample_dir, "segmentations")
155
-
156
- def _get_image_path(self, index: int) -> str:
157
- """Returns the corresponding image path."""
158
- sample_dir = self._get_sample_dir(index)
159
- return os.path.join(self._root, sample_dir, "ct.nii.gz")
160
-
161
- def _get_sample_dir(self, index: int) -> str:
162
- """Returns the corresponding sample directory."""
163
- sample_index = self._indices[index // self._n_slices_per_image]
164
- return self._samples_dirs[sample_index]
165
-
166
- def _get_sample_slice_index(self, index: int) -> int:
167
- """Returns the corresponding slice index."""
168
- image_path = self._get_image_path(index)
169
- total_slices = io.fetch_total_nifti_slices(image_path)
170
- slice_indices = np.linspace(0, total_slices - 1, num=self._n_slices_per_image, dtype=int)
171
- return slice_indices[index % self._n_slices_per_image]
172
-
173
- def _fetch_samples_dirs(self) -> List[str]:
174
- """Returns the name of all the samples of all the splits of the dataset."""
175
- sample_filenames = [
176
- filename
177
- for filename in os.listdir(self._root)
178
- if os.path.isdir(os.path.join(self._root, filename))
179
- ]
180
- return sorted(sample_filenames)
181
-
182
- def _create_indices(self) -> List[int]:
183
- """Builds the dataset indices for the specified split."""
184
- split_index_ranges = {
185
- "train": self._train_index_ranges,
186
- "val": self._val_index_ranges,
187
- None: [(0, 103)],
188
- }
189
- index_ranges = split_index_ranges.get(self._split)
190
- if index_ranges is None:
191
- raise ValueError("Invalid data split. Use 'train', 'val' or `None`.")
192
-
193
- return _utils.ranges_to_indices(index_ranges)
194
-
195
- def _download_dataset(self) -> None:
196
- """Downloads the dataset."""
197
- dataset_resources = {
198
- "small": self._resources_small,
199
- "full": self._resources_full,
200
- None: (0, 103),
201
- }
202
- resources = dataset_resources.get(self._version)
203
- if resources is None:
204
- raise ValueError("Invalid data version. Use 'small' or 'full'.")
205
-
206
- for resource in resources:
207
- utils.download_and_extract_archive(
208
- resource.url,
209
- download_root=self._root,
210
- filename=resource.filename,
211
- remove_finished=True,
212
- )
@@ -1,5 +0,0 @@
1
- """Model post-process transforms."""
2
-
3
- from eva.vision.models.networks.postprocesses.cls import ExtractCLSFeatures
4
-
5
- __all__ = ["ExtractCLSFeatures"]
@@ -1,25 +0,0 @@
1
- """Transforms for extracting the CLS output from a model output."""
2
-
3
- import torch
4
- from transformers import modeling_outputs
5
-
6
-
7
- class ExtractCLSFeatures:
8
- """Extracts the CLS token from a ViT model output."""
9
-
10
- def __call__(
11
- self, tensor: torch.Tensor | modeling_outputs.BaseModelOutputWithPooling
12
- ) -> torch.Tensor:
13
- """Call method for the transformation.
14
-
15
- Args:
16
- tensor: The tensor representing the model output.
17
- """
18
- if isinstance(tensor, torch.Tensor):
19
- transformed_tensor = tensor[:, 0, :]
20
- elif isinstance(tensor, modeling_outputs.BaseModelOutputWithPooling):
21
- transformed_tensor = tensor.last_hidden_state[:, 0, :]
22
- else:
23
- raise ValueError(f"Unsupported type {type(tensor)}")
24
-
25
- return transformed_tensor
@@ -1,405 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: kaiko-eva
3
- Version: 0.0.1
4
- Summary: Evaluation Framework for oncology foundation models.
5
- Keywords: machine-learning evaluation-framework oncology foundation-models
6
- Author-Email: Ioannis Gatopoulos <ioannis@kaiko.ai>, Nicolas Känzig <nicolas@kaiko.ai>, Roman Moser <roman@kaiko.ai>
7
- Maintainer-Email: Ioannis Gatopoulos <ioannis@kaiko.ai>, Nicolas Känzig <nicolas@kaiko.ai>, Roman Moser <roman@kaiko.ai>
8
- License: Apache License
9
- Version 2.0, January 2004
10
- http://www.apache.org/licenses/
11
-
12
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
13
-
14
- 1. Definitions.
15
-
16
- "License" shall mean the terms and conditions for use, reproduction,
17
- and distribution as defined by Sections 1 through 9 of this document.
18
-
19
- "Licensor" shall mean the copyright owner or entity authorized by
20
- the copyright owner that is granting the License.
21
-
22
- "Legal Entity" shall mean the union of the acting entity and all
23
- other entities that control, are controlled by, or are under common
24
- control with that entity. For the purposes of this definition,
25
- "control" means (i) the power, direct or indirect, to cause the
26
- direction or management of such entity, whether by contract or
27
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
28
- outstanding shares, or (iii) beneficial ownership of such entity.
29
-
30
- "You" (or "Your") shall mean an individual or Legal Entity
31
- exercising permissions granted by this License.
32
-
33
- "Source" form shall mean the preferred form for making modifications,
34
- including but not limited to software source code, documentation
35
- source, and configuration files.
36
-
37
- "Object" form shall mean any form resulting from mechanical
38
- transformation or translation of a Source form, including but
39
- not limited to compiled object code, generated documentation,
40
- and conversions to other media types.
41
-
42
- "Work" shall mean the work of authorship, whether in Source or
43
- Object form, made available under the License, as indicated by a
44
- copyright notice that is included in or attached to the work
45
- (an example is provided in the Appendix below).
46
-
47
- "Derivative Works" shall mean any work, whether in Source or Object
48
- form, that is based on (or derived from) the Work and for which the
49
- editorial revisions, annotations, elaborations, or other modifications
50
- represent, as a whole, an original work of authorship. For the purposes
51
- of this License, Derivative Works shall not include works that remain
52
- separable from, or merely link (or bind by name) to the interfaces of,
53
- the Work and Derivative Works thereof.
54
-
55
- "Contribution" shall mean any work of authorship, including
56
- the original version of the Work and any modifications or additions
57
- to that Work or Derivative Works thereof, that is intentionally
58
- submitted to Licensor for inclusion in the Work by the copyright owner
59
- or by an individual or Legal Entity authorized to submit on behalf of
60
- the copyright owner. For the purposes of this definition, "submitted"
61
- means any form of electronic, verbal, or written communication sent
62
- to the Licensor or its representatives, including but not limited to
63
- communication on electronic mailing lists, source code control systems,
64
- and issue tracking systems that are managed by, or on behalf of, the
65
- Licensor for the purpose of discussing and improving the Work, but
66
- excluding communication that is conspicuously marked or otherwise
67
- designated in writing by the copyright owner as "Not a Contribution."
68
-
69
- "Contributor" shall mean Licensor and any individual or Legal Entity
70
- on behalf of whom a Contribution has been received by Licensor and
71
- subsequently incorporated within the Work.
72
-
73
- 2. Grant of Copyright License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- copyright license to reproduce, prepare Derivative Works of,
77
- publicly display, publicly perform, sublicense, and distribute the
78
- Work and such Derivative Works in Source or Object form.
79
-
80
- 3. Grant of Patent License. Subject to the terms and conditions of
81
- this License, each Contributor hereby grants to You a perpetual,
82
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
83
- (except as stated in this section) patent license to make, have made,
84
- use, offer to sell, sell, import, and otherwise transfer the Work,
85
- where such license applies only to those patent claims licensable
86
- by such Contributor that are necessarily infringed by their
87
- Contribution(s) alone or by combination of their Contribution(s)
88
- with the Work to which such Contribution(s) was submitted. If You
89
- institute patent litigation against any entity (including a
90
- cross-claim or counterclaim in a lawsuit) alleging that the Work
91
- or a Contribution incorporated within the Work constitutes direct
92
- or contributory patent infringement, then any patent licenses
93
- granted to You under this License for that Work shall terminate
94
- as of the date such litigation is filed.
95
-
96
- 4. Redistribution. You may reproduce and distribute copies of the
97
- Work or Derivative Works thereof in any medium, with or without
98
- modifications, and in Source or Object form, provided that You
99
- meet the following conditions:
100
-
101
- (a) You must give any other recipients of the Work or
102
- Derivative Works a copy of this License; and
103
-
104
- (b) You must cause any modified files to carry prominent notices
105
- stating that You changed the files; and
106
-
107
- (c) You must retain, in the Source form of any Derivative Works
108
- that You distribute, all copyright, patent, trademark, and
109
- attribution notices from the Source form of the Work,
110
- excluding those notices that do not pertain to any part of
111
- the Derivative Works; and
112
-
113
- (d) If the Work includes a "NOTICE" text file as part of its
114
- distribution, then any Derivative Works that You distribute must
115
- include a readable copy of the attribution notices contained
116
- within such NOTICE file, excluding those notices that do not
117
- pertain to any part of the Derivative Works, in at least one
118
- of the following places: within a NOTICE text file distributed
119
- as part of the Derivative Works; within the Source form or
120
- documentation, if provided along with the Derivative Works; or,
121
- within a display generated by the Derivative Works, if and
122
- wherever such third-party notices normally appear. The contents
123
- of the NOTICE file are for informational purposes only and
124
- do not modify the License. You may add Your own attribution
125
- notices within Derivative Works that You distribute, alongside
126
- or as an addendum to the NOTICE text from the Work, provided
127
- that such additional attribution notices cannot be construed
128
- as modifying the License.
129
-
130
- You may add Your own copyright statement to Your modifications and
131
- may provide additional or different license terms and conditions
132
- for use, reproduction, or distribution of Your modifications, or
133
- for any such Derivative Works as a whole, provided Your use,
134
- reproduction, and distribution of the Work otherwise complies with
135
- the conditions stated in this License.
136
-
137
- 5. Submission of Contributions. Unless You explicitly state otherwise,
138
- any Contribution intentionally submitted for inclusion in the Work
139
- by You to the Licensor shall be under the terms and conditions of
140
- this License, without any additional terms or conditions.
141
- Notwithstanding the above, nothing herein shall supersede or modify
142
- the terms of any separate license agreement you may have executed
143
- with Licensor regarding such Contributions.
144
-
145
- 6. Trademarks. This License does not grant permission to use the trade
146
- names, trademarks, service marks, or product names of the Licensor,
147
- except as required for reasonable and customary use in describing the
148
- origin of the Work and reproducing the content of the NOTICE file.
149
-
150
- 7. Disclaimer of Warranty. Unless required by applicable law or
151
- agreed to in writing, Licensor provides the Work (and each
152
- Contributor provides its Contributions) on an "AS IS" BASIS,
153
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
154
- implied, including, without limitation, any warranties or conditions
155
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
156
- PARTICULAR PURPOSE. You are solely responsible for determining the
157
- appropriateness of using or redistributing the Work and assume any
158
- risks associated with Your exercise of permissions under this License.
159
-
160
- 8. Limitation of Liability. In no event and under no legal theory,
161
- whether in tort (including negligence), contract, or otherwise,
162
- unless required by applicable law (such as deliberate and grossly
163
- negligent acts) or agreed to in writing, shall any Contributor be
164
- liable to You for damages, including any direct, indirect, special,
165
- incidental, or consequential damages of any character arising as a
166
- result of this License or out of the use or inability to use the
167
- Work (including but not limited to damages for loss of goodwill,
168
- work stoppage, computer failure or malfunction, or any and all
169
- other commercial damages or losses), even if such Contributor
170
- has been advised of the possibility of such damages.
171
-
172
- 9. Accepting Warranty or Additional Liability. While redistributing
173
- the Work or Derivative Works thereof, You may choose to offer,
174
- and charge a fee for, acceptance of support, warranty, indemnity,
175
- or other liability obligations and/or rights consistent with this
176
- License. However, in accepting such obligations, You may act only
177
- on Your own behalf and on Your sole responsibility, not on behalf
178
- of any other Contributor, and only if You agree to indemnify,
179
- defend, and hold each Contributor harmless for any liability
180
- incurred by, or claims asserted against, such Contributor by reason
181
- of your accepting any such warranty or additional liability.
182
-
183
- END OF TERMS AND CONDITIONS
184
-
185
- APPENDIX: How to apply the Apache License to your work.
186
-
187
- To apply the Apache License to your work, attach the following
188
- boilerplate notice, with the fields enclosed by brackets "[]"
189
- replaced with your own identifying information. (Don't include
190
- the brackets!) The text should be enclosed in the appropriate
191
- comment syntax for the file format. We also recommend that a
192
- file or class name and description of purpose be included on the
193
- same "printed page" as the copyright notice for easier
194
- identification within third-party archives.
195
-
196
- Copyright 2024 kaiko.ai
197
-
198
- Licensed under the Apache License, Version 2.0 (the "License");
199
- you may not use this file except in compliance with the License.
200
- You may obtain a copy of the License at
201
-
202
- http://www.apache.org/licenses/LICENSE-2.0
203
-
204
- Unless required by applicable law or agreed to in writing, software
205
- distributed under the License is distributed on an "AS IS" BASIS,
206
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
207
- See the License for the specific language governing permissions and
208
- limitations under the License.
209
- Classifier: Topic :: Software Development :: Build Tools
210
- Classifier: Programming Language :: Python :: 3
211
- Classifier: Programming Language :: Python :: 3.10
212
- Classifier: Programming Language :: Python :: 3.11
213
- Classifier: Programming Language :: Python :: 3.12
214
- Project-URL: Homepage, https://kaiko-ai.github.io/eva/dev/
215
- Project-URL: Repository, https://github.com/kaiko-ai/eva
216
- Project-URL: Documentation, https://kaiko-ai.github.io/eva/dev/
217
- Requires-Python: >=3.10
218
- Requires-Dist: lightning>=2.2.1
219
- Requires-Dist: jsonargparse[omegaconf]>=4.27.4
220
- Requires-Dist: tensorboard>=2.16.2
221
- Requires-Dist: loguru>=0.7.2
222
- Requires-Dist: pandas>=2.2.0
223
- Requires-Dist: transformers>=4.38.2
224
- Requires-Dist: onnxruntime>=1.17.1
225
- Requires-Dist: onnx>=1.15.0
226
- Requires-Dist: toolz>=0.12.1
227
- Requires-Dist: h5py>=3.10.0; extra == "vision"
228
- Requires-Dist: nibabel>=5.2.0; extra == "vision"
229
- Requires-Dist: opencv-python-headless>=4.9.0.80; extra == "vision"
230
- Requires-Dist: timm>=0.9.12; extra == "vision"
231
- Requires-Dist: torchvision>=0.17.0; extra == "vision"
232
- Requires-Dist: h5py>=3.10.0; extra == "all"
233
- Requires-Dist: nibabel>=5.2.0; extra == "all"
234
- Requires-Dist: opencv-python-headless>=4.9.0.80; extra == "all"
235
- Requires-Dist: timm>=0.9.12; extra == "all"
236
- Requires-Dist: torchvision>=0.17.0; extra == "all"
237
- Provides-Extra: vision
238
- Provides-Extra: all
239
- Description-Content-Type: text/markdown
240
-
241
- <div align="center">
242
-
243
- <img src="https://github.com/kaiko-ai/eva/blob/main/docs/images/eva-logo.png?raw=true" width="400">
244
-
245
- <br />
246
-
247
- _Oncology FM Evaluation Framework by kaiko.ai_
248
-
249
- [![PyPI](https://img.shields.io/pypi/v/kaiko-eva.svg?logo=python)](https://pypi.python.org/pypi/kaiko-eva)
250
- [![CI](https://github.com/kaiko-ai/eva/workflows/CI/badge.svg)](https://github.com/kaiko-ai/eva/actions?query=workflow%3ACI)
251
- [![license](https://img.shields.io/badge/License-Apache%202.0-blue.svg?labelColor=gray)](https://github.com/kaiko-ai/eva#license)
252
-
253
- <p align="center">
254
- <a href="https://github.com/kaiko-ai/eva#installation">Installation</a> •
255
- <a href="https://github.com/kaiko-ai/eva#how-to-use">How To Use</a> •
256
- <a href="https://kaiko-ai.github.io/eva/">Documentation</a> •
257
- <a href="https://kaiko-ai.github.io/eva/dev/datasets/">Datasets</a> •
258
- <a href="https://github.com/kaiko-ai/eva#benchmarks">Benchmarks</a> <br>
259
- <a href="https://github.com/kaiko-ai/eva#contributing">Contribute</a> •
260
- <a href="https://github.com/kaiko-ai/eva#acknowledgements">Acknowledgements</a>
261
- </p>
262
-
263
- </div>
264
-
265
- <br />
266
-
267
- _`eva`_ is an evaluation framework for oncology foundation models (FMs) by [kaiko.ai](https://kaiko.ai/).
268
- Check out the [documentation](https://kaiko-ai.github.io/eva/) for more information.
269
-
270
- ### Highlights:
271
- - Easy and reliable benchmark of Oncology FMs
272
- - Automatic embedding inference and evaluation of a downstream task
273
- - Native support of popular medical [datasets](https://kaiko-ai.github.io/eva/dev/datasets/) and models
274
- - Produce statistics over multiple evaluation fits and multiple metrics
275
-
276
- ## Installation
277
-
278
- Simple installation from PyPI:
279
- ```sh
280
- # to install the core version only
281
- pip install kaiko-eva
282
-
283
- # to install the expanded `vision` version
284
- pip install 'kaiko-eva[vision]'
285
-
286
- # to install everything
287
- pip install 'kaiko-eva[all]'
288
- ```
289
-
290
- To install the latest version of the `main` branch:
291
- ```sh
292
- pip install "kaiko-eva[all] @ git+https://github.com/kaiko-ai/eva.git"
293
- ```
294
-
295
- You can verify that the installation was successful by executing:
296
- ```sh
297
- eva --version
298
- ```
299
-
300
- ## How To Use
301
-
302
- _eva_ can be used directly from the terminal as a CLI tool as follows:
303
- ```sh
304
- eva {fit,predict,predict_fit} --config url/or/path/to/the/config.yaml
305
- ```
306
-
307
- When used as a CLI tool, `_eva_` supports configuration files (`.yaml`) as an argument to define its functionality.
308
- Native supported configs can be found at the [configs](https://github.com/kaiko-ai/eva/tree/main/configs) directory
309
- of the repo. Apart from cloning the repo, you can download the latest config folder as `.zip` from your browser from
310
- [here](https://download-directory.github.io/?url=https://github.com/kaiko-ai/eva/tree/main/configs). Alternatively,
311
- from a specific release the configs can be downloaded from the terminal as follows:
312
- ```sh
313
- curl -LO https://github.com/kaiko-ai/eva/releases/download/0.0.1/configs.zip | unzip configs.zip
314
- ```
315
-
316
- For example, to perform a downstream evaluation of DINO ViT-S/16 on the BACH dataset with
317
- linear probing by first inferring the embeddings and performing 5 sequential fits, execute:
318
- ```sh
319
- # from a locally stored config file
320
- eva predict_fit --config ./configs/vision/dino_vit/offline/bach.yaml
321
-
322
- # from a remote stored config file
323
- eva predict_fit --config https://raw.githubusercontent.com/kaiko-ai/eva/main/configs/vision/dino_vit/offline/bach.yaml
324
- ```
325
-
326
- > [!NOTE]
327
- > All the datasets that support automatic download in the repo have by default the option to automatically download set to false.
328
- > For automatic download you have to manually set download=true.
329
-
330
-
331
- To view all the possibles, execute:
332
- ```sh
333
- eva --help
334
- ```
335
-
336
- For more information, please refer to the [documentation](https://kaiko-ai.github.io/eva/dev/user-guide/tutorials/offline_vs_online/)
337
- and [tutorials](https://kaiko-ai.github.io/eva/dev/user-guide/advanced/replicate_evaluations/).
338
-
339
- ## Benchmarks
340
-
341
- In this section you will find model benchmarks which were generated with _eva_.
342
-
343
- ### Table I: WSI patch-level benchmark
344
-
345
- <br />
346
-
347
- <div align="center">
348
-
349
- | Model | BACH | CRC | MHIST | PCam/val | PCam/test |
350
- |--------------------------------------------------|-------|-------|-------|----------|-----------|
351
- | ViT-S/16 _(random)_ <sup>[1]</sup> | 0.410 | 0.617 | 0.501 | 0.753 | 0.728 |
352
- | ViT-S/16 _(ImageNet)_ <sup>[1]</sup> | 0.695 | 0.935 | 0.831 | 0.864 | 0.849 |
353
- | ViT-B/8 _(ImageNet)_ <sup>[1]</sup> | 0.710 | 0.939 | 0.814 | 0.870 | 0.856 |
354
- | DINO<sub>(p=16)</sub> <sup>[2]</sup> | 0.801 | 0.934 | 0.768 | 0.889 | 0.895 |
355
- | Phikon <sup>[3]</sup> | 0.725 | 0.935 | 0.777 | 0.912 | 0.915 |
356
- | ViT-S/16 _(kaiko.ai)_ <sup>[4]</sup> | 0.797 | 0.943 | 0.828 | 0.903 | 0.893 |
357
- | ViT-S/8 _(kaiko.ai)_ <sup>[4]</sup> | 0.834 | 0.946 | 0.832 | 0.897 | 0.887 |
358
- | ViT-B/16 _(kaiko.ai)_ <sup>[4]</sup> | 0.810 | 0.960 | 0.826 | 0.900 | 0.898 |
359
- | ViT-B/8 _(kaiko.ai)_ <sup>[4]</sup> | 0.865 | 0.956 | 0.809 | 0.913 | 0.921 |
360
- | ViT-L/14 _(kaiko.ai)_ <sup>[4]</sup> | 0.870 | 0.930 | 0.809 | 0.908 | 0.898 |
361
-
362
- _Table I: Linear probing evaluation of FMs on patch-level downstream datasets.<br> We report averaged balanced accuracy
363
- over 5 runs, with an average standard deviation of ±0.003._
364
-
365
- </div>
366
-
367
- <br />
368
-
369
- _References_:
370
- 1. _"Emerging properties in self-supervised vision transformers”_
371
- 2. _"Benchmarking self-supervised learning on diverse pathology datasets”_
372
- 3. _"Scaling self-supervised learning for histopathology with masked image modeling”_
373
- 4. _"Towards Training Large-Scale Pathology Foundation Models: from TCGA to Hospital Scale”_
374
-
375
- ## Contributing
376
-
377
- _eva_ is an open source project and welcomes contributions of all kinds. Please checkout the [developer](./docs/DEVELOPER_GUIDE.md)
378
- and [contributing guide](./docs/CONTRIBUTING.md) for help on how to do so.
379
-
380
- All contributors must follow the [code of conduct](./docs/CODE_OF_CONDUCT.md).
381
-
382
-
383
- ## Acknowledgements
384
-
385
- Our codebase is built using multiple opensource contributions
386
-
387
- <div align="center">
388
-
389
- [![python](https://img.shields.io/badge/-Python-blue?logo=python&logoColor=white)](https://github.com/pre-commit/pre-commit)
390
- [![pytorch](https://img.shields.io/badge/PyTorch-ee4c2c?logo=pytorch&logoColor=white)](https://pytorch.org/get-started/locally/)
391
- [![lightning](https://img.shields.io/badge/-⚡️_Lightning-792ee5?logo=pytorchlightning&logoColor=white)](https://pytorchlightning.ai/)<br>
392
- [![black](https://img.shields.io/badge/Code%20Style-Black-black.svg?labelColor=gray)](https://black.readthedocs.io/en/stable/)
393
- [![isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
394
- [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
395
- [![Checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/)<br>
396
- [![pdm-managed](https://img.shields.io/badge/pdm-managed-blueviolet)](https://pdm-project.org)
397
- [![Nox](https://img.shields.io/badge/%F0%9F%A6%8A-Nox-D85E00.svg)](https://github.com/wntrblm/nox)
398
- [![Built with Material for MkDocs](https://img.shields.io/badge/Material_for_MkDocs-526CFE?logo=MaterialForMkDocs&logoColor=white)](https://squidfunk.github.io/mkdocs-material/)
399
-
400
- </div>
401
-
402
- ---
403
- <div align="center">
404
- <img src="https://github.com/kaiko-ai/eva/blob/main/docs/images/kaiko-logo.png?raw=true" width="200">
405
- </div>