diff --git a/configs/core/tests/offline/embeddings.yaml b/configs/core/tests/offline/embeddings.yaml index 82ad9afb..6e1d31ba 100644 --- a/configs/core/tests/offline/embeddings.yaml +++ b/configs/core/tests/offline/embeddings.yaml @@ -47,18 +47,18 @@ data: init_args: datasets: train: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: &DATASET_ARGS root: ${oc.env:TESTS_ROOT, tests/eva}/assets/core/datasets/embeddings manifest_file: manifest.csv split: train val: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: <<: *DATASET_ARGS split: val test: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: <<: *DATASET_ARGS split: test diff --git a/configs/vision/dino_vit/offline/bach.yaml b/configs/vision/dino_vit/offline/bach.yaml index 93683e3e..3a6b6a06 100644 --- a/configs/vision/dino_vit/offline/bach.yaml +++ b/configs/vision/dino_vit/offline/bach.yaml @@ -29,7 +29,7 @@ trainer: 0: train 1: val backbone: - class_path: eva.models.networks.wrappers.ModelFromFunction + class_path: eva.models.ModelFromFunction init_args: path: torch.hub.load arguments: @@ -74,13 +74,13 @@ data: init_args: datasets: train: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: &DATASET_ARGS root: *DATASET_EMBEDDINGS_ROOT manifest_file: manifest.csv split: train val: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: <<: *DATASET_ARGS split: val diff --git a/configs/vision/dino_vit/offline/crc.yaml b/configs/vision/dino_vit/offline/crc.yaml index 16bb84ad..1aafaa41 100644 --- a/configs/vision/dino_vit/offline/crc.yaml +++ b/configs/vision/dino_vit/offline/crc.yaml @@ -29,7 +29,7 @@ trainer: 0: train 1: val backbone: - class_path: eva.models.networks.wrappers.ModelFromFunction + class_path: eva.models.ModelFromFunction init_args: path: torch.hub.load arguments: @@ -74,13 +74,13 @@ data: init_args: datasets: train: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: &DATASET_ARGS root: *DATASET_EMBEDDINGS_ROOT manifest_file: manifest.csv split: train val: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: <<: *DATASET_ARGS split: val diff --git a/configs/vision/dino_vit/offline/mhist.yaml b/configs/vision/dino_vit/offline/mhist.yaml index 77fef9cf..2d0bdca4 100644 --- a/configs/vision/dino_vit/offline/mhist.yaml +++ b/configs/vision/dino_vit/offline/mhist.yaml @@ -29,7 +29,7 @@ trainer: 0: train 1: test backbone: - class_path: eva.models.networks.wrappers.ModelFromFunction + class_path: eva.models.ModelFromFunction init_args: path: torch.hub.load arguments: @@ -72,15 +72,15 @@ data: init_args: datasets: train: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: &DATASET_ARGS root: *DATASET_EMBEDDINGS_ROOT manifest_file: manifest.csv split: train target_transforms: - class_path: eva.vision.data.transforms.common.ArrayToFloatTensor + class_path: eva.core.data.transforms.ArrayToFloatTensor val: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: <<: *DATASET_ARGS split: test diff --git a/configs/vision/dino_vit/offline/patch_camelyon.yaml b/configs/vision/dino_vit/offline/patch_camelyon.yaml index 14520a35..8bcc3f99 100644 --- a/configs/vision/dino_vit/offline/patch_camelyon.yaml +++ b/configs/vision/dino_vit/offline/patch_camelyon.yaml @@ -30,7 +30,7 @@ trainer: 1: val 2: test backbone: - class_path: eva.models.networks.wrappers.ModelFromFunction + class_path: eva.models.ModelFromFunction init_args: path: torch.hub.load arguments: @@ -73,20 +73,20 @@ data: init_args: datasets: train: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: &DATASET_ARGS root: *DATASET_EMBEDDINGS_ROOT manifest_file: manifest.csv split: train target_transforms: - class_path: eva.vision.data.transforms.common.ArrayToFloatTensor + class_path: eva.core.data.transforms.ArrayToFloatTensor val: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: <<: *DATASET_ARGS split: val test: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: <<: *DATASET_ARGS split: test diff --git a/configs/vision/dino_vit/online/bach.yaml b/configs/vision/dino_vit/online/bach.yaml index 136043e7..3ec211d7 100644 --- a/configs/vision/dino_vit/online/bach.yaml +++ b/configs/vision/dino_vit/online/bach.yaml @@ -30,7 +30,7 @@ model: class_path: eva.HeadModule init_args: backbone: - class_path: eva.models.networks.wrappers.ModelFromFunction + class_path: eva.models.ModelFromFunction init_args: path: torch.hub.load arguments: diff --git a/configs/vision/dino_vit/online/crc.yaml b/configs/vision/dino_vit/online/crc.yaml index 98a2fa09..2bb0b6c7 100644 --- a/configs/vision/dino_vit/online/crc.yaml +++ b/configs/vision/dino_vit/online/crc.yaml @@ -30,7 +30,7 @@ model: class_path: eva.HeadModule init_args: backbone: - class_path: eva.models.networks.wrappers.ModelFromFunction + class_path: eva.models.ModelFromFunction init_args: path: torch.hub.load arguments: diff --git a/configs/vision/dino_vit/online/mhist.yaml b/configs/vision/dino_vit/online/mhist.yaml index b1c3de0c..b3b09c03 100644 --- a/configs/vision/dino_vit/online/mhist.yaml +++ b/configs/vision/dino_vit/online/mhist.yaml @@ -30,7 +30,7 @@ model: class_path: eva.HeadModule init_args: backbone: - class_path: eva.models.networks.wrappers.ModelFromFunction + class_path: eva.models.ModelFromFunction init_args: path: torch.hub.load arguments: @@ -76,7 +76,7 @@ data: mean: ${oc.env:NORMALIZE_MEAN, [0.485, 0.456, 0.406]} std: ${oc.env:NORMALIZE_STD, [0.229, 0.224, 0.225]} target_transforms: - class_path: eva.vision.data.transforms.common.ArrayToFloatTensor + class_path: eva.core.data.transforms.ArrayToFloatTensor val: class_path: eva.vision.datasets.MHIST init_args: diff --git a/configs/vision/dino_vit/online/patch_camelyon.yaml b/configs/vision/dino_vit/online/patch_camelyon.yaml index 4f4e6334..1708d944 100644 --- a/configs/vision/dino_vit/online/patch_camelyon.yaml +++ b/configs/vision/dino_vit/online/patch_camelyon.yaml @@ -30,7 +30,7 @@ model: class_path: eva.HeadModule init_args: backbone: - class_path: eva.models.networks.wrappers.ModelFromFunction + class_path: eva.models.ModelFromFunction init_args: path: torch.hub.load arguments: @@ -81,7 +81,7 @@ data: mean: ${oc.env:NORMALIZE_MEAN, [0.485, 0.456, 0.406]} std: ${oc.env:NORMALIZE_STD, [0.229, 0.224, 0.225]} target_transforms: - class_path: eva.vision.data.transforms.common.ArrayToFloatTensor + class_path: eva.core.data.transforms.ArrayToFloatTensor val: class_path: eva.vision.datasets.PatchCamelyon init_args: diff --git a/configs/vision/owkin/phikon/offline/bach.yaml b/configs/vision/owkin/phikon/offline/bach.yaml index 1ee3832f..34305d67 100644 --- a/configs/vision/owkin/phikon/offline/bach.yaml +++ b/configs/vision/owkin/phikon/offline/bach.yaml @@ -29,11 +29,11 @@ trainer: 0: train 1: val backbone: - class_path: eva.models.networks.wrappers.HuggingFaceModel + class_path: eva.models.HuggingFaceModel init_args: model_name_or_path: owkin/phikon tensor_transforms: - class_path: eva.models.networks.transforms.ExtractCLSFeatures + class_path: eva.core.models.networks.transforms.ExtractCLSFeatures logger: - class_path: pytorch_lightning.loggers.TensorBoardLogger init_args: @@ -70,7 +70,7 @@ data: init_args: datasets: train: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: &DATASET_ARGS root: *EMBEDDINGS_DIR manifest_file: manifest.csv @@ -78,7 +78,7 @@ data: column_mapping: path: embedding val: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: <<: *DATASET_ARGS split: val diff --git a/configs/vision/owkin/phikon/offline/crc.yaml b/configs/vision/owkin/phikon/offline/crc.yaml index b3511133..93135777 100644 --- a/configs/vision/owkin/phikon/offline/crc.yaml +++ b/configs/vision/owkin/phikon/offline/crc.yaml @@ -29,11 +29,11 @@ trainer: 0: train 1: val backbone: - class_path: eva.models.networks.wrappers.HuggingFaceModel + class_path: eva.models.HuggingFaceModel init_args: model_name_or_path: owkin/phikon tensor_transforms: - class_path: eva.models.networks.transforms.ExtractCLSFeatures + class_path: eva.core.models.networks.transforms.ExtractCLSFeatures logger: - class_path: pytorch_lightning.loggers.TensorBoardLogger init_args: @@ -70,7 +70,7 @@ data: init_args: datasets: train: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: &DATASET_ARGS root: *EMBEDDINGS_DIR manifest_file: manifest.csv @@ -78,7 +78,7 @@ data: column_mapping: path: embedding val: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: <<: *DATASET_ARGS split: val diff --git a/configs/vision/owkin/phikon/offline/mhist.yaml b/configs/vision/owkin/phikon/offline/mhist.yaml index 6601e600..b9dcd6e7 100644 --- a/configs/vision/owkin/phikon/offline/mhist.yaml +++ b/configs/vision/owkin/phikon/offline/mhist.yaml @@ -29,11 +29,11 @@ trainer: 0: train 1: test backbone: - class_path: eva.models.networks.wrappers.HuggingFaceModel + class_path: eva.models.HuggingFaceModel init_args: model_name_or_path: owkin/phikon tensor_transforms: - class_path: eva.models.networks.transforms.ExtractCLSFeatures + class_path: eva.core.models.networks.transforms.ExtractCLSFeatures logger: - class_path: pytorch_lightning.loggers.TensorBoardLogger init_args: @@ -68,7 +68,7 @@ data: init_args: datasets: train: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: &DATASET_ARGS root: *EMBEDDINGS_DIR manifest_file: manifest.csv @@ -76,9 +76,9 @@ data: column_mapping: path: embedding target_transforms: - class_path: eva.vision.data.transforms.common.ArrayToFloatTensor + class_path: eva.core.data.transforms.ArrayToFloatTensor val: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: <<: *DATASET_ARGS split: test diff --git a/configs/vision/owkin/phikon/offline/patch_camelyon.yaml b/configs/vision/owkin/phikon/offline/patch_camelyon.yaml index 39ba6c17..a9d6fe01 100644 --- a/configs/vision/owkin/phikon/offline/patch_camelyon.yaml +++ b/configs/vision/owkin/phikon/offline/patch_camelyon.yaml @@ -30,11 +30,11 @@ trainer: 1: val 2: test backbone: - class_path: eva.models.networks.wrappers.HuggingFaceModel + class_path: eva.models.HuggingFaceModel init_args: model_name_or_path: owkin/phikon tensor_transforms: - class_path: eva.models.networks.transforms.ExtractCLSFeatures + class_path: eva.core.models.networks.transforms.ExtractCLSFeatures logger: - class_path: pytorch_lightning.loggers.TensorBoardLogger init_args: @@ -69,7 +69,7 @@ data: init_args: datasets: train: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: &DATASET_ARGS root: *EMBEDDINGS_DIR manifest_file: manifest.csv @@ -77,14 +77,14 @@ data: column_mapping: path: embedding target_transforms: - class_path: eva.vision.data.transforms.common.ArrayToFloatTensor + class_path: eva.core.data.transforms.ArrayToFloatTensor val: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: <<: *DATASET_ARGS split: val test: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: <<: *DATASET_ARGS split: test diff --git a/configs/vision/tests/offline/patch_camelyon.yaml b/configs/vision/tests/offline/patch_camelyon.yaml index 2deae65e..912bc915 100644 --- a/configs/vision/tests/offline/patch_camelyon.yaml +++ b/configs/vision/tests/offline/patch_camelyon.yaml @@ -15,7 +15,7 @@ trainer: 1: val 2: test backbone: - class_path: eva.models.networks.wrappers.ModelFromFunction + class_path: eva.core.models.networks.wrappers.ModelFromFunction init_args: path: torch.hub.load arguments: @@ -65,15 +65,15 @@ data: init_args: datasets: train: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: &DATASET_ARGS root: *DATASET_EMBEDDINGS_ROOT manifest_file: manifest.csv split: train target_transforms: - class_path: eva.vision.data.transforms.common.ArrayToFloatTensor + class_path: eva.core.data.transforms.ArrayToFloatTensor val: - class_path: eva.data.datasets.classification.EmbeddingsDataset + class_path: eva.datasets.EmbeddingsClassificationDataset init_args: <<: *DATASET_ARGS split: val diff --git a/configs/vision/tests/online/patch_camelyon.yaml b/configs/vision/tests/online/patch_camelyon.yaml index d1de1435..52c3b466 100644 --- a/configs/vision/tests/online/patch_camelyon.yaml +++ b/configs/vision/tests/online/patch_camelyon.yaml @@ -48,7 +48,7 @@ data: mean: ${oc.env:NORMALIZE_MEAN, [0.485, 0.456, 0.406]} std: ${oc.env:NORMALIZE_STD, [0.229, 0.224, 0.225]} target_transforms: - class_path: eva.vision.data.transforms.common.ArrayToFloatTensor + class_path: eva.core.data.transforms.ArrayToFloatTensor val: class_path: eva.vision.datasets.PatchCamelyon init_args: diff --git a/src/eva/__init__.py b/src/eva/__init__.py index a0833f1c..f1ecafd5 100644 --- a/src/eva/__init__.py +++ b/src/eva/__init__.py @@ -1,19 +1,33 @@ -"""EVA core API.""" +"""eva public API.""" -from eva.cli import cli -from eva.data import DataLoader, DataloadersSchema, DataModule, DatasetsSchema -from eva.interface import Interface -from eva.models import HeadModule, InferenceModule -from eva.trainers import Trainer +from eva.core import ( + DataLoader, + DataloadersSchema, + DataModule, + DatasetsSchema, + HeadModule, + InferenceModule, + Interface, + Trainer, + callbacks, + data, + metrics, + models, +) +from eva.core.data import datasets __all__ = [ - "cli", "DataLoader", "DataloadersSchema", "DataModule", "DatasetsSchema", - "Interface", "HeadModule", "InferenceModule", + "Interface", "Trainer", + "callbacks", + "data", + "metrics", + "models", + "datasets", ] diff --git a/src/eva/__main__.py b/src/eva/__main__.py index 10fd039e..3ecb04f9 100644 --- a/src/eva/__main__.py +++ b/src/eva/__main__.py @@ -1,10 +1,10 @@ -"""EVA's main entry-point module.""" +"""Main entry-point module.""" -from eva.cli import cli +from eva.core.cli import cli def main() -> None: - """EVA's main entry-point. + """Main entry-point. The CLI fetches the input arguments from `sys.argv`. diff --git a/src/eva/callbacks/__init__.py b/src/eva/callbacks/__init__.py deleted file mode 100644 index 5f483b85..00000000 --- a/src/eva/callbacks/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Callbacks API.""" - -from eva.callbacks.writers import EmbeddingsWriter - -__all__ = ["EmbeddingsWriter"] diff --git a/src/eva/callbacks/writers/__init__.py b/src/eva/callbacks/writers/__init__.py deleted file mode 100644 index d2b47a62..00000000 --- a/src/eva/callbacks/writers/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Callbacks API.""" - -from eva.callbacks.writers.embeddings import EmbeddingsWriter - -__all__ = ["EmbeddingsWriter"] diff --git a/src/eva/core/__init__.py b/src/eva/core/__init__.py new file mode 100644 index 00000000..70eca1de --- /dev/null +++ b/src/eva/core/__init__.py @@ -0,0 +1,19 @@ +"""eva core API.""" + +from eva.core.cli import cli +from eva.core.data import DataLoader, DataloadersSchema, DataModule, DatasetsSchema +from eva.core.interface import Interface +from eva.core.models import HeadModule, InferenceModule +from eva.core.trainers import Trainer + +__all__ = [ + "cli", + "DataLoader", + "DataloadersSchema", + "DataModule", + "DatasetsSchema", + "Interface", + "HeadModule", + "InferenceModule", + "Trainer", +] diff --git a/src/eva/core/callbacks/__init__.py b/src/eva/core/callbacks/__init__.py new file mode 100644 index 00000000..dc14697c --- /dev/null +++ b/src/eva/core/callbacks/__init__.py @@ -0,0 +1,5 @@ +"""Callbacks API.""" + +from eva.core.callbacks.writers import EmbeddingsWriter + +__all__ = ["EmbeddingsWriter"] diff --git a/src/eva/core/callbacks/writers/__init__.py b/src/eva/core/callbacks/writers/__init__.py new file mode 100644 index 00000000..a731f06f --- /dev/null +++ b/src/eva/core/callbacks/writers/__init__.py @@ -0,0 +1,5 @@ +"""Callbacks API.""" + +from eva.core.callbacks.writers.embeddings import EmbeddingsWriter + +__all__ = ["EmbeddingsWriter"] diff --git a/src/eva/callbacks/writers/embeddings.py b/src/eva/core/callbacks/writers/embeddings.py similarity index 97% rename from src/eva/callbacks/writers/embeddings.py rename to src/eva/core/callbacks/writers/embeddings.py index 7c1b0596..b6b3188c 100644 --- a/src/eva/callbacks/writers/embeddings.py +++ b/src/eva/core/callbacks/writers/embeddings.py @@ -12,9 +12,9 @@ from torch import multiprocessing, nn from typing_extensions import override -from eva.callbacks.writers.typings import QUEUE_ITEM -from eva.models.modules.typings import INPUT_BATCH -from eva.utils import multiprocessing as eva_multiprocessing +from eva.core.callbacks.writers.typings import QUEUE_ITEM +from eva.core.models.modules.typings import INPUT_BATCH +from eva.core.utils import multiprocessing as eva_multiprocessing class EmbeddingsWriter(callbacks.BasePredictionWriter): diff --git a/src/eva/callbacks/writers/typings.py b/src/eva/core/callbacks/writers/typings.py similarity index 100% rename from src/eva/callbacks/writers/typings.py rename to src/eva/core/callbacks/writers/typings.py diff --git a/src/eva/cli/__init__.py b/src/eva/core/cli/__init__.py similarity index 51% rename from src/eva/cli/__init__.py rename to src/eva/core/cli/__init__.py index 0f19154e..270cdad8 100644 --- a/src/eva/cli/__init__.py +++ b/src/eva/core/cli/__init__.py @@ -1,5 +1,5 @@ """CLI API.""" -from eva.cli.cli import cli +from eva.core.cli.cli import cli __all__ = ["cli"] diff --git a/src/eva/cli/cli.py b/src/eva/core/cli/cli.py similarity index 80% rename from src/eva/cli/cli.py rename to src/eva/core/cli/cli.py index 165053ec..ec1499e9 100644 --- a/src/eva/cli/cli.py +++ b/src/eva/core/cli/cli.py @@ -2,8 +2,8 @@ import jsonargparse -from eva import interface -from eva.cli import logo, setup +from eva.core import interface +from eva.core.cli import logo, setup def cli() -> object: diff --git a/src/eva/cli/logo.py b/src/eva/core/cli/logo.py similarity index 100% rename from src/eva/cli/logo.py rename to src/eva/core/cli/logo.py diff --git a/src/eva/cli/setup.py b/src/eva/core/cli/setup.py similarity index 98% rename from src/eva/cli/setup.py rename to src/eva/core/cli/setup.py index 0c8c8d72..c45dd300 100644 --- a/src/eva/cli/setup.py +++ b/src/eva/core/cli/setup.py @@ -9,7 +9,7 @@ from lightning_fabric.utilities import seed as pl_seed from loguru import logger -from eva.utils import workers +from eva.core.utils import workers def _configure_random_seed(seed: int | None = None) -> None: diff --git a/src/eva/core/data/__init__.py b/src/eva/core/data/__init__.py new file mode 100644 index 00000000..00c8076c --- /dev/null +++ b/src/eva/core/data/__init__.py @@ -0,0 +1,14 @@ +"""Data API.""" + +from eva.core.data.dataloaders import DataLoader +from eva.core.data.datamodules import DataloadersSchema, DataModule, DatasetsSchema +from eva.core.data.datasets import Dataset, TorchDataset + +__all__ = [ + "DataLoader", + "DataloadersSchema", + "DataModule", + "DatasetsSchema", + "Dataset", + "TorchDataset", +] diff --git a/src/eva/core/data/dataloaders/__init__.py b/src/eva/core/data/dataloaders/__init__.py new file mode 100644 index 00000000..f20954fc --- /dev/null +++ b/src/eva/core/data/dataloaders/__init__.py @@ -0,0 +1,5 @@ +"""Dataloaders API.""" + +from eva.core.data.dataloaders.dataloader import DataLoader + +__all__ = ["DataLoader"] diff --git a/src/eva/data/dataloaders/dataloader.py b/src/eva/core/data/dataloaders/dataloader.py similarity index 98% rename from src/eva/data/dataloaders/dataloader.py rename to src/eva/core/data/dataloaders/dataloader.py index 2d822db4..5c8a3292 100644 --- a/src/eva/data/dataloaders/dataloader.py +++ b/src/eva/core/data/dataloaders/dataloader.py @@ -6,7 +6,7 @@ from torch.utils.data import dataloader -from eva.data import datasets, samplers +from eva.core.data import datasets, samplers @dataclasses.dataclass diff --git a/src/eva/core/data/datamodules/__init__.py b/src/eva/core/data/datamodules/__init__.py new file mode 100644 index 00000000..d152e8f3 --- /dev/null +++ b/src/eva/core/data/datamodules/__init__.py @@ -0,0 +1,6 @@ +"""Datamodules API.""" + +from eva.core.data.datamodules.datamodule import DataModule +from eva.core.data.datamodules.schemas import DataloadersSchema, DatasetsSchema + +__all__ = ["DataModule", "DataloadersSchema", "DatasetsSchema"] diff --git a/src/eva/data/datamodules/call.py b/src/eva/core/data/datamodules/call.py similarity index 94% rename from src/eva/data/datamodules/call.py rename to src/eva/core/data/datamodules/call.py index 5a00bfe2..0915cc7b 100644 --- a/src/eva/data/datamodules/call.py +++ b/src/eva/core/data/datamodules/call.py @@ -2,7 +2,7 @@ from typing import Any, Iterable -from eva.data import datasets as datasets_lib +from eva.core.data import datasets as datasets_lib def call_method_if_exists(objects: Iterable[Any], /, method: str) -> None: diff --git a/src/eva/data/datamodules/datamodule.py b/src/eva/core/data/datamodules/datamodule.py similarity index 95% rename from src/eva/data/datamodules/datamodule.py rename to src/eva/core/data/datamodules/datamodule.py index cc6b1815..ca049208 100644 --- a/src/eva/data/datamodules/datamodule.py +++ b/src/eva/core/data/datamodules/datamodule.py @@ -6,9 +6,9 @@ from pytorch_lightning.utilities.types import EVAL_DATALOADERS, TRAIN_DATALOADERS from typing_extensions import override -from eva.data import dataloaders as dataloaders_lib -from eva.data import datasets as datasets_lib -from eva.data.datamodules import call, schemas +from eva.core.data import dataloaders as dataloaders_lib +from eva.core.data import datasets as datasets_lib +from eva.core.data.datamodules import call, schemas class DataModule(pl.LightningDataModule): diff --git a/src/eva/data/datamodules/schemas.py b/src/eva/core/data/datamodules/schemas.py similarity index 97% rename from src/eva/data/datamodules/schemas.py rename to src/eva/core/data/datamodules/schemas.py index bcca944c..8780ac61 100644 --- a/src/eva/data/datamodules/schemas.py +++ b/src/eva/core/data/datamodules/schemas.py @@ -3,7 +3,7 @@ import dataclasses from typing import List -from eva.data import dataloaders, datasets +from eva.core.data import dataloaders, datasets TRAIN_DATASET = datasets.TorchDataset | None """Train dataset.""" diff --git a/src/eva/core/data/datasets/__init__.py b/src/eva/core/data/datasets/__init__.py new file mode 100644 index 00000000..c8f665fa --- /dev/null +++ b/src/eva/core/data/datasets/__init__.py @@ -0,0 +1,7 @@ +"""Datasets API.""" + +from eva.core.data.datasets.base import Dataset +from eva.core.data.datasets.classification import EmbeddingsClassificationDataset +from eva.core.data.datasets.dataset import TorchDataset + +__all__ = ["Dataset", "EmbeddingsClassificationDataset", "TorchDataset"] diff --git a/src/eva/data/datasets/base.py b/src/eva/core/data/datasets/base.py similarity index 85% rename from src/eva/data/datasets/base.py rename to src/eva/core/data/datasets/base.py index c49f49c5..d83fa74e 100644 --- a/src/eva/data/datasets/base.py +++ b/src/eva/core/data/datasets/base.py @@ -1,6 +1,6 @@ """Base dataset class.""" -from eva.data.datasets import dataset +from eva.core.data.datasets import dataset class Dataset(dataset.TorchDataset): @@ -11,7 +11,7 @@ def prepare_data(self) -> None: This method is preferred for downloading and preparing the data, for example generate manifest files. If implemented, it will be called via - :class:`eva.data.datamodules.DataModule`, which ensures that is called + :class:`eva.core.data.datamodules.DataModule`, which ensures that is called only within a single process, making it multi-processes safe. """ @@ -20,7 +20,7 @@ def setup(self) -> None: This method is preferred for creating datasets or performing train/val/test splits. If implemented, it will be called via - :class:`eva.data.datamodules.DataModule` at the beginning of fit + :class:`eva.core.data.datamodules.DataModule` at the beginning of fit (train + validate), validate, test, or predict and it will be called from every process (i.e. GPU) across all the nodes in DDP. """ @@ -47,7 +47,7 @@ def teardown(self) -> None: """Cleans up the data artifacts. Used to clean-up when the run is finished. If implemented, it will - be called via :class:`eva.data.datamodules.DataModule` at the end + be called via :class:`eva.core.data.datamodules.DataModule` at the end of fit (train + validate), validate, test, or predict and it will be called from every process (i.e. GPU) across all the nodes in DDP. """ diff --git a/src/eva/core/data/datasets/classification/__init__.py b/src/eva/core/data/datasets/classification/__init__.py new file mode 100644 index 00000000..abd096df --- /dev/null +++ b/src/eva/core/data/datasets/classification/__init__.py @@ -0,0 +1,5 @@ +"""Classification datasets API.""" + +from eva.core.data.datasets.classification.embeddings import EmbeddingsClassificationDataset + +__all__ = ["EmbeddingsClassificationDataset"] diff --git a/src/eva/data/datasets/classification/embeddings.py b/src/eva/core/data/datasets/classification/embeddings.py similarity index 97% rename from src/eva/data/datasets/classification/embeddings.py rename to src/eva/core/data/datasets/classification/embeddings.py index 605ed29b..e9bac527 100644 --- a/src/eva/data/datasets/classification/embeddings.py +++ b/src/eva/core/data/datasets/classification/embeddings.py @@ -8,11 +8,11 @@ import torch from typing_extensions import override -from eva.data.datasets import base -from eva.utils import io +from eva.core.data.datasets import base +from eva.core.utils import io -class EmbeddingsDataset(base.Dataset): +class EmbeddingsClassificationDataset(base.Dataset): """Embeddings classification dataset.""" default_column_mapping: Dict[str, str] = { diff --git a/src/eva/data/datasets/dataset.py b/src/eva/core/data/datasets/dataset.py similarity index 100% rename from src/eva/data/datasets/dataset.py rename to src/eva/core/data/datasets/dataset.py diff --git a/src/eva/core/data/samplers/__init__.py b/src/eva/core/data/samplers/__init__.py new file mode 100644 index 00000000..5cc3a852 --- /dev/null +++ b/src/eva/core/data/samplers/__init__.py @@ -0,0 +1,5 @@ +"""Data samplers API.""" + +from eva.core.data.samplers.sampler import Sampler + +__all__ = ["Sampler"] diff --git a/src/eva/data/samplers/sampler.py b/src/eva/core/data/samplers/sampler.py similarity index 100% rename from src/eva/data/samplers/sampler.py rename to src/eva/core/data/samplers/sampler.py diff --git a/src/eva/core/data/transforms/__init__.py b/src/eva/core/data/transforms/__init__.py new file mode 100644 index 00000000..03ed7f96 --- /dev/null +++ b/src/eva/core/data/transforms/__init__.py @@ -0,0 +1,5 @@ +"""Core data transforms.""" + +from eva.core.data.transforms.dtype import ArrayToFloatTensor, ArrayToTensor + +__all__ = ["ArrayToFloatTensor", "ArrayToTensor"] diff --git a/src/eva/core/data/transforms/dtype/__init__.py b/src/eva/core/data/transforms/dtype/__init__.py new file mode 100644 index 00000000..50b6fb20 --- /dev/null +++ b/src/eva/core/data/transforms/dtype/__init__.py @@ -0,0 +1,5 @@ +"""Type casting related transforms.""" + +from eva.core.data.transforms.dtype.array import ArrayToFloatTensor, ArrayToTensor + +__all__ = ["ArrayToFloatTensor", "ArrayToTensor"] diff --git a/src/eva/vision/data/transforms/common/array_to_tensor.py b/src/eva/core/data/transforms/dtype/array.py similarity index 100% rename from src/eva/vision/data/transforms/common/array_to_tensor.py rename to src/eva/core/data/transforms/dtype/array.py diff --git a/src/eva/core/interface/__init__.py b/src/eva/core/interface/__init__.py new file mode 100644 index 00000000..73627b8a --- /dev/null +++ b/src/eva/core/interface/__init__.py @@ -0,0 +1,5 @@ +"""Interface API.""" + +from eva.core.interface.interface import Interface + +__all__ = ["Interface"] diff --git a/src/eva/interface/interface.py b/src/eva/core/interface/interface.py similarity index 95% rename from src/eva/interface/interface.py rename to src/eva/core/interface/interface.py index 0d7c4fa2..af0e9aa7 100644 --- a/src/eva/interface/interface.py +++ b/src/eva/core/interface/interface.py @@ -1,8 +1,8 @@ """Main interface class.""" -from eva import trainers as eva_trainer -from eva.data import datamodules -from eva.models import modules +from eva.core import trainers as eva_trainer +from eva.core.data import datamodules +from eva.core.models import modules class Interface: diff --git a/src/eva/core/metrics/__init__.py b/src/eva/core/metrics/__init__.py new file mode 100644 index 00000000..c1a8745c --- /dev/null +++ b/src/eva/core/metrics/__init__.py @@ -0,0 +1,17 @@ +"""Metrics API.""" + +from eva.core.metrics.average_loss import AverageLoss +from eva.core.metrics.binary_balanced_accuracy import BinaryBalancedAccuracy +from eva.core.metrics.defaults import BinaryClassificationMetrics, MulticlassClassificationMetrics +from eva.core.metrics.structs import Metric, MetricCollection, MetricModule, MetricsSchema + +__all__ = [ + "AverageLoss", + "BinaryBalancedAccuracy", + "Metric", + "MetricCollection", + "MetricModule", + "MetricsSchema", + "MulticlassClassificationMetrics", + "BinaryClassificationMetrics", +] diff --git a/src/eva/metrics/average_loss.py b/src/eva/core/metrics/average_loss.py similarity index 94% rename from src/eva/metrics/average_loss.py rename to src/eva/core/metrics/average_loss.py index c563c465..390c72f5 100644 --- a/src/eva/metrics/average_loss.py +++ b/src/eva/core/metrics/average_loss.py @@ -4,10 +4,10 @@ from loguru import logger from typing_extensions import override -from eva.metrics import core +from eva.core.metrics import structs -class AverageLoss(core.Metric): +class AverageLoss(structs.Metric): """Average loss metric tracker.""" is_differentiable = True diff --git a/src/eva/metrics/binary_balanced_accuracy.py b/src/eva/core/metrics/binary_balanced_accuracy.py similarity index 100% rename from src/eva/metrics/binary_balanced_accuracy.py rename to src/eva/core/metrics/binary_balanced_accuracy.py diff --git a/src/eva/core/metrics/defaults/__init__.py b/src/eva/core/metrics/defaults/__init__.py new file mode 100644 index 00000000..a75d8286 --- /dev/null +++ b/src/eva/core/metrics/defaults/__init__.py @@ -0,0 +1,6 @@ +"""Default metric collections API.""" + +from eva.core.metrics.defaults.classification.binary import BinaryClassificationMetrics +from eva.core.metrics.defaults.classification.multiclass import MulticlassClassificationMetrics + +__all__ = ["MulticlassClassificationMetrics", "BinaryClassificationMetrics"] diff --git a/src/eva/core/metrics/defaults/classification/__init__.py b/src/eva/core/metrics/defaults/classification/__init__.py new file mode 100644 index 00000000..638d43ab --- /dev/null +++ b/src/eva/core/metrics/defaults/classification/__init__.py @@ -0,0 +1,6 @@ +"""Default classification metric collections API.""" + +from eva.core.metrics.defaults.classification.binary import BinaryClassificationMetrics +from eva.core.metrics.defaults.classification.multiclass import MulticlassClassificationMetrics + +__all__ = ["MulticlassClassificationMetrics", "BinaryClassificationMetrics"] diff --git a/src/eva/metrics/defaults/classification/binary.py b/src/eva/core/metrics/defaults/classification/binary.py similarity index 95% rename from src/eva/metrics/defaults/classification/binary.py rename to src/eva/core/metrics/defaults/classification/binary.py index 64da004e..e13d55e3 100644 --- a/src/eva/metrics/defaults/classification/binary.py +++ b/src/eva/core/metrics/defaults/classification/binary.py @@ -2,10 +2,10 @@ from torchmetrics import classification -from eva.metrics import binary_balanced_accuracy, core +from eva.core.metrics import binary_balanced_accuracy, structs -class BinaryClassificationMetrics(core.MetricCollection): +class BinaryClassificationMetrics(structs.MetricCollection): """Default metrics for binary classification tasks.""" def __init__( diff --git a/src/eva/metrics/defaults/classification/multiclass.py b/src/eva/core/metrics/defaults/classification/multiclass.py similarity index 96% rename from src/eva/metrics/defaults/classification/multiclass.py rename to src/eva/core/metrics/defaults/classification/multiclass.py index cdf15d7a..fba93835 100644 --- a/src/eva/metrics/defaults/classification/multiclass.py +++ b/src/eva/core/metrics/defaults/classification/multiclass.py @@ -4,10 +4,10 @@ from torchmetrics import classification -from eva.metrics import core +from eva.core.metrics import structs -class MulticlassClassificationMetrics(core.MetricCollection): +class MulticlassClassificationMetrics(structs.MetricCollection): """Default metrics for multi-class classification tasks.""" def __init__( diff --git a/src/eva/core/metrics/structs/__init__.py b/src/eva/core/metrics/structs/__init__.py new file mode 100644 index 00000000..e5c51e4b --- /dev/null +++ b/src/eva/core/metrics/structs/__init__.py @@ -0,0 +1,9 @@ +"""Core metrics modules API.""" + +from eva.core.metrics.structs.collection import MetricCollection +from eva.core.metrics.structs.metric import Metric +from eva.core.metrics.structs.module import MetricModule +from eva.core.metrics.structs.schemas import MetricsSchema +from eva.core.metrics.structs.typings import MetricModuleType + +__all__ = ["MetricCollection", "Metric", "MetricModule", "MetricsSchema", "MetricModuleType"] diff --git a/src/eva/metrics/core/collection.py b/src/eva/core/metrics/structs/collection.py similarity index 100% rename from src/eva/metrics/core/collection.py rename to src/eva/core/metrics/structs/collection.py diff --git a/src/eva/metrics/core/metric.py b/src/eva/core/metrics/structs/metric.py similarity index 100% rename from src/eva/metrics/core/metric.py rename to src/eva/core/metrics/structs/metric.py diff --git a/src/eva/metrics/core/module.py b/src/eva/core/metrics/structs/module.py similarity index 96% rename from src/eva/metrics/core/module.py rename to src/eva/core/metrics/structs/module.py index 89a5ef9b..af0ca38e 100644 --- a/src/eva/metrics/core/module.py +++ b/src/eva/core/metrics/structs/module.py @@ -4,8 +4,8 @@ from torch import nn -from eva.metrics.core import collection, schemas -from eva.metrics.core.typings import MetricModuleType +from eva.core.metrics.structs import collection, schemas +from eva.core.metrics.structs.typings import MetricModuleType class MetricModule(nn.Module): diff --git a/src/eva/metrics/core/schemas.py b/src/eva/core/metrics/structs/schemas.py similarity index 95% rename from src/eva/metrics/core/schemas.py rename to src/eva/core/metrics/structs/schemas.py index 1f089d31..ef8b7fb4 100644 --- a/src/eva/metrics/core/schemas.py +++ b/src/eva/core/metrics/structs/schemas.py @@ -2,7 +2,7 @@ import dataclasses -from eva.metrics.core.typings import MetricModuleType +from eva.core.metrics.structs.typings import MetricModuleType @dataclasses.dataclass(frozen=True) diff --git a/src/eva/metrics/core/typings.py b/src/eva/core/metrics/structs/typings.py similarity index 85% rename from src/eva/metrics/core/typings.py rename to src/eva/core/metrics/structs/typings.py index d7cbaf66..4aca24a4 100644 --- a/src/eva/metrics/core/typings.py +++ b/src/eva/core/metrics/structs/typings.py @@ -2,7 +2,7 @@ from typing import Dict, Sequence, Union -from eva.metrics.core import collection, metric +from eva.core.metrics.structs import collection, metric BaseMetricModuleType = Union[metric.Metric, collection.MetricCollection] """The base module metric type.""" diff --git a/src/eva/core/models/__init__.py b/src/eva/core/models/__init__.py new file mode 100644 index 00000000..a62037b9 --- /dev/null +++ b/src/eva/core/models/__init__.py @@ -0,0 +1,13 @@ +"""Models API.""" + +from eva.core.models.modules import HeadModule, InferenceModule +from eva.core.models.networks import MLP, HuggingFaceModel, ModelFromFunction, ONNXModel + +__all__ = [ + "HeadModule", + "InferenceModule", + "MLP", + "HuggingFaceModel", + "ModelFromFunction", + "ONNXModel", +] diff --git a/src/eva/core/models/modules/__init__.py b/src/eva/core/models/modules/__init__.py new file mode 100644 index 00000000..0ac804f0 --- /dev/null +++ b/src/eva/core/models/modules/__init__.py @@ -0,0 +1,7 @@ +"""Model Modules API.""" + +from eva.core.models.modules.head import HeadModule +from eva.core.models.modules.inference import InferenceModule +from eva.core.models.modules.module import ModelModule + +__all__ = ["HeadModule", "ModelModule", "InferenceModule"] diff --git a/src/eva/models/modules/head.py b/src/eva/core/models/modules/head.py similarity index 94% rename from src/eva/models/modules/head.py rename to src/eva/core/models/modules/head.py index 9732d71f..14e91648 100644 --- a/src/eva/models/modules/head.py +++ b/src/eva/core/models/modules/head.py @@ -9,10 +9,10 @@ from torch.optim import lr_scheduler from typing_extensions import override -from eva.metrics import core as metrics_lib -from eva.models.modules import module -from eva.models.modules.typings import INPUT_BATCH, MODEL_TYPE -from eva.models.modules.utils import batch_postprocess, grad +from eva.core.metrics import structs as metrics_lib +from eva.core.models.modules import module +from eva.core.models.modules.typings import INPUT_BATCH, MODEL_TYPE +from eva.core.models.modules.utils import batch_postprocess, grad class HeadModule(module.ModelModule): diff --git a/src/eva/models/modules/inference.py b/src/eva/core/models/modules/inference.py similarity index 88% rename from src/eva/models/modules/inference.py rename to src/eva/core/models/modules/inference.py index 201998ff..d41f584f 100644 --- a/src/eva/models/modules/inference.py +++ b/src/eva/core/models/modules/inference.py @@ -4,8 +4,8 @@ from pytorch_lightning.utilities.types import STEP_OUTPUT from typing_extensions import override -from eva.models.modules import module -from eva.models.modules.typings import INPUT_BATCH, MODEL_TYPE +from eva.core.models.modules import module +from eva.core.models.modules.typings import INPUT_BATCH, MODEL_TYPE class InferenceModule(module.ModelModule): diff --git a/src/eva/models/modules/module.py b/src/eva/core/models/modules/module.py similarity index 97% rename from src/eva/models/modules/module.py rename to src/eva/core/models/modules/module.py index 40378f18..7a25d185 100644 --- a/src/eva/models/modules/module.py +++ b/src/eva/core/models/modules/module.py @@ -8,9 +8,9 @@ from pytorch_lightning.utilities.types import STEP_OUTPUT from typing_extensions import override -from eva.metrics import core as metrics_lib -from eva.models.modules.typings import INPUT_BATCH -from eva.models.modules.utils import batch_postprocess +from eva.core.metrics import structs as metrics_lib +from eva.core.models.modules.typings import INPUT_BATCH +from eva.core.models.modules.utils import batch_postprocess class ModelModule(pl.LightningModule): diff --git a/src/eva/models/modules/typings.py b/src/eva/core/models/modules/typings.py similarity index 100% rename from src/eva/models/modules/typings.py rename to src/eva/core/models/modules/typings.py diff --git a/src/eva/core/models/modules/utils/__init__.py b/src/eva/core/models/modules/utils/__init__.py new file mode 100644 index 00000000..f190e07b --- /dev/null +++ b/src/eva/core/models/modules/utils/__init__.py @@ -0,0 +1,6 @@ +"""Utilities and helper functionalities for model modules.""" + +from eva.core.models.modules.utils import grad +from eva.core.models.modules.utils.batch_postprocess import BatchPostProcess + +__all__ = ["grad", "BatchPostProcess"] diff --git a/src/eva/models/modules/utils/batch_postprocess.py b/src/eva/core/models/modules/utils/batch_postprocess.py similarity index 100% rename from src/eva/models/modules/utils/batch_postprocess.py rename to src/eva/core/models/modules/utils/batch_postprocess.py diff --git a/src/eva/models/modules/utils/grad.py b/src/eva/core/models/modules/utils/grad.py similarity index 100% rename from src/eva/models/modules/utils/grad.py rename to src/eva/core/models/modules/utils/grad.py diff --git a/src/eva/core/models/networks/__init__.py b/src/eva/core/models/networks/__init__.py new file mode 100644 index 00000000..c1ce5bb3 --- /dev/null +++ b/src/eva/core/models/networks/__init__.py @@ -0,0 +1,6 @@ +"""Networks API.""" + +from eva.core.models.networks.mlp import MLP +from eva.core.models.networks.wrappers import HuggingFaceModel, ModelFromFunction, ONNXModel + +__all__ = ["ModelFromFunction", "HuggingFaceModel", "ONNXModel", "MLP"] diff --git a/src/eva/models/networks/_utils.py b/src/eva/core/models/networks/_utils.py similarity index 100% rename from src/eva/models/networks/_utils.py rename to src/eva/core/models/networks/_utils.py diff --git a/src/eva/models/networks/mlp.py b/src/eva/core/models/networks/mlp.py similarity index 100% rename from src/eva/models/networks/mlp.py rename to src/eva/core/models/networks/mlp.py diff --git a/src/eva/core/models/networks/transforms/__init__.py b/src/eva/core/models/networks/transforms/__init__.py new file mode 100644 index 00000000..ed9b411e --- /dev/null +++ b/src/eva/core/models/networks/transforms/__init__.py @@ -0,0 +1,5 @@ +"""Model outputs transforms API.""" + +from eva.core.models.networks.transforms.extract_cls_features import ExtractCLSFeatures + +__all__ = ["ExtractCLSFeatures"] diff --git a/src/eva/models/networks/transforms/extract_cls_features.py b/src/eva/core/models/networks/transforms/extract_cls_features.py similarity index 100% rename from src/eva/models/networks/transforms/extract_cls_features.py rename to src/eva/core/models/networks/transforms/extract_cls_features.py diff --git a/src/eva/core/models/networks/wrappers/__init__.py b/src/eva/core/models/networks/wrappers/__init__.py new file mode 100644 index 00000000..42513046 --- /dev/null +++ b/src/eva/core/models/networks/wrappers/__init__.py @@ -0,0 +1,8 @@ +"""Model Wrappers API.""" + +from eva.core.models.networks.wrappers.base import BaseModel +from eva.core.models.networks.wrappers.from_function import ModelFromFunction +from eva.core.models.networks.wrappers.huggingface import HuggingFaceModel +from eva.core.models.networks.wrappers.onnx import ONNXModel + +__all__ = ["BaseModel", "ModelFromFunction", "HuggingFaceModel", "ONNXModel"] diff --git a/src/eva/models/networks/wrappers/base.py b/src/eva/core/models/networks/wrappers/base.py similarity index 100% rename from src/eva/models/networks/wrappers/base.py rename to src/eva/core/models/networks/wrappers/base.py diff --git a/src/eva/models/networks/wrappers/from_function.py b/src/eva/core/models/networks/wrappers/from_function.py similarity index 95% rename from src/eva/models/networks/wrappers/from_function.py rename to src/eva/core/models/networks/wrappers/from_function.py index a33ec022..5a3b981c 100644 --- a/src/eva/models/networks/wrappers/from_function.py +++ b/src/eva/core/models/networks/wrappers/from_function.py @@ -7,8 +7,8 @@ from torch import nn from typing_extensions import override -from eva.models.networks import _utils -from eva.models.networks.wrappers import base +from eva.core.models.networks import _utils +from eva.core.models.networks.wrappers import base class ModelFromFunction(base.BaseModel): diff --git a/src/eva/models/networks/wrappers/huggingface.py b/src/eva/core/models/networks/wrappers/huggingface.py similarity index 96% rename from src/eva/models/networks/wrappers/huggingface.py rename to src/eva/core/models/networks/wrappers/huggingface.py index ce9823c0..084f61c3 100644 --- a/src/eva/models/networks/wrappers/huggingface.py +++ b/src/eva/core/models/networks/wrappers/huggingface.py @@ -6,7 +6,7 @@ import transformers from typing_extensions import override -from eva.models.networks.wrappers import base +from eva.core.models.networks.wrappers import base class HuggingFaceModel(base.BaseModel): diff --git a/src/eva/models/networks/wrappers/onnx.py b/src/eva/core/models/networks/wrappers/onnx.py similarity index 97% rename from src/eva/models/networks/wrappers/onnx.py rename to src/eva/core/models/networks/wrappers/onnx.py index cd973ea2..b631034b 100644 --- a/src/eva/models/networks/wrappers/onnx.py +++ b/src/eva/core/models/networks/wrappers/onnx.py @@ -6,7 +6,7 @@ import torch from typing_extensions import override -from eva.models.networks.wrappers import base +from eva.core.models.networks.wrappers import base class ONNXModel(base.BaseModel): diff --git a/src/eva/core/trainers/__init__.py b/src/eva/core/trainers/__init__.py new file mode 100644 index 00000000..00063fd8 --- /dev/null +++ b/src/eva/core/trainers/__init__.py @@ -0,0 +1,6 @@ +"""Trainers API.""" + +from eva.core.trainers.functional import infer_model, run_evaluation_session +from eva.core.trainers.trainer import Trainer + +__all__ = ["infer_model", "run_evaluation_session", "Trainer"] diff --git a/src/eva/trainers/_logging.py b/src/eva/core/trainers/_logging.py similarity index 100% rename from src/eva/trainers/_logging.py rename to src/eva/core/trainers/_logging.py diff --git a/src/eva/trainers/_recorder.py b/src/eva/core/trainers/_recorder.py similarity index 100% rename from src/eva/trainers/_recorder.py rename to src/eva/core/trainers/_recorder.py diff --git a/src/eva/trainers/_utils.py b/src/eva/core/trainers/_utils.py similarity index 100% rename from src/eva/trainers/_utils.py rename to src/eva/core/trainers/_utils.py diff --git a/src/eva/trainers/functional.py b/src/eva/core/trainers/functional.py similarity index 95% rename from src/eva/trainers/functional.py rename to src/eva/core/trainers/functional.py index b9cabbbe..8a8a28d7 100644 --- a/src/eva/trainers/functional.py +++ b/src/eva/core/trainers/functional.py @@ -4,10 +4,10 @@ from pytorch_lightning.utilities.types import _EVALUATE_OUTPUT -from eva.data import datamodules -from eva.models import modules -from eva.trainers import _recorder, _utils -from eva.trainers import trainer as eva_trainer +from eva.core.data import datamodules +from eva.core.models import modules +from eva.core.trainers import _recorder, _utils +from eva.core.trainers import trainer as eva_trainer def run_evaluation_session( diff --git a/src/eva/trainers/trainer.py b/src/eva/core/trainers/trainer.py similarity index 96% rename from src/eva/trainers/trainer.py rename to src/eva/core/trainers/trainer.py index 101e8bcd..168bcdf2 100644 --- a/src/eva/trainers/trainer.py +++ b/src/eva/core/trainers/trainer.py @@ -8,9 +8,9 @@ from pytorch_lightning.utilities import argparse from typing_extensions import override -from eva.data import datamodules -from eva.models import modules -from eva.trainers import _logging, functional +from eva.core.data import datamodules +from eva.core.models import modules +from eva.core.trainers import _logging, functional class Trainer(pl_trainer.Trainer): diff --git a/src/eva/utils/__init__.py b/src/eva/core/utils/__init__.py similarity index 100% rename from src/eva/utils/__init__.py rename to src/eva/core/utils/__init__.py diff --git a/src/eva/utils/io/__init__.py b/src/eva/core/utils/io/__init__.py similarity index 50% rename from src/eva/utils/io/__init__.py rename to src/eva/core/utils/io/__init__.py index 37c97f2a..232ec98d 100644 --- a/src/eva/utils/io/__init__.py +++ b/src/eva/core/utils/io/__init__.py @@ -1,5 +1,5 @@ """Core I/O utilities.""" -from eva.utils.io.dataframe import read_dataframe +from eva.core.utils.io.dataframe import read_dataframe __all__ = ["read_dataframe"] diff --git a/src/eva/utils/io/dataframe.py b/src/eva/core/utils/io/dataframe.py similarity index 100% rename from src/eva/utils/io/dataframe.py rename to src/eva/core/utils/io/dataframe.py diff --git a/src/eva/utils/multiprocessing.py b/src/eva/core/utils/multiprocessing.py similarity index 100% rename from src/eva/utils/multiprocessing.py rename to src/eva/core/utils/multiprocessing.py diff --git a/src/eva/utils/workers.py b/src/eva/core/utils/workers.py similarity index 100% rename from src/eva/utils/workers.py rename to src/eva/core/utils/workers.py diff --git a/src/eva/data/__init__.py b/src/eva/data/__init__.py deleted file mode 100644 index cffca8be..00000000 --- a/src/eva/data/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -"""Data API.""" - -from eva.data.dataloaders import DataLoader -from eva.data.datamodules import DataloadersSchema, DataModule, DatasetsSchema -from eva.data.datasets import Dataset - -__all__ = [ - "DataLoader", - "DataloadersSchema", - "DataModule", - "DatasetsSchema", - "Dataset", -] diff --git a/src/eva/data/dataloaders/__init__.py b/src/eva/data/dataloaders/__init__.py deleted file mode 100644 index 64e825a9..00000000 --- a/src/eva/data/dataloaders/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Dataloaders API.""" - -from eva.data.dataloaders.dataloader import DataLoader - -__all__ = ["DataLoader"] diff --git a/src/eva/data/datamodules/__init__.py b/src/eva/data/datamodules/__init__.py deleted file mode 100644 index 9a4fa593..00000000 --- a/src/eva/data/datamodules/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -"""Datamodules API.""" - -from eva.data.datamodules.datamodule import DataModule -from eva.data.datamodules.schemas import DataloadersSchema, DatasetsSchema - -__all__ = ["DataModule", "DataloadersSchema", "DatasetsSchema"] diff --git a/src/eva/data/datasets/__init__.py b/src/eva/data/datasets/__init__.py deleted file mode 100644 index 18d41bf5..00000000 --- a/src/eva/data/datasets/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Datasets API.""" - -from eva.data.datasets import classification -from eva.data.datasets.base import Dataset -from eva.data.datasets.dataset import TorchDataset - -__all__ = ["classification", "Dataset", "TorchDataset"] diff --git a/src/eva/data/datasets/classification/__init__.py b/src/eva/data/datasets/classification/__init__.py deleted file mode 100644 index 5ed5335f..00000000 --- a/src/eva/data/datasets/classification/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Classification datasets API.""" - -from eva.data.datasets.classification.embeddings import EmbeddingsDataset - -__all__ = ["EmbeddingsDataset"] diff --git a/src/eva/data/samplers/__init__.py b/src/eva/data/samplers/__init__.py deleted file mode 100644 index 1cc44e24..00000000 --- a/src/eva/data/samplers/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Data samplers API.""" - -from eva.data.samplers.sampler import Sampler - -__all__ = ["Sampler"] diff --git a/src/eva/interface/__init__.py b/src/eva/interface/__init__.py deleted file mode 100644 index 7d05fb37..00000000 --- a/src/eva/interface/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Interface API.""" - -from eva.interface.interface import Interface - -__all__ = ["Interface"] diff --git a/src/eva/metrics/__init__.py b/src/eva/metrics/__init__.py deleted file mode 100644 index 2613f4ac..00000000 --- a/src/eva/metrics/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ -"""Metrics API.""" - -from eva.metrics.average_loss import AverageLoss -from eva.metrics.binary_balanced_accuracy import BinaryBalancedAccuracy -from eva.metrics.core import Metric, MetricCollection, MetricModule, MetricsSchema -from eva.metrics.defaults.classification.binary import BinaryClassificationMetrics -from eva.metrics.defaults.classification.multiclass import MulticlassClassificationMetrics - -__all__ = [ - "AverageLoss", - "BinaryBalancedAccuracy", - "Metric", - "MetricCollection", - "MetricModule", - "MetricsSchema", - "MulticlassClassificationMetrics", - "BinaryClassificationMetrics", -] diff --git a/src/eva/metrics/core/__init__.py b/src/eva/metrics/core/__init__.py deleted file mode 100644 index 206cb25f..00000000 --- a/src/eva/metrics/core/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -"""Core metrics modules API.""" - -from eva.metrics.core.collection import MetricCollection -from eva.metrics.core.metric import Metric -from eva.metrics.core.module import MetricModule -from eva.metrics.core.schemas import MetricsSchema -from eva.metrics.core.typings import MetricModuleType - -__all__ = ["MetricCollection", "Metric", "MetricModule", "MetricsSchema", "MetricModuleType"] diff --git a/src/eva/metrics/defaults/__init__.py b/src/eva/metrics/defaults/__init__.py deleted file mode 100644 index 5d21d47f..00000000 --- a/src/eva/metrics/defaults/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -"""Default metric collections API.""" - -from eva.metrics.defaults.classification.binary import BinaryClassificationMetrics -from eva.metrics.defaults.classification.multiclass import MulticlassClassificationMetrics - -__all__ = ["MulticlassClassificationMetrics", "BinaryClassificationMetrics"] diff --git a/src/eva/metrics/defaults/classification/__init__.py b/src/eva/metrics/defaults/classification/__init__.py deleted file mode 100644 index da9f4f6b..00000000 --- a/src/eva/metrics/defaults/classification/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -"""Default classification metric collections API.""" - -from eva.metrics.defaults.classification.binary import BinaryClassificationMetrics -from eva.metrics.defaults.classification.multiclass import MulticlassClassificationMetrics - -__all__ = ["MulticlassClassificationMetrics", "BinaryClassificationMetrics"] diff --git a/src/eva/models/__init__.py b/src/eva/models/__init__.py deleted file mode 100644 index 373275e3..00000000 --- a/src/eva/models/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -"""Models API.""" - -from eva.models import networks -from eva.models.modules import HeadModule, InferenceModule - -__all__ = ["networks", "HeadModule", "InferenceModule"] diff --git a/src/eva/models/modules/__init__.py b/src/eva/models/modules/__init__.py deleted file mode 100644 index 1a80ea55..00000000 --- a/src/eva/models/modules/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Model Modules API.""" - -from eva.models.modules.head import HeadModule -from eva.models.modules.inference import InferenceModule -from eva.models.modules.module import ModelModule - -__all__ = ["HeadModule", "ModelModule", "InferenceModule"] diff --git a/src/eva/models/modules/utils/__init__.py b/src/eva/models/modules/utils/__init__.py deleted file mode 100644 index 4b48ce0d..00000000 --- a/src/eva/models/modules/utils/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -"""Utilities and helper functionalities for model modules.""" - -from eva.models.modules.utils import grad -from eva.models.modules.utils.batch_postprocess import BatchPostProcess - -__all__ = ["grad", "BatchPostProcess"] diff --git a/src/eva/models/networks/__init__.py b/src/eva/models/networks/__init__.py deleted file mode 100644 index a8f8c092..00000000 --- a/src/eva/models/networks/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -"""Networks API.""" - -from eva.models.networks import transforms, wrappers -from eva.models.networks.mlp import MLP - -__all__ = ["transforms", "wrappers", "MLP"] diff --git a/src/eva/models/networks/transforms/__init__.py b/src/eva/models/networks/transforms/__init__.py deleted file mode 100644 index 50885f56..00000000 --- a/src/eva/models/networks/transforms/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Model outputs transforms API.""" - -from eva.models.networks.transforms.extract_cls_features import ExtractCLSFeatures - -__all__ = ["ExtractCLSFeatures"] diff --git a/src/eva/models/networks/wrappers/__init__.py b/src/eva/models/networks/wrappers/__init__.py deleted file mode 100644 index 5b2e5509..00000000 --- a/src/eva/models/networks/wrappers/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -"""Model Wrappers API.""" - -from eva.models.networks.wrappers.base import BaseModel -from eva.models.networks.wrappers.from_function import ModelFromFunction -from eva.models.networks.wrappers.huggingface import HuggingFaceModel -from eva.models.networks.wrappers.onnx import ONNXModel - -__all__ = ["BaseModel", "ModelFromFunction", "HuggingFaceModel", "ONNXModel"] diff --git a/src/eva/trainers/__init__.py b/src/eva/trainers/__init__.py deleted file mode 100644 index 302fa06d..00000000 --- a/src/eva/trainers/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -"""Trainers API.""" - -from eva.trainers.functional import infer_model, run_evaluation_session -from eva.trainers.trainer import Trainer - -__all__ = ["infer_model", "run_evaluation_session", "Trainer"] diff --git a/src/eva/vision/data/datasets/vision.py b/src/eva/vision/data/datasets/vision.py index f2cb736b..81b08f57 100644 --- a/src/eva/vision/data/datasets/vision.py +++ b/src/eva/vision/data/datasets/vision.py @@ -3,7 +3,7 @@ import abc from typing import Generic, TypeVar -from eva.data.datasets import base +from eva.core.data.datasets import base DataSample = TypeVar("DataSample") """The data sample type.""" diff --git a/src/eva/vision/data/transforms/__init__.py b/src/eva/vision/data/transforms/__init__.py index 8ba10985..4e89dfa3 100644 --- a/src/eva/vision/data/transforms/__init__.py +++ b/src/eva/vision/data/transforms/__init__.py @@ -1,5 +1,5 @@ """Vision data transforms.""" -from eva.vision.data.transforms.common import ArrayToFloatTensor, ArrayToTensor, ResizeAndCrop +from eva.vision.data.transforms.common import ResizeAndCrop -__all__ = ["ArrayToTensor", "ResizeAndCrop", "ArrayToFloatTensor"] +__all__ = ["ResizeAndCrop"] diff --git a/src/eva/vision/data/transforms/common/__init__.py b/src/eva/vision/data/transforms/common/__init__.py index d7eafaa1..b1a13ac5 100644 --- a/src/eva/vision/data/transforms/common/__init__.py +++ b/src/eva/vision/data/transforms/common/__init__.py @@ -1,6 +1,5 @@ """Common vision transforms.""" -from eva.vision.data.transforms.common.array_to_tensor import ArrayToFloatTensor, ArrayToTensor from eva.vision.data.transforms.common.resize_and_crop import ResizeAndCrop -__all__ = ["ResizeAndCrop", "ArrayToTensor", "ArrayToFloatTensor"] +__all__ = ["ResizeAndCrop"] diff --git a/src/eva/vision/models/networks/abmil.py b/src/eva/vision/models/networks/abmil.py index d9f1d483..bb2ca482 100644 --- a/src/eva/vision/models/networks/abmil.py +++ b/src/eva/vision/models/networks/abmil.py @@ -5,7 +5,7 @@ import torch import torch.nn as nn -from eva.models.networks import MLP +from eva.core.models.networks import MLP class ABMIL(torch.nn.Module): diff --git a/tests/eva/__init__.py b/tests/eva/__init__.py index 15a95149..8691dd9c 100644 --- a/tests/eva/__init__.py +++ b/tests/eva/__init__.py @@ -1 +1 @@ -"""EVA core tests.""" +"""eva core tests.""" diff --git a/tests/eva/callbacks/__init__.py b/tests/eva/core/callbacks/__init__.py similarity index 100% rename from tests/eva/callbacks/__init__.py rename to tests/eva/core/callbacks/__init__.py diff --git a/tests/eva/callbacks/writers/__init__.py b/tests/eva/core/callbacks/writers/__init__.py similarity index 100% rename from tests/eva/callbacks/writers/__init__.py rename to tests/eva/core/callbacks/writers/__init__.py diff --git a/tests/eva/callbacks/writers/test_embeddings.py b/tests/eva/core/callbacks/writers/test_embeddings.py similarity index 97% rename from tests/eva/callbacks/writers/test_embeddings.py rename to tests/eva/core/callbacks/writers/test_embeddings.py index 83efe4dc..3990f453 100644 --- a/tests/eva/callbacks/writers/test_embeddings.py +++ b/tests/eva/core/callbacks/writers/test_embeddings.py @@ -14,9 +14,9 @@ from torch import nn from typing_extensions import override -from eva.callbacks import writers -from eva.data import dataloaders, datamodules, datasets -from eva.models import modules +from eva.core.callbacks import writers +from eva.core.data import dataloaders, datamodules, datasets +from eva.core.models import modules @pytest.mark.parametrize("batch_size, n_samples", list(itertools.product([5, 8], [7, 16]))) diff --git a/tests/eva/data/__init__.py b/tests/eva/core/data/__init__.py similarity index 100% rename from tests/eva/data/__init__.py rename to tests/eva/core/data/__init__.py diff --git a/tests/eva/data/dataloaders/__init__.py b/tests/eva/core/data/dataloaders/__init__.py similarity index 100% rename from tests/eva/data/dataloaders/__init__.py rename to tests/eva/core/data/dataloaders/__init__.py diff --git a/tests/eva/data/dataloaders/test_dataloader.py b/tests/eva/core/data/dataloaders/test_dataloader.py similarity index 96% rename from tests/eva/data/dataloaders/test_dataloader.py rename to tests/eva/core/data/dataloaders/test_dataloader.py index eb2e6d3b..12c3dd05 100644 --- a/tests/eva/data/dataloaders/test_dataloader.py +++ b/tests/eva/core/data/dataloaders/test_dataloader.py @@ -4,7 +4,7 @@ from torch.utils import data as torch_data from typing_extensions import override -from eva.data import dataloaders, datasets +from eva.core.data import dataloaders, datasets @pytest.mark.parametrize( diff --git a/tests/eva/data/datamodules/__init__.py b/tests/eva/core/data/datamodules/__init__.py similarity index 100% rename from tests/eva/data/datamodules/__init__.py rename to tests/eva/core/data/datamodules/__init__.py diff --git a/tests/eva/data/datamodules/_utils.py b/tests/eva/core/data/datamodules/_utils.py similarity index 94% rename from tests/eva/data/datamodules/_utils.py rename to tests/eva/core/data/datamodules/_utils.py index 6fede5a0..5fee9a50 100644 --- a/tests/eva/data/datamodules/_utils.py +++ b/tests/eva/core/data/datamodules/_utils.py @@ -2,7 +2,7 @@ from typing_extensions import override -from eva.data import datasets as datasets_lib +from eva.core.data import datasets as datasets_lib class DummyDataset(datasets_lib.Dataset): diff --git a/tests/eva/data/datamodules/test_datamodule.py b/tests/eva/core/data/datamodules/test_datamodule.py similarity index 94% rename from tests/eva/data/datamodules/test_datamodule.py rename to tests/eva/core/data/datamodules/test_datamodule.py index 36408725..da915be9 100644 --- a/tests/eva/data/datamodules/test_datamodule.py +++ b/tests/eva/core/data/datamodules/test_datamodule.py @@ -5,9 +5,9 @@ import pytest from torch.utils import data as torch_data -from eva.data import dataloaders, datamodules, datasets -from eva.data.datamodules import schemas -from tests.eva.data.datamodules import _utils +from eva.core.data import dataloaders, datamodules, datasets +from eva.core.data.datamodules import schemas +from tests.eva.core.data.datamodules import _utils def test_datamodule_methods(datamodule: datamodules.DataModule) -> None: diff --git a/tests/eva/data/datamodules/test_schemas.py b/tests/eva/core/data/datamodules/test_schemas.py similarity index 95% rename from tests/eva/data/datamodules/test_schemas.py rename to tests/eva/core/data/datamodules/test_schemas.py index bda0353a..188c9a62 100644 --- a/tests/eva/data/datamodules/test_schemas.py +++ b/tests/eva/core/data/datamodules/test_schemas.py @@ -2,7 +2,7 @@ import pytest -from eva.data.datamodules import schemas +from eva.core.data.datamodules import schemas def test_datasets_schema(dataset_schema: schemas.DatasetsSchema) -> None: diff --git a/tests/eva/data/datasets/__init__.py b/tests/eva/core/data/datasets/__init__.py similarity index 100% rename from tests/eva/data/datasets/__init__.py rename to tests/eva/core/data/datasets/__init__.py diff --git a/tests/eva/data/datasets/classification/__init__.py b/tests/eva/core/data/datasets/classification/__init__.py similarity index 100% rename from tests/eva/data/datasets/classification/__init__.py rename to tests/eva/core/data/datasets/classification/__init__.py diff --git a/tests/eva/data/datasets/classification/test_embedding_datasets.py b/tests/eva/core/data/datasets/classification/test_embedding_datasets.py similarity index 68% rename from tests/eva/data/datasets/classification/test_embedding_datasets.py rename to tests/eva/core/data/datasets/classification/test_embedding_datasets.py index 84132960..040c439a 100644 --- a/tests/eva/data/datasets/classification/test_embedding_datasets.py +++ b/tests/eva/core/data/datasets/classification/test_embedding_datasets.py @@ -7,7 +7,7 @@ import pytest import torch -from eva.data.datasets import classification +from eva.core.data.datasets import classification @pytest.mark.parametrize( @@ -15,10 +15,10 @@ [("train", (8,)), ("val", (8,))], ) def test_patch_embedding_dataset( - patch_embeddings_dataset: classification.EmbeddingsDataset, + patch_embeddings_dataset: classification.EmbeddingsClassificationDataset, embeddings_shape: Tuple[int, ...], ): - """Test that the EmbeddingsDataset level dataset.""" + """Test that the EmbeddingsClassificationDataset level dataset.""" # assert data sample is a tuple sample = patch_embeddings_dataset[0] assert isinstance(sample, tuple) @@ -32,9 +32,11 @@ def test_patch_embedding_dataset( @pytest.fixture(scope="function") -def patch_embeddings_dataset(split: str, assets_path: str) -> classification.EmbeddingsDataset: - """EmbeddingsDataset dataset fixture.""" - dataset = classification.EmbeddingsDataset( +def patch_embeddings_dataset( + split: str, assets_path: str +) -> classification.EmbeddingsClassificationDataset: + """EmbeddingsClassificationDataset dataset fixture.""" + dataset = classification.EmbeddingsClassificationDataset( root=os.path.join(assets_path, "core", "datasets", "embeddings"), manifest_file="manifest.csv", split=split, diff --git a/tests/eva/metrics/__init__.py b/tests/eva/core/metrics/__init__.py similarity index 100% rename from tests/eva/metrics/__init__.py rename to tests/eva/core/metrics/__init__.py diff --git a/tests/eva/metrics/core/__init__.py b/tests/eva/core/metrics/core/__init__.py similarity index 100% rename from tests/eva/metrics/core/__init__.py rename to tests/eva/core/metrics/core/__init__.py diff --git a/tests/eva/metrics/core/test_metric_module.py b/tests/eva/core/metrics/core/test_metric_module.py similarity index 54% rename from tests/eva/metrics/core/test_metric_module.py rename to tests/eva/core/metrics/core/test_metric_module.py index 0218ec69..faccf285 100644 --- a/tests/eva/metrics/core/test_metric_module.py +++ b/tests/eva/core/metrics/core/test_metric_module.py @@ -5,19 +5,22 @@ import pytest import torchmetrics -from eva.metrics import core +from eva.core.metrics import structs @pytest.mark.parametrize( "schema, expected", [ - (core.MetricsSchema(train=torchmetrics.Dice()), [1, 0, 0]), - (core.MetricsSchema(evaluation=torchmetrics.Dice()), [0, 1, 1]), - (core.MetricsSchema(common=torchmetrics.Dice()), [1, 1, 1]), - (core.MetricsSchema(train=torchmetrics.Dice(), evaluation=torchmetrics.Dice()), [1, 1, 1]), + (structs.MetricsSchema(train=torchmetrics.Dice()), [1, 0, 0]), + (structs.MetricsSchema(evaluation=torchmetrics.Dice()), [0, 1, 1]), + (structs.MetricsSchema(common=torchmetrics.Dice()), [1, 1, 1]), + ( + structs.MetricsSchema(train=torchmetrics.Dice(), evaluation=torchmetrics.Dice()), + [1, 1, 1], + ), ], ) -def test_metric_module(metric_module: core.MetricModule, expected: List[int]) -> None: +def test_metric_module(metric_module: structs.MetricModule, expected: List[int]) -> None: """Tests the MetricModule.""" assert len(metric_module.training_metrics) == expected[0] assert len(metric_module.validation_metrics) == expected[1] @@ -29,6 +32,6 @@ def test_metric_module(metric_module: core.MetricModule, expected: List[int]) -> @pytest.fixture(scope="function") -def metric_module(schema: core.MetricsSchema) -> core.MetricModule: +def metric_module(schema: structs.MetricsSchema) -> structs.MetricModule: """MetricModule fixture.""" - return core.MetricModule.from_schema(schema=schema) + return structs.MetricModule.from_schema(schema=schema) diff --git a/tests/eva/metrics/core/test_schemas.py b/tests/eva/core/metrics/core/test_schemas.py similarity index 89% rename from tests/eva/metrics/core/test_schemas.py rename to tests/eva/core/metrics/core/test_schemas.py index d42b42db..29d0c2a8 100644 --- a/tests/eva/metrics/core/test_schemas.py +++ b/tests/eva/core/metrics/core/test_schemas.py @@ -3,8 +3,8 @@ import pytest import torchmetrics -from eva.metrics import core -from eva.metrics.core.typings import MetricModuleType +from eva.core.metrics import structs +from eva.core.metrics.structs.typings import MetricModuleType @pytest.mark.parametrize( @@ -55,7 +55,7 @@ ], ) def test_metric_schema( - metric_schema: core.MetricsSchema, + metric_schema: structs.MetricsSchema, expected_train: str, expected_evaluation: str, ): @@ -69,9 +69,9 @@ def metric_schema( common: MetricModuleType | None, train: MetricModuleType | None, evaluation: MetricModuleType | None, -) -> core.MetricsSchema: +) -> structs.MetricsSchema: """MetricsSchema fixture.""" - return core.MetricsSchema( + return structs.MetricsSchema( common=common, train=train, evaluation=evaluation, diff --git a/tests/eva/metrics/defaults/__init__.py b/tests/eva/core/metrics/defaults/__init__.py similarity index 100% rename from tests/eva/metrics/defaults/__init__.py rename to tests/eva/core/metrics/defaults/__init__.py diff --git a/tests/eva/metrics/defaults/classification/__init__.py b/tests/eva/core/metrics/defaults/classification/__init__.py similarity index 100% rename from tests/eva/metrics/defaults/classification/__init__.py rename to tests/eva/core/metrics/defaults/classification/__init__.py diff --git a/tests/eva/metrics/defaults/classification/test_binary.py b/tests/eva/core/metrics/defaults/classification/test_binary.py similarity index 97% rename from tests/eva/metrics/defaults/classification/test_binary.py rename to tests/eva/core/metrics/defaults/classification/test_binary.py index 323566eb..01aea2e1 100644 --- a/tests/eva/metrics/defaults/classification/test_binary.py +++ b/tests/eva/core/metrics/defaults/classification/test_binary.py @@ -3,7 +3,7 @@ import pytest import torch -from eva.metrics import defaults +from eva.core.metrics import defaults PREDS_ONE = torch.tensor([0.70, 0.05, 0.99, 0.10, 0.3]) TARGET_ONE = torch.tensor([0, 1, 1, 0, 1]) diff --git a/tests/eva/metrics/defaults/classification/test_multiclass.py b/tests/eva/core/metrics/defaults/classification/test_multiclass.py similarity index 97% rename from tests/eva/metrics/defaults/classification/test_multiclass.py rename to tests/eva/core/metrics/defaults/classification/test_multiclass.py index 05bfb5ea..0e091293 100644 --- a/tests/eva/metrics/defaults/classification/test_multiclass.py +++ b/tests/eva/core/metrics/defaults/classification/test_multiclass.py @@ -3,7 +3,7 @@ import pytest import torch -from eva.metrics import defaults +from eva.core.metrics import defaults NUM_CLASSES_ONE = 5 PREDS_ONE = torch.tensor( diff --git a/tests/eva/metrics/test_average_loss.py b/tests/eva/core/metrics/test_average_loss.py similarity index 97% rename from tests/eva/metrics/test_average_loss.py rename to tests/eva/core/metrics/test_average_loss.py index 12a329be..beae131e 100644 --- a/tests/eva/metrics/test_average_loss.py +++ b/tests/eva/core/metrics/test_average_loss.py @@ -3,7 +3,7 @@ import pytest import torch -from eva import metrics +from eva.core import metrics BATCH_ONE, BATCH_TWO = [ torch.tensor( diff --git a/tests/eva/metrics/test_binary_balanced_accuracy.py b/tests/eva/core/metrics/test_binary_balanced_accuracy.py similarity index 98% rename from tests/eva/metrics/test_binary_balanced_accuracy.py rename to tests/eva/core/metrics/test_binary_balanced_accuracy.py index c3a1c146..43bc4af4 100644 --- a/tests/eva/metrics/test_binary_balanced_accuracy.py +++ b/tests/eva/core/metrics/test_binary_balanced_accuracy.py @@ -3,7 +3,7 @@ import pytest import torch -from eva import metrics +from eva.core import metrics PREDS_ONE = torch.tensor([[0.70, 0.95, 0.19, 0.10, 0.59]]) TARGET_ONE = torch.tensor([[1, 1, 0, 0, 0]]) diff --git a/tests/eva/models/__init__.py b/tests/eva/core/models/__init__.py similarity index 100% rename from tests/eva/models/__init__.py rename to tests/eva/core/models/__init__.py diff --git a/tests/eva/models/modules/__init__.py b/tests/eva/core/models/modules/__init__.py similarity index 100% rename from tests/eva/models/modules/__init__.py rename to tests/eva/core/models/modules/__init__.py diff --git a/tests/eva/models/modules/conftest.py b/tests/eva/core/models/modules/conftest.py similarity index 95% rename from tests/eva/models/modules/conftest.py rename to tests/eva/core/models/modules/conftest.py index d7cb665f..fbcff042 100644 --- a/tests/eva/models/modules/conftest.py +++ b/tests/eva/core/models/modules/conftest.py @@ -6,8 +6,8 @@ import torch from torch.utils import data as torch_data -from eva.data import dataloaders, datamodules, datasets -from eva.trainers import trainer as eva_trainer +from eva.core.data import dataloaders, datamodules, datasets +from eva.core.trainers import trainer as eva_trainer @pytest.fixture(scope="function") diff --git a/tests/eva/models/modules/test_head.py b/tests/eva/core/models/modules/test_head.py similarity index 91% rename from tests/eva/models/modules/test_head.py rename to tests/eva/core/models/modules/test_head.py index d14891f0..b3b0bc35 100644 --- a/tests/eva/models/modules/test_head.py +++ b/tests/eva/core/models/modules/test_head.py @@ -7,9 +7,9 @@ import torch from torch import nn -from eva import metrics, trainers -from eva.data import datamodules -from eva.models import modules +from eva.core import metrics, trainers +from eva.core.data import datamodules +from eva.core.models import modules @pytest.mark.parametrize( diff --git a/tests/eva/models/modules/test_inference.py b/tests/eva/core/models/modules/test_inference.py similarity index 91% rename from tests/eva/models/modules/test_inference.py rename to tests/eva/core/models/modules/test_inference.py index 42fe7719..b17f6202 100644 --- a/tests/eva/models/modules/test_inference.py +++ b/tests/eva/core/models/modules/test_inference.py @@ -7,9 +7,9 @@ import torch from torch import nn -from eva.data import datamodules -from eva.models import modules -from eva.trainers import trainer as eva_trainer +from eva.core.data import datamodules +from eva.core.models import modules +from eva.core.trainers import trainer as eva_trainer N_CLASSES = 4 """The number of classes in the dataset.""" diff --git a/tests/eva/models/modules/utils/__init__.py b/tests/eva/core/models/modules/utils/__init__.py similarity index 100% rename from tests/eva/models/modules/utils/__init__.py rename to tests/eva/core/models/modules/utils/__init__.py diff --git a/tests/eva/models/modules/utils/test_batch_postproces.py b/tests/eva/core/models/modules/utils/test_batch_postproces.py similarity index 96% rename from tests/eva/models/modules/utils/test_batch_postproces.py rename to tests/eva/core/models/modules/utils/test_batch_postproces.py index 8aefaa4e..25f3d71b 100644 --- a/tests/eva/models/modules/utils/test_batch_postproces.py +++ b/tests/eva/core/models/modules/utils/test_batch_postproces.py @@ -6,7 +6,7 @@ import torch from torch import nn -from eva.models.modules.utils import batch_postprocess +from eva.core.models.modules.utils import batch_postprocess BATCH_OUTPUTS_1 = { "predictions": torch.Tensor([1.5, -0.3]), diff --git a/tests/eva/models/networks/__init__.py b/tests/eva/core/models/networks/__init__.py similarity index 100% rename from tests/eva/models/networks/__init__.py rename to tests/eva/core/models/networks/__init__.py diff --git a/tests/eva/models/networks/test_mlp.py b/tests/eva/core/models/networks/test_mlp.py similarity index 97% rename from tests/eva/models/networks/test_mlp.py rename to tests/eva/core/models/networks/test_mlp.py index 469a3cfd..a4a19831 100644 --- a/tests/eva/models/networks/test_mlp.py +++ b/tests/eva/core/models/networks/test_mlp.py @@ -6,7 +6,7 @@ import pytest import torch -from eva.models.networks import MLP +from eva.core.models.networks import MLP @pytest.mark.parametrize( diff --git a/tests/eva/models/networks/wrappers/__init__.py b/tests/eva/core/models/networks/wrappers/__init__.py similarity index 100% rename from tests/eva/models/networks/wrappers/__init__.py rename to tests/eva/core/models/networks/wrappers/__init__.py diff --git a/tests/eva/models/networks/wrappers/test_from_function.py b/tests/eva/core/models/networks/wrappers/test_from_function.py similarity index 96% rename from tests/eva/models/networks/wrappers/test_from_function.py rename to tests/eva/core/models/networks/wrappers/test_from_function.py index b1f0cb3a..d94c095b 100644 --- a/tests/eva/models/networks/wrappers/test_from_function.py +++ b/tests/eva/core/models/networks/wrappers/test_from_function.py @@ -6,7 +6,7 @@ import torch from torch import nn -from eva.models.networks import wrappers +from eva.core.models.networks import wrappers @pytest.mark.parametrize( diff --git a/tests/eva/models/networks/wrappers/test_huggingface.py b/tests/eva/core/models/networks/wrappers/test_huggingface.py similarity index 94% rename from tests/eva/models/networks/wrappers/test_huggingface.py rename to tests/eva/core/models/networks/wrappers/test_huggingface.py index a9e97d47..84e0e4fa 100644 --- a/tests/eva/models/networks/wrappers/test_huggingface.py +++ b/tests/eva/core/models/networks/wrappers/test_huggingface.py @@ -6,7 +6,7 @@ import torch from transformers import modeling_outputs -from eva.models.networks import transforms, wrappers +from eva.core.models.networks import transforms, wrappers @pytest.mark.parametrize( diff --git a/tests/eva/models/networks/wrappers/test_onnx.py b/tests/eva/core/models/networks/wrappers/test_onnx.py similarity index 96% rename from tests/eva/models/networks/wrappers/test_onnx.py rename to tests/eva/core/models/networks/wrappers/test_onnx.py index 656daad0..cfcdaaab 100644 --- a/tests/eva/models/networks/wrappers/test_onnx.py +++ b/tests/eva/core/models/networks/wrappers/test_onnx.py @@ -8,7 +8,7 @@ import torch from pytorch_lightning.demos import boring_classes -from eva.models.networks import wrappers +from eva.core.models.networks import wrappers @pytest.mark.parametrize( diff --git a/tests/eva/test_cli.py b/tests/eva/core/test_cli.py similarity index 100% rename from tests/eva/test_cli.py rename to tests/eva/core/test_cli.py diff --git a/tests/eva/trainers/__init__.py b/tests/eva/core/trainers/__init__.py similarity index 100% rename from tests/eva/trainers/__init__.py rename to tests/eva/core/trainers/__init__.py diff --git a/tests/eva/trainers/test_recorder.py b/tests/eva/core/trainers/test_recorder.py similarity index 99% rename from tests/eva/trainers/test_recorder.py rename to tests/eva/core/trainers/test_recorder.py index ce38e771..6e3f30e3 100644 --- a/tests/eva/trainers/test_recorder.py +++ b/tests/eva/core/trainers/test_recorder.py @@ -7,7 +7,7 @@ import pytest from pytorch_lightning.utilities.types import _EVALUATE_OUTPUT -from eva.trainers import _recorder +from eva.core.trainers import _recorder _RELATIVE_TOLERANCE = 1e-3 """The test relative tolerance.""" diff --git a/tests/eva/vision/test_vision_cli.py b/tests/eva/vision/test_vision_cli.py index d39b604c..a1c69963 100644 --- a/tests/eva/vision/test_vision_cli.py +++ b/tests/eva/vision/test_vision_cli.py @@ -1,4 +1,4 @@ -"""Tests regarding the EVA `fit` CLI command on vision datasets.""" +"""Tests regarding eva's CLI commands on vision datasets.""" import os import tempfile @@ -10,6 +10,35 @@ from tests.eva import _cli +@pytest.mark.parametrize( + "configuration_file", + [ + "configs/vision/dino_vit/online/bach.yaml", + "configs/vision/dino_vit/online/crc.yaml", + "configs/vision/dino_vit/online/mhist.yaml", + "configs/vision/dino_vit/online/patch_camelyon.yaml", + "configs/vision/dino_vit/offline/bach.yaml", + "configs/vision/dino_vit/offline/crc.yaml", + "configs/vision/dino_vit/offline/mhist.yaml", + "configs/vision/dino_vit/offline/patch_camelyon.yaml", + "configs/vision/owkin/phikon/offline/bach.yaml", + "configs/vision/owkin/phikon/offline/crc.yaml", + "configs/vision/owkin/phikon/offline/mhist.yaml", + "configs/vision/owkin/phikon/offline/patch_camelyon.yaml", + ], +) +def test_configuration_initialization(configuration_file: str, lib_path: str) -> None: + """Tests that a given configuration file can be initialized.""" + _cli.run_cli_from_main( + cli_args=[ + "fit", + "--config", + os.path.join(lib_path, configuration_file), + "--print_config", + ] + ) + + @pytest.mark.parametrize( "configuration_file", [