Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename tool and update README #63

Merged
merged 6 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 59 additions & 60 deletions README.md

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions clip_eval/dataset/types/__init__.py

This file was deleted.

3 changes: 0 additions & 3 deletions clip_eval/model/types/__init__.py

This file was deleted.

Binary file added images/embeddings.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/eval-usage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/logo_v1.webp
Binary file not shown.
Binary file added images/tti-eval-banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ requires = ["poetry-core"]

[tool.poetry]
authors = ["Cord Technologies Limited <[email protected]>"]
description = "Working with multiple CLIP models"
name = "clip-eval"
description = "Evaluating text-to-image and image-to-text retrieval models."
name = "tti-eval"
readme = "README.md"
version = "0.1.0"
packages = [{include = "clip_eval", from = "."}]
packages = [{include = "tti_eval", from = "."}]

[tool.poetry.dependencies]
autofaiss = "^2.17.0"
Expand Down Expand Up @@ -41,7 +41,7 @@ ipdb = "^0.13.13"
pytest = "^8.1.1"

[tool.poetry.scripts]
clip-eval = "clip_eval.cli.main:cli"
tti-eval = "tti_eval.cli.main:cli"

[tool.ruff]
line-length = 120
Expand Down
2 changes: 1 addition & 1 deletion sources/dataset-definition-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"type": "string"
},
"module_path": {
"default": "../../clip_eval/dataset/types/__init__.py",
"default": "../../tti_eval/dataset/types/__init__.py",
"format": "path",
"title": "Module Path",
"type": "string"
Expand Down
2 changes: 1 addition & 1 deletion sources/model-definition-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "string"
},
"module_path": {
"default": "../../clip_eval/model/types/__init__.py",
"default": "../../tti_eval/model/types/__init__.py",
"format": "path",
"title": "Module Path",
"type": "string"
Expand Down
4 changes: 2 additions & 2 deletions tests/common/test_embedding_definition.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

from clip_eval.common import EmbeddingDefinition, Embeddings, Split
from clip_eval.compute import compute_embeddings_from_definition
from tti_eval.common import EmbeddingDefinition, Embeddings, Split
from tti_eval.compute import compute_embeddings_from_definition

if __name__ == "__main__":
def_ = EmbeddingDefinition(
Expand Down
6 changes: 3 additions & 3 deletions tests/evaluation/test_knn.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np

from clip_eval.common import ClassArray, Embeddings, ProbabilityArray
from clip_eval.evaluation.knn import WeightedKNNClassifier
from clip_eval.evaluation.utils import normalize, softmax
from tti_eval.common import ClassArray, Embeddings, ProbabilityArray
from tti_eval.evaluation.knn import WeightedKNNClassifier
from tti_eval.evaluation.utils import normalize, softmax


def slow_knn_predict(
Expand Down
File renamed without changes.
18 changes: 9 additions & 9 deletions clip_eval/cli/main.py → tti_eval/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import matplotlib.pyplot as plt
from typer import Option, Typer

from clip_eval.common import Split
from clip_eval.compute import compute_embeddings_from_definition
from clip_eval.utils import read_all_cached_embeddings
from tti_eval.common import Split
from tti_eval.compute import compute_embeddings_from_definition
from tti_eval.utils import read_all_cached_embeddings

from .utils import (
parse_raw_embedding_definitions,
select_existing_embedding_definitions,
select_from_all_embedding_definitions,
)

cli = Typer(name="clip-eval", no_args_is_help=True, rich_markup_mode="markdown")
cli = Typer(name="tti-eval", no_args_is_help=True, rich_markup_mode="markdown")


@cli.command(
Expand Down Expand Up @@ -84,13 +84,13 @@ def evaluate_embeddings(
all_: Annotated[bool, Option("--all", "-a", help="Evaluate all models.")] = False,
save: Annotated[bool, Option("--save", "-s", help="Save evaluation results to a CSV file.")] = False,
):
from clip_eval.evaluation import (
from tti_eval.evaluation import (
I2IRetrievalEvaluator,
LinearProbeClassifier,
WeightedKNNClassifier,
ZeroShotClassifier,
)
from clip_eval.evaluation.evaluator import export_evaluation_to_csv, run_evaluation
from tti_eval.evaluation.evaluator import export_evaluation_to_csv, run_evaluation

model_datasets = model_datasets or []

Expand All @@ -117,7 +117,7 @@ def animate_embeddings(
interactive: Annotated[bool, Option(help="Interactive plot instead of animation.")] = False,
reduction: Annotated[str, Option(help="Reduction type [pca, tsne, umap (default)].")] = "umap",
):
from clip_eval.plotting.animation import build_animation, save_animation_to_file
from tti_eval.plotting.animation import build_animation, save_animation_to_file

defs = select_existing_embedding_definitions(by_dataset=True, count=2)
res = build_animation(defs[0], defs[1], interactive=interactive, reduction=reduction)
Expand All @@ -135,8 +135,8 @@ def list_models_datasets(
Option("--all", "-a", help="List all models and datasets that are available via the tool."),
] = False,
):
from clip_eval.dataset import DatasetProvider
from clip_eval.model import ModelProvider
from tti_eval.dataset import DatasetProvider
from tti_eval.model import ModelProvider

if all_:
datasets = DatasetProvider.list_dataset_titles()
Expand Down
8 changes: 4 additions & 4 deletions clip_eval/cli/utils.py → tti_eval/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from InquirerPy.base.control import Choice
from natsort import natsorted, ns

from clip_eval.common import EmbeddingDefinition
from clip_eval.dataset import DatasetProvider
from clip_eval.model import ModelProvider
from clip_eval.utils import read_all_cached_embeddings
from tti_eval.common import EmbeddingDefinition
from tti_eval.dataset import DatasetProvider
from tti_eval.model import ModelProvider
from tti_eval.utils import read_all_cached_embeddings


@overload
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion clip_eval/common/base.py → tti_eval/common/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pydantic import BaseModel, model_validator
from pydantic.functional_validators import AfterValidator

from clip_eval.constants import NPZ_KEYS, PROJECT_PATHS
from tti_eval.constants import NPZ_KEYS, PROJECT_PATHS

from .numpy_types import ClassArray, EmbeddingArray
from .string_utils import safe_str
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions clip_eval/compute.py → tti_eval/compute.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from torch.utils.data import DataLoader

from clip_eval.common import EmbeddingDefinition, Embeddings, Split
from clip_eval.dataset import Dataset, DatasetProvider
from clip_eval.model import Model, ModelProvider
from tti_eval.common import EmbeddingDefinition, Embeddings, Split
from tti_eval.dataset import Dataset, DatasetProvider
from tti_eval.model import Model, ModelProvider


def compute_embeddings(model: Model, dataset: Dataset, batch_size: int = 50) -> Embeddings:
Expand Down
10 changes: 6 additions & 4 deletions clip_eval/constants.py → tti_eval/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
load_dotenv()

# If the cache directory is not explicitly specified, use the `.cache` directory located in the project's root.
_CLIP_EVAL_ROOT_DIR = Path(__file__).parent.parent
CACHE_PATH = Path(os.environ.get("CLIP_EVAL_CACHE_PATH", _CLIP_EVAL_ROOT_DIR / ".cache"))
_OUTPUT_PATH = Path(os.environ.get("CLIP_EVAL_OUTPUT_PATH", _CLIP_EVAL_ROOT_DIR / "output"))
_SOURCES_PATH = _CLIP_EVAL_ROOT_DIR / "sources"
_TTI_EVAL_ROOT_DIR = Path(__file__).parent.parent
CACHE_PATH = Path(os.environ.get("TTI_EVAL_CACHE_PATH", _TTI_EVAL_ROOT_DIR / ".cache"))
_OUTPUT_PATH = Path(
os.environ.get("TTI_EVAL_OUTPUT_PATH", _TTI_EVAL_ROOT_DIR / "output")
)
_SOURCES_PATH = _TTI_EVAL_ROOT_DIR / "sources"


class PROJECT_PATHS:
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions clip_eval/dataset/base.py → tti_eval/dataset/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from pydantic import BaseModel, ConfigDict
from torch.utils.data import Dataset as TorchDataset

from clip_eval.common import Split
from clip_eval.constants import CACHE_PATH, SOURCES_PATH
from tti_eval.common import Split
from tti_eval.constants import CACHE_PATH, SOURCES_PATH

DEFAULT_DATASET_TYPES_LOCATION = (
Path(relpath(str(__file__), SOURCES_PATH.DATASET_INSTANCE_DEFINITIONS)).parent / "types" / "__init__.py"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from natsort import natsorted, ns

from clip_eval.constants import CACHE_PATH, SOURCES_PATH
from tti_eval.constants import CACHE_PATH, SOURCES_PATH

from .base import Dataset, DatasetDefinitionSpec, Split
from .utils import load_class_from_path
Expand Down
2 changes: 2 additions & 0 deletions tti_eval/dataset/types/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from tti_eval.dataset.types.encord_ds import EncordDataset
from tti_eval.dataset.types.hugging_face import HFDataset
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from PIL import Image as PILImage
from tqdm.auto import tqdm

from clip_eval.dataset import Dataset, Split
from clip_eval.dataset.utils import collect_async, download_file, simple_random_split
from tti_eval.dataset import Dataset, Split
from tti_eval.dataset.utils import collect_async, download_file, simple_random_split


class EncordDataset(Dataset):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datasets import ClassLabel, DatasetDict, Sequence, Value, load_dataset

from clip_eval.dataset import Dataset, Split
from tti_eval.dataset import Dataset, Split


class HFDataset(Dataset):
Expand Down
2 changes: 1 addition & 1 deletion clip_eval/dataset/utils.py → tti_eval/dataset/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import requests
from tqdm.auto import tqdm

from clip_eval.common import Split
from tti_eval.common import Split

T = TypeVar("T")
G = TypeVar("G")
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC, abstractmethod
from typing import Any

from clip_eval.common import ClassArray, Embeddings, ProbabilityArray
from tti_eval.common import ClassArray, Embeddings, ProbabilityArray

from .utils import normalize

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
from natsort import natsorted, ns
from tabulate import tabulate

from clip_eval.common import EmbeddingDefinition, Split
from clip_eval.constants import OUTPUT_PATH
from clip_eval.evaluation import (
from tti_eval.common import EmbeddingDefinition, Split
from tti_eval.constants import OUTPUT_PATH
from tti_eval.evaluation import (
EvaluationModel,
I2IRetrievalEvaluator,
LinearProbeClassifier,
WeightedKNNClassifier,
ZeroShotClassifier,
)
from clip_eval.utils import read_all_cached_embeddings
from tti_eval.utils import read_all_cached_embeddings


def print_evaluation_results(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
from autofaiss import build_index

from clip_eval.common import Embeddings
from tti_eval.common import Embeddings

from .base import EvaluationModel

Expand Down
2 changes: 1 addition & 1 deletion clip_eval/evaluation/knn.py → tti_eval/evaluation/knn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
from autofaiss import build_index

from clip_eval.common import ClassArray, Embeddings, ProbabilityArray
from tti_eval.common import ClassArray, Embeddings, ProbabilityArray

from .base import ClassificationModel
from .utils import softmax
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import numpy as np
from sklearn.linear_model import LogisticRegression, LogisticRegressionCV

from clip_eval.common import ClassArray, Embeddings, ProbabilityArray
from clip_eval.evaluation.base import ClassificationModel
from tti_eval.common import ClassArray, Embeddings, ProbabilityArray
from tti_eval.evaluation.base import ClassificationModel

logger = logging.getLogger("multiclips")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import numpy.typing as npt

from clip_eval.common.numpy_types import DType
from tti_eval.common.numpy_types import DType


def normalize(x: npt.NDArray[DType]) -> npt.NDArray[DType]:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np

from clip_eval.common import ClassArray, Embeddings, ProbabilityArray
from clip_eval.evaluation.base import ClassificationModel
from clip_eval.evaluation.utils import softmax
from tti_eval.common import ClassArray, Embeddings, ProbabilityArray
from tti_eval.evaluation.base import ClassificationModel
from tti_eval.evaluation.utils import softmax


class ZeroShotClassifier(ClassificationModel):
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions clip_eval/model/base.py → tti_eval/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from pydantic import BaseModel, ConfigDict
from torch.utils.data import DataLoader

from clip_eval.common.numpy_types import ClassArray, EmbeddingArray
from clip_eval.constants import CACHE_PATH, SOURCES_PATH
from tti_eval.common.numpy_types import ClassArray, EmbeddingArray
from tti_eval.constants import CACHE_PATH, SOURCES_PATH

DEFAULT_MODEL_TYPES_LOCATION = (
Path(relpath(str(__file__), SOURCES_PATH.MODEL_INSTANCE_DEFINITIONS)).parent / "types" / "__init__.py"
Expand Down
4 changes: 2 additions & 2 deletions clip_eval/model/provider.py → tti_eval/model/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from natsort import natsorted, ns

from clip_eval.constants import SOURCES_PATH
from clip_eval.dataset.utils import load_class_from_path
from tti_eval.constants import SOURCES_PATH
from tti_eval.dataset.utils import load_class_from_path

from .base import Model, ModelDefinitionSpec

Expand Down
3 changes: 3 additions & 0 deletions tti_eval/model/types/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from tti_eval.model.types.hugging_face_clip import ClosedCLIPModel
from tti_eval.model.types.local_clip_model import LocalCLIPModel
from tti_eval.model.types.open_clip_model import OpenCLIPModel
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from transformers import AutoProcessor as HF_AutoProcessor
from transformers import AutoTokenizer as HF_AutoTokenizer

from clip_eval.common import ClassArray, EmbeddingArray
from clip_eval.dataset import Dataset
from clip_eval.model import Model
from tti_eval.common import ClassArray, EmbeddingArray
from tti_eval.dataset import Dataset
from tti_eval.model import Model


class ClosedCLIPModel(Model):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from clip_eval.model.types.open_clip_model import OpenCLIPModel
from tti_eval.model.types.open_clip_model import OpenCLIPModel


class LocalCLIPModel(OpenCLIPModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from torch.utils.data import DataLoader
from tqdm import tqdm

from clip_eval.common import ClassArray, EmbeddingArray
from clip_eval.dataset import Dataset
from clip_eval.model import Model
from tti_eval.common import ClassArray, EmbeddingArray
from tti_eval.dataset import Dataset
from tti_eval.model import Model


class OpenCLIPModel(Model):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
from matplotlib.widgets import Slider
from PIL import Image

from clip_eval.common import EmbeddingDefinition
from clip_eval.common.base import SafeName
from clip_eval.common.numpy_types import ClassArray, N2Array
from clip_eval.constants import OUTPUT_PATH
from clip_eval.dataset import DatasetProvider, Split
from tti_eval.common import EmbeddingDefinition
from tti_eval.common.base import SafeName
from tti_eval.common.numpy_types import ClassArray, N2Array
from tti_eval.constants import OUTPUT_PATH
from tti_eval.dataset import DatasetProvider, Split

from .reduction import REDUCTIONS, reduction_from_string

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sklearn.decomposition import PCA
from sklearn.manifold import TSNE

from clip_eval.common import EmbeddingArray, EmbeddingDefinition, ReductionArray, Split
from tti_eval.common import EmbeddingArray, EmbeddingDefinition, ReductionArray, Split


class Reducer:
Expand Down
Loading
Loading