From ef21329f6e94adc889f4308dddd7500a29971507 Mon Sep 17 00:00:00 2001 From: Lorenz Linhardt Date: Tue, 18 Jun 2024 13:32:38 +0200 Subject: [PATCH 1/6] TimmExtractor default transformations are now loaded from timm --- thingsvision/core/extraction/extractors.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/thingsvision/core/extraction/extractors.py b/thingsvision/core/extraction/extractors.py index 5646125..a6a4468 100644 --- a/thingsvision/core/extraction/extractors.py +++ b/thingsvision/core/extraction/extractors.py @@ -141,6 +141,19 @@ def load_model_from_source(self) -> None: f"\nCould not find {self.model_name} in timm library.\nChoose a different model.\n" ) + def get_default_transformation( + self, + mean, + std, + resize_dim: int = 256, + crop_dim: int = 224, + apply_center_crop: bool = True, + ) -> Any: + data_config = timm.data.resolve_model_data_config(self.model) + transforms = timm.data.create_transform(**data_config, is_training=False) + + return transforms + class KerasExtractor(TensorFlowExtractor): def __init__( From 035da335195807417c86c0a12669c7717cec62ee Mon Sep 17 00:00:00 2001 From: Lorenz Linhardt Date: Tue, 18 Jun 2024 16:05:48 +0200 Subject: [PATCH 2/6] Update requirements.txt --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 50cb09d..f9bfb53 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ h5py keras-cv-attention-models>=1.3.5 matplotlib numba -numpy +numpy<=1.26.4 open_clip_torch==2.24.* pandas regex @@ -20,4 +20,4 @@ tqdm dreamsim==0.1.3 git+https://github.com/openai/CLIP.git git+https://github.com/serre-lab/Harmonization.git -transformers==4.40.1 \ No newline at end of file +transformers==4.40.1 From 03be38d987f722c2564292989bd5707c0df001f9 Mon Sep 17 00:00:00 2001 From: LukasMut Date: Tue, 18 Jun 2024 16:44:39 +0200 Subject: [PATCH 3/6] patch version update --- thingsvision/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thingsvision/_version.py b/thingsvision/_version.py index 492f7d9..763cefd 100644 --- a/thingsvision/_version.py +++ b/thingsvision/_version.py @@ -1 +1 @@ -__version__ = "2.6.7" +__version__ = "2.6.8" From 4e369f4d74f5b57b968e2865e6456137a6a72b8c Mon Sep 17 00:00:00 2001 From: LukasMut Date: Tue, 18 Jun 2024 16:54:23 +0200 Subject: [PATCH 4/6] added warning for not using input arguments in get transform method --- thingsvision/core/extraction/extractors.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/thingsvision/core/extraction/extractors.py b/thingsvision/core/extraction/extractors.py index a6a4468..f13eca3 100644 --- a/thingsvision/core/extraction/extractors.py +++ b/thingsvision/core/extraction/extractors.py @@ -1,13 +1,13 @@ import os +import warnings from typing import Any, Callable, Dict, List, Optional, Union import numpy as np -import timm -import torchvision - import tensorflow as tf import tensorflow.keras.applications as tensorflow_models +import timm import torch +import torchvision try: from torch.hub import load_state_dict_from_url @@ -149,9 +149,14 @@ def get_default_transformation( crop_dim: int = 224, apply_center_crop: bool = True, ) -> Any: + warnings.warn( + message="\nInput arguments are ignored because automatically infers transforms from model config.\n", + category=UserWarning, + stacklevel=2, + ) data_config = timm.data.resolve_model_data_config(self.model) transforms = timm.data.create_transform(**data_config, is_training=False) - + return transforms From 9c921fd56356bb5b0f9875f7767276a9b2f1e978 Mon Sep 17 00:00:00 2001 From: LukasMut Date: Tue, 18 Jun 2024 16:57:23 +0200 Subject: [PATCH 5/6] added warning for not using input arguments in get transform method --- thingsvision/core/extraction/extractors.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/thingsvision/core/extraction/extractors.py b/thingsvision/core/extraction/extractors.py index f13eca3..c013513 100644 --- a/thingsvision/core/extraction/extractors.py +++ b/thingsvision/core/extraction/extractors.py @@ -104,6 +104,11 @@ def get_default_transformation( apply_center_crop: bool = True, ) -> Any: if self.weights: + warnings.warn( + message="\nInput arguments are ignored because transforms are automatically infered transforms from model weights.\n", + category=UserWarning, + stacklevel=2, + ) transforms = self.weights.transforms() else: transforms = super().get_default_transformation( From 34e04c2e8b7f22ee88c0bd7f9684d256ed744d73 Mon Sep 17 00:00:00 2001 From: LukasMut Date: Tue, 18 Jun 2024 16:58:01 +0200 Subject: [PATCH 6/6] added warning for not using input arguments in get transform method --- thingsvision/core/extraction/extractors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thingsvision/core/extraction/extractors.py b/thingsvision/core/extraction/extractors.py index c013513..72d78ee 100644 --- a/thingsvision/core/extraction/extractors.py +++ b/thingsvision/core/extraction/extractors.py @@ -105,7 +105,7 @@ def get_default_transformation( ) -> Any: if self.weights: warnings.warn( - message="\nInput arguments are ignored because transforms are automatically infered transforms from model weights.\n", + message="\nInput arguments are ignored because transforms are automatically inferred from model weights.\n", category=UserWarning, stacklevel=2, )