Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.2
hooks:
- id: ruff-check
args: [ --fix ]
- id: ruff-format

Comment thread
Copilot marked this conversation as resolved.
Outdated
- repo: https://github.com/codespell-project/codespell
Expand Down
24 changes: 4 additions & 20 deletions examples/clustering_images_using_fv.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,16 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "9d64d8aebd89bdcd",
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-18T23:05:14.526690Z",
"start_time": "2025-01-18T23:05:00.750503Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2025-01-19 00:05:08,127 - numexpr.utils - INFO - Note: NumExpr detected 64 cores but \"NUMEXPR_MAX_THREADS\" not set, so enforcing safe limit of 8.\n",
"2025-01-19 00:05:08,128 - numexpr.utils - INFO - NumExpr defaulting to 8 threads.\n"
]
}
],
"source": [
"from torchvision.models import VGG16_Weights, vgg16\n",
"\n",
"from pyvisim._utils import *\n",
"from pyvisim.datasets import OxfordFlowerDataset\n",
"from pyvisim.encoders import FisherVectorEncoder, GMMWeights\n",
"from pyvisim.features import DeepConvFeature"
]
"outputs": [],
"source": "import numpy as np\nfrom torchvision.models import VGG16_Weights, vgg16\n\nfrom pyvisim._utils import (\n cluster_images_and_generate_statistics,\n cosine_similarity,\n plot_and_save_heatmap,\n)\nfrom pyvisim.datasets import OxfordFlowerDataset\nfrom pyvisim.encoders import FisherVectorEncoder, GMMWeights\nfrom pyvisim.features import DeepConvFeature"
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -316,4 +300,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
19 changes: 3 additions & 16 deletions examples/clustering_images_using_pipeline.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"id": "9d64d8aebd89bdcd",
"metadata": {
"ExecuteTime": {
Expand All @@ -31,20 +31,7 @@
}
},
"outputs": [],
"source": [
"from torchvision.models import VGG16_Weights, vgg16\n",
"\n",
"from pyvisim._utils import *\n",
"from pyvisim.datasets import OxfordFlowerDataset\n",
"from pyvisim.encoders import (\n",
" FisherVectorEncoder,\n",
" GMMWeights,\n",
" KMeansWeights,\n",
" Pipeline,\n",
" VLADEncoder,\n",
")\n",
"from pyvisim.features import DeepConvFeature"
]
"source": "import numpy as np\nfrom torchvision.models import VGG16_Weights, vgg16\n\nfrom pyvisim._utils import (\n cluster_images_and_generate_statistics,\n cosine_similarity,\n plot_and_save_heatmap,\n)\nfrom pyvisim.datasets import OxfordFlowerDataset\nfrom pyvisim.encoders import (\n FisherVectorEncoder,\n GMMWeights,\n KMeansWeights,\n Pipeline,\n VLADEncoder,\n)\nfrom pyvisim.features import DeepConvFeature"
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -320,4 +307,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
13 changes: 3 additions & 10 deletions examples/clustering_images_using_vlad.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"id": "9d64d8aebd89bdcd",
"metadata": {
"ExecuteTime": {
Expand All @@ -29,14 +29,7 @@
}
},
"outputs": [],
"source": [
"from torchvision.models import VGG16_Weights, vgg16\n",
"\n",
"from pyvisim._utils import *\n",
"from pyvisim.datasets import OxfordFlowerDataset\n",
"from pyvisim.encoders import KMeansWeights, VLADEncoder\n",
"from pyvisim.features import DeepConvFeature"
]
"source": "import numpy as np\nfrom torchvision.models import VGG16_Weights, vgg16\n\nfrom pyvisim._utils import (\n cluster_images_and_generate_statistics,\n cosine_similarity,\n plot_and_save_heatmap,\n)\nfrom pyvisim.datasets import OxfordFlowerDataset\nfrom pyvisim.encoders import KMeansWeights, VLADEncoder\nfrom pyvisim.features import DeepConvFeature"
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -305,4 +298,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
19 changes: 5 additions & 14 deletions examples/m_ap_and_top_k_accuracy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"id": "45cf34f1532e800e",
"metadata": {
"ExecuteTime": {
Expand All @@ -80,10 +80,7 @@
}
},
"outputs": [],
"source": [
"train_imgs, train_labels = zip(*[(img, label) for img, label, _ in train_dataset])\n",
"val_imgs, val_labels = zip(*[(img, label) for img, label, _ in val_dataset])"
]
"source": "train_imgs, train_labels = zip(\n *[(img, label) for img, label, _ in train_dataset], strict=True\n)\nval_imgs, val_labels = zip(*[(img, label) for img, label, _ in val_dataset], strict=True)"
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -170,7 +167,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"id": "b41f8223d09379ac",
"metadata": {
"ExecuteTime": {
Expand All @@ -179,13 +176,7 @@
}
},
"outputs": [],
"source": [
"train_paths, train_labels = zip(*[(path, label) for _, label, path in train_dataset])\n",
"encodings_vlad = vlad_encoder.generate_encoding_map(train_paths)\n",
"encodings_fisher = fisher_vector_encoder.generate_encoding_map(train_paths)\n",
"encodings_pipeline = pipeline_with_pca.generate_encoding_map(train_paths)\n",
"dataset_labels_dict = dict(zip(train_paths, train_labels))"
]
"source": "train_paths, train_labels = zip(\n *[(path, label) for _, label, path in train_dataset], strict=True\n)\nencodings_vlad = vlad_encoder.generate_encoding_map(train_paths)\nencodings_fisher = fisher_vector_encoder.generate_encoding_map(train_paths)\nencodings_pipeline = pipeline_with_pca.generate_encoding_map(train_paths)\ndataset_labels_dict = dict(zip(train_paths, train_labels, strict=True))"
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -579,4 +570,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
19 changes: 3 additions & 16 deletions examples/pipeline.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "3cfeb663c836d2a9",
"metadata": {
"ExecuteTime": {
Expand All @@ -32,20 +32,7 @@
}
},
"outputs": [],
"source": [
"from torchvision.models import VGG16_Weights, vgg16\n",
"\n",
"from pyvisim._utils import *\n",
"from pyvisim.datasets import OxfordFlowerDataset # or any dataset you have\n",
"from pyvisim.encoders import (\n",
" FisherVectorEncoder,\n",
" GMMWeights,\n",
" KMeansWeights,\n",
" Pipeline,\n",
" VLADEncoder,\n",
")\n",
"from pyvisim.features import DeepConvFeature"
]
"source": "import os\n\nimport numpy as np\nimport torch\nfrom torchvision.models import VGG16_Weights, vgg16\n\nfrom pyvisim._utils import cosine_similarity, plot_and_save_heatmap, plot_image\nfrom pyvisim.datasets import OxfordFlowerDataset # or any dataset you have\nfrom pyvisim.encoders import (\n FisherVectorEncoder,\n GMMWeights,\n KMeansWeights,\n Pipeline,\n VLADEncoder,\n)\nfrom pyvisim.features import DeepConvFeature"
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -553,4 +540,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
18 changes: 3 additions & 15 deletions examples/vlad_and_fisher_with_vgg16_deep_features.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "169b9b052dc0e9b4",
"metadata": {
"ExecuteTime": {
Expand All @@ -43,19 +43,7 @@
}
},
"outputs": [],
"source": [
"from torchvision.models import VGG16_Weights, vgg16\n",
"\n",
"from pyvisim._utils import *\n",
"from pyvisim.datasets import OxfordFlowerDataset # We'll create this in a moment\n",
"from pyvisim.encoders._base_encoder import GMMWeights, KMeansWeights\n",
"from pyvisim.encoders.fisher_vector import FisherVectorEncoder\n",
"from pyvisim.encoders.vlad import VLADEncoder\n",
"from pyvisim.eval import retrieve_top_k_similar\n",
"\n",
"# Our library imports\n",
"from pyvisim.features import DeepConvFeature"
]
"source": "import os\n\nimport cv2\nimport matplotlib.pyplot as plt\nfrom torchvision.models import VGG16_Weights, vgg16\n\nfrom pyvisim._utils import plot_image\nfrom pyvisim.datasets import OxfordFlowerDataset # We'll create this in a moment\nfrom pyvisim.encoders._base_encoder import GMMWeights, KMeansWeights\nfrom pyvisim.encoders.fisher_vector import FisherVectorEncoder\nfrom pyvisim.encoders.vlad import VLADEncoder\nfrom pyvisim.eval import retrieve_top_k_similar\n\n# Our library imports\nfrom pyvisim.features import DeepConvFeature"
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -1093,4 +1081,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
4 changes: 0 additions & 4 deletions pyvisim/_base_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import numpy as np



class SimilarityMetric(abc.ABC):
"""
Abstract base for all similarity encoders.
Expand Down Expand Up @@ -39,9 +38,6 @@ class FeatureExtractorBase(abc.ABC):

_logger = logging.getLogger("Feature_Extractor")

def __init__(self):
pass

@abc.abstractmethod
def __call__(self, image: np.ndarray):
"""
Expand Down
Loading
Loading