diff --git a/clip_eval/dataset/base.py b/clip_eval/dataset/base.py index 9275d6b..a0cd918 100644 --- a/clip_eval/dataset/base.py +++ b/clip_eval/dataset/base.py @@ -1,11 +1,16 @@ from abc import ABC, abstractmethod from enum import StrEnum, auto +from os.path import relpath from pathlib import Path from pydantic import BaseModel, ConfigDict from torch.utils.data import Dataset as TorchDataset -from clip_eval.constants import CACHE_PATH +from clip_eval.constants import CACHE_PATH, SOURCES_PATH + +DEFAULT_DATASET_TYPES_LOCATION = ( + Path(relpath(str(__file__), SOURCES_PATH.DATASET_INSTANCE_DEFINITIONS)).parent / "types" / "__init__.py" +) class Split(StrEnum): @@ -18,7 +23,7 @@ class Split(StrEnum): class DatasetDefinitionSpec(BaseModel): dataset_type: str title: str - module_path: Path = Path(__file__).parent / "types" / "__init__.py" + module_path: Path = DEFAULT_DATASET_TYPES_LOCATION split: Split | None = None title_in_source: str | None = None cache_dir: Path | None = None diff --git a/clip_eval/model/base.py b/clip_eval/model/base.py index b61d11a..2fc7e67 100644 --- a/clip_eval/model/base.py +++ b/clip_eval/model/base.py @@ -1,5 +1,6 @@ from abc import ABC, abstractmethod from collections.abc import Callable +from os.path import relpath from pathlib import Path from typing import Any @@ -8,13 +9,17 @@ from torch.utils.data import DataLoader from clip_eval.common.numpy_types import ClassArray, EmbeddingArray -from clip_eval.constants import CACHE_PATH +from clip_eval.constants import CACHE_PATH, SOURCES_PATH + +DEFAULT_MODEL_TYPES_LOCATION = ( + Path(relpath(str(__file__), SOURCES_PATH.MODEL_INSTANCE_DEFINITIONS)).parent / "types" / "__init__.py" +) class ModelDefinitionSpec(BaseModel): model_type: str title: str - module_path: Path = Path(__file__).parent / "types" / "__init__.py" + module_path: Path = DEFAULT_MODEL_TYPES_LOCATION device: str | None = None title_in_source: str | None = None cache_dir: Path | None = None diff --git a/sources/dataset-definition-schema.json b/sources/dataset-definition-schema.json index faa98c2..dcda309 100644 --- a/sources/dataset-definition-schema.json +++ b/sources/dataset-definition-schema.json @@ -17,22 +17,26 @@ "title": "Dataset Type", "type": "string" }, + "title": { + "title": "Title", + "type": "string" + }, "module_path": { + "default": "../../clip_eval/dataset/types/__init__.py", "format": "path", "title": "Module Path", "type": "string" }, - "title": { - "title": "Title", - "type": "string" - }, "split": { - "allOf": [ + "anyOf": [ { "$ref": "#/$defs/Split" + }, + { + "type": "null" } ], - "default": "all" + "default": null }, "title_in_source": { "anyOf": [ @@ -62,7 +66,6 @@ }, "required": [ "dataset_type", - "module_path", "title" ], "title": "DatasetDefinitionSpec", diff --git a/sources/model-definition-schema.json b/sources/model-definition-schema.json index 40aa14e..6d7abd4 100644 --- a/sources/model-definition-schema.json +++ b/sources/model-definition-schema.json @@ -5,15 +5,16 @@ "title": "Model Type", "type": "string" }, + "title": { + "title": "Title", + "type": "string" + }, "module_path": { + "default": "../../clip_eval/model/types/__init__.py", "format": "path", "title": "Module Path", "type": "string" }, - "title": { - "title": "Title", - "type": "string" - }, "device": { "anyOf": [ { @@ -54,7 +55,6 @@ }, "required": [ "model_type", - "module_path", "title" ], "title": "ModelDefinitionSpec",