Skip to content

Commit

Permalink
chore: update default types location and schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
eloy-encord committed Apr 16, 2024
1 parent b2503c8 commit 258eccc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
9 changes: 7 additions & 2 deletions clip_eval/dataset/base.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions clip_eval/model/base.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
17 changes: 10 additions & 7 deletions sources/dataset-definition-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -62,7 +66,6 @@
},
"required": [
"dataset_type",
"module_path",
"title"
],
"title": "DatasetDefinitionSpec",
Expand Down
10 changes: 5 additions & 5 deletions sources/model-definition-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down Expand Up @@ -54,7 +55,6 @@
},
"required": [
"model_type",
"module_path",
"title"
],
"title": "ModelDefinitionSpec",
Expand Down

0 comments on commit 258eccc

Please sign in to comment.