pyvisim 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyvisim-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Nhat Huy Vu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
pyvisim-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,158 @@
1
+ Metadata-Version: 2.2
2
+ Name: pyvisim
3
+ Version: 0.1.0
4
+ Summary: A Python library for image similarity analysis using Image Encoders and Neural Networks
5
+ Home-page: https://github.com/MechaCritter/Python-Visual-Similarity
6
+ Author: Nhat Huy Vu
7
+ Author-email: vunhathuy234@gmail.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: opencv-python>=4.5.3
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: license
22
+ Dynamic: requires-dist
23
+ Dynamic: requires-python
24
+ Dynamic: summary
25
+
26
+ <!-- Logo -->
27
+ <p align="center">
28
+ <img src="res/images/logo.png" alt="pyvisim" width="1418" />
29
+ </p>
30
+
31
+ <!-- Added badges to convey project readiness/branding (example placeholders) -->
32
+ ![License](https://img.shields.io/badge/license-MIT-brightgreen)
33
+ ![Version](https://img.shields.io/badge/version-0.1.0-blue)
34
+ ![Status](https://img.shields.io/badge/status-pre--release-orange)
35
+ ![Python](https://img.shields.io/badge/Python-3.10%2B-brightgreen)
36
+ ![Contributions](https://img.shields.io/badge/contributions-welcome-brightgreen)
37
+
38
+ # Welcome to `pyvisim`!
39
+
40
+ `pyvisim` is a Python library for computing image similarities using encoding methods such as Fisher Vectors, VLAD
41
+ and Siamese Networks.
42
+
43
+ This project was made by me in cooperation with the __Lehrstuhl für Automatisierung und Informationssysteme__
44
+ at the Technical University of Munich.
45
+
46
+ ## Table of Contents
47
+
48
+ 1. [Why **pyvisim**](#why-pyvisim)
49
+ 2. [Installation](#installation)
50
+ 3. [Contributing](#contributing)
51
+ 4. [Get in Touch](#get-in-touch)
52
+ 5. [TODO](#todo)
53
+ 6. [License](#license)
54
+ 7. [Acknowledgements](#acknowledgements)
55
+ 8. [References](#references)
56
+
57
+ ## Why `pyvisim`?
58
+
59
+ `pyvisim` is designed to provide a simple and efficient way to compare images. The use-cases include:
60
+
61
+ 1. **Image Retrieval**
62
+ Retrieve the top-k most similar images from a dataset.
63
+ - Use encoding methods like VLAD or Fisher Vectors to quickly find the most relevant matches. Please visit
64
+ [this juptyer notebook](examples/vlad_fisher_with_vgg16_embeddings_image_retrieval.ipynb) for an example.
65
+ - Example use: Building a fast image search engine for photo management software.
66
+
67
+ 2. **Deep Learning Embeddings**
68
+ - Generate VLAD or Fisher vectors from neural network embeddings, e.g., VGG16 or other models.
69
+ - Enhance your deep learning pipeline by leveraging traditional encoding methods on top of CNN features.
70
+
71
+ 3. **Image Clustering**
72
+ - Cluster images based on their similarities to group them by category or content. An example and benchmarking
73
+ can be found in [this notebook](examples/clustering_images_using_fv.ipynb).
74
+ - Useful for organizing unlabeled data or generating pseudo-labels for further training.
75
+
76
+ 4. **Pipeline for Combining Multiple Encoders**
77
+ - Chain various encoders in a single pipeline. An example can be found in [this notebook](examples/pipeline.ipynb).
78
+ - Achieve more robust similarity metrics by blending different feature representations.
79
+
80
+ 5. **Siamese Network (Coming Soon!)**
81
+ - Train a neural network to learn a similarity function directly from pairs/triples of images.
82
+ - Possible use cases include face recognition, signature verification, or any image-based identity matching.
83
+
84
+ ## Installation
85
+
86
+ Currently, the package still needs to be tested and validated before being uploaded to PyPI. To use the library, you can
87
+ clone the repository and install the package locally:
88
+
89
+ ```bash
90
+ git clone # TODO: Add the link to the repository
91
+ cd similarity_metrics_of_images
92
+ pip install .
93
+ ```
94
+
95
+ All experiments in this project was made on the Oxford Flower Dataset <ref>[7]</ref>, for which I
96
+ have created a custom dataset class. To use this class, import it as follows:
97
+
98
+ ```python
99
+ from image_similarity.datasets import OxfordFlowerDataset
100
+ ```
101
+ In order to replicate the experiments done in this project, follow the preprocessing steps in
102
+ the [datasets README](pyvisim/datasets/README.md).
103
+
104
+ ## Contributing
105
+
106
+ We love contributions of all kinds—whether it’s suggesting new features, fixing bugs, or writing docs! Here’s how you
107
+ can get involved:
108
+
109
+ 1. **Fork** this repository.
110
+ 2. **Create a new branch** for your changes.
111
+ 3. **Open a pull request** with a clear description of your idea or fix.
112
+
113
+ We welcome all feedback and hope to build a supportive community around pyvisim!
114
+
115
+ ## Get in Touch
116
+ If you have any questions or just want to say hi, feel free to:
117
+ - Open an issue on [GitHub](https://github.com/MechaCritter/similarity_metrics_of_images/issues).
118
+ - Write me an email at [vunhathuy234@gmail.com](mailto:vunhathuy234@gmail.com).
119
+ - Connect on [LinkedIn](https://www.linkedin.com/in/nhat-huy-vu-80495111b/) to follow my work and share your thoughts.
120
+
121
+ ## TODO
122
+
123
+ The features below are planned for future releases:
124
+
125
+ - Implement proper **unit tests** to validate the functionality of the package before uploading to PyPI.
126
+ - Implement the **siamese network**.
127
+ - Add **tensor sketch approximation** and **mutual information** analysis for Fisher Vector, according to this
128
+ paper by Weixia Zhang, Jia Yan, Wenxuan Shi, Tianpeng Feng, and Dexiang Deng <sup>[1](#references)</sup>
129
+ - Add support for **vision transformers** for the `DeepConvFeature` class.
130
+
131
+ You are welcome to implement any of these features or suggest new ones!
132
+
133
+ ## License
134
+ This project is licensed under the terms of the MIT license.
135
+
136
+ ## Acknowledgements
137
+
138
+ I would like to thank the __Lehrstuhl für Automatisierung und Informationssysteme__ at the Technical University of Munich
139
+ for their support, guidance and provision of computational resources for this project, without which this project would
140
+ not have been possible. I would also like to thank my supervisor, <add name>, for his guidance, as well as Dr. <add name>
141
+ for her valuable feedback and suggestions.
142
+
143
+ ## References
144
+
145
+ [1] Weixia Zhang, Jia Yan, Wenxuan Shi, Tianpeng Feng, and Dexiang Deng, "Refining Deep Convolutional Features for
146
+ Improving Fine-Grained Image Recognition," EURASIP Journal on Image and Video Processing, 2017. \
147
+ [2] Relja Arandjelović and Andrew Zisserman, 'All About VLAD', Department of Engineering Science, University of Oxford. \
148
+ [3] E. Spyromitros-Xioufis, S. Papadopoulos, I. Kompatsiaris, G. Tsoumakas, and I. Vlahavas, "An Empirical Study on the
149
+ Combination of SURF Features with VLAD Vectors for Image Search," Informatics and Telematics Institute, Center for Research and
150
+ Technology Hellas, Thessaloniki, Greece; Department of Informatics, Aristotle University of Thessaloniki, Greece. \
151
+ [4] Relja Arandjelović and Andrew Zisserman, "Three things everyone should know to improve object retrieval," Department of
152
+ Engineering Science, University of Oxford. \
153
+ [5] Hervé Jégou, Florent Perronnin, Matthijs Douze, Jorge Sánchez, Patrick Pérez, and Cordelia Schmid, "Aggregating Local
154
+ Image Descriptors into Compact Codes," IEEE. \
155
+ [6] Liangliang Wang and Deepu Rajan, "An Image Similarity Descriptor for Classification Tasks," J. Vis. Commun.
156
+ Image R., vol. 71, pp. 102847, 2020. \
157
+ [7] [Oxford Flower Dataset](https://www.robots.ox.ac.uk/~vgg/data/flowers/102/).
158
+
@@ -0,0 +1,133 @@
1
+ <!-- Logo -->
2
+ <p align="center">
3
+ <img src="res/images/logo.png" alt="pyvisim" width="1418" />
4
+ </p>
5
+
6
+ <!-- Added badges to convey project readiness/branding (example placeholders) -->
7
+ ![License](https://img.shields.io/badge/license-MIT-brightgreen)
8
+ ![Version](https://img.shields.io/badge/version-0.1.0-blue)
9
+ ![Status](https://img.shields.io/badge/status-pre--release-orange)
10
+ ![Python](https://img.shields.io/badge/Python-3.10%2B-brightgreen)
11
+ ![Contributions](https://img.shields.io/badge/contributions-welcome-brightgreen)
12
+
13
+ # Welcome to `pyvisim`!
14
+
15
+ `pyvisim` is a Python library for computing image similarities using encoding methods such as Fisher Vectors, VLAD
16
+ and Siamese Networks.
17
+
18
+ This project was made by me in cooperation with the __Lehrstuhl für Automatisierung und Informationssysteme__
19
+ at the Technical University of Munich.
20
+
21
+ ## Table of Contents
22
+
23
+ 1. [Why **pyvisim**](#why-pyvisim)
24
+ 2. [Installation](#installation)
25
+ 3. [Contributing](#contributing)
26
+ 4. [Get in Touch](#get-in-touch)
27
+ 5. [TODO](#todo)
28
+ 6. [License](#license)
29
+ 7. [Acknowledgements](#acknowledgements)
30
+ 8. [References](#references)
31
+
32
+ ## Why `pyvisim`?
33
+
34
+ `pyvisim` is designed to provide a simple and efficient way to compare images. The use-cases include:
35
+
36
+ 1. **Image Retrieval**
37
+ Retrieve the top-k most similar images from a dataset.
38
+ - Use encoding methods like VLAD or Fisher Vectors to quickly find the most relevant matches. Please visit
39
+ [this juptyer notebook](examples/vlad_fisher_with_vgg16_embeddings_image_retrieval.ipynb) for an example.
40
+ - Example use: Building a fast image search engine for photo management software.
41
+
42
+ 2. **Deep Learning Embeddings**
43
+ - Generate VLAD or Fisher vectors from neural network embeddings, e.g., VGG16 or other models.
44
+ - Enhance your deep learning pipeline by leveraging traditional encoding methods on top of CNN features.
45
+
46
+ 3. **Image Clustering**
47
+ - Cluster images based on their similarities to group them by category or content. An example and benchmarking
48
+ can be found in [this notebook](examples/clustering_images_using_fv.ipynb).
49
+ - Useful for organizing unlabeled data or generating pseudo-labels for further training.
50
+
51
+ 4. **Pipeline for Combining Multiple Encoders**
52
+ - Chain various encoders in a single pipeline. An example can be found in [this notebook](examples/pipeline.ipynb).
53
+ - Achieve more robust similarity metrics by blending different feature representations.
54
+
55
+ 5. **Siamese Network (Coming Soon!)**
56
+ - Train a neural network to learn a similarity function directly from pairs/triples of images.
57
+ - Possible use cases include face recognition, signature verification, or any image-based identity matching.
58
+
59
+ ## Installation
60
+
61
+ Currently, the package still needs to be tested and validated before being uploaded to PyPI. To use the library, you can
62
+ clone the repository and install the package locally:
63
+
64
+ ```bash
65
+ git clone # TODO: Add the link to the repository
66
+ cd similarity_metrics_of_images
67
+ pip install .
68
+ ```
69
+
70
+ All experiments in this project was made on the Oxford Flower Dataset <ref>[7]</ref>, for which I
71
+ have created a custom dataset class. To use this class, import it as follows:
72
+
73
+ ```python
74
+ from image_similarity.datasets import OxfordFlowerDataset
75
+ ```
76
+ In order to replicate the experiments done in this project, follow the preprocessing steps in
77
+ the [datasets README](pyvisim/datasets/README.md).
78
+
79
+ ## Contributing
80
+
81
+ We love contributions of all kinds—whether it’s suggesting new features, fixing bugs, or writing docs! Here’s how you
82
+ can get involved:
83
+
84
+ 1. **Fork** this repository.
85
+ 2. **Create a new branch** for your changes.
86
+ 3. **Open a pull request** with a clear description of your idea or fix.
87
+
88
+ We welcome all feedback and hope to build a supportive community around pyvisim!
89
+
90
+ ## Get in Touch
91
+ If you have any questions or just want to say hi, feel free to:
92
+ - Open an issue on [GitHub](https://github.com/MechaCritter/similarity_metrics_of_images/issues).
93
+ - Write me an email at [vunhathuy234@gmail.com](mailto:vunhathuy234@gmail.com).
94
+ - Connect on [LinkedIn](https://www.linkedin.com/in/nhat-huy-vu-80495111b/) to follow my work and share your thoughts.
95
+
96
+ ## TODO
97
+
98
+ The features below are planned for future releases:
99
+
100
+ - Implement proper **unit tests** to validate the functionality of the package before uploading to PyPI.
101
+ - Implement the **siamese network**.
102
+ - Add **tensor sketch approximation** and **mutual information** analysis for Fisher Vector, according to this
103
+ paper by Weixia Zhang, Jia Yan, Wenxuan Shi, Tianpeng Feng, and Dexiang Deng <sup>[1](#references)</sup>
104
+ - Add support for **vision transformers** for the `DeepConvFeature` class.
105
+
106
+ You are welcome to implement any of these features or suggest new ones!
107
+
108
+ ## License
109
+ This project is licensed under the terms of the MIT license.
110
+
111
+ ## Acknowledgements
112
+
113
+ I would like to thank the __Lehrstuhl für Automatisierung und Informationssysteme__ at the Technical University of Munich
114
+ for their support, guidance and provision of computational resources for this project, without which this project would
115
+ not have been possible. I would also like to thank my supervisor, <add name>, for his guidance, as well as Dr. <add name>
116
+ for her valuable feedback and suggestions.
117
+
118
+ ## References
119
+
120
+ [1] Weixia Zhang, Jia Yan, Wenxuan Shi, Tianpeng Feng, and Dexiang Deng, "Refining Deep Convolutional Features for
121
+ Improving Fine-Grained Image Recognition," EURASIP Journal on Image and Video Processing, 2017. \
122
+ [2] Relja Arandjelović and Andrew Zisserman, 'All About VLAD', Department of Engineering Science, University of Oxford. \
123
+ [3] E. Spyromitros-Xioufis, S. Papadopoulos, I. Kompatsiaris, G. Tsoumakas, and I. Vlahavas, "An Empirical Study on the
124
+ Combination of SURF Features with VLAD Vectors for Image Search," Informatics and Telematics Institute, Center for Research and
125
+ Technology Hellas, Thessaloniki, Greece; Department of Informatics, Aristotle University of Thessaloniki, Greece. \
126
+ [4] Relja Arandjelović and Andrew Zisserman, "Three things everyone should know to improve object retrieval," Department of
127
+ Engineering Science, University of Oxford. \
128
+ [5] Hervé Jégou, Florent Perronnin, Matthijs Douze, Jorge Sánchez, Patrick Pérez, and Cordelia Schmid, "Aggregating Local
129
+ Image Descriptors into Compact Codes," IEEE. \
130
+ [6] Liangliang Wang and Deepu Rajan, "An Image Similarity Descriptor for Classification Tasks," J. Vis. Commun.
131
+ Image R., vol. 71, pp. 102847, 2020. \
132
+ [7] [Oxford Flower Dataset](https://www.robots.ox.ac.uk/~vgg/data/flowers/102/).
133
+
@@ -0,0 +1,5 @@
1
+ """
2
+ PyVisim: A Python library for image similarity analysis using Image Encoders and Neural Networks.
3
+ """
4
+
5
+ __all__ = ['datasets', 'encoders', 'features', 'eval']
@@ -0,0 +1,51 @@
1
+ import abc
2
+ import logging
3
+
4
+ import numpy as np
5
+
6
+ class SimilarityMetric(abc.ABC):
7
+ """
8
+ Abstract base for all similarity encoders.
9
+
10
+ All concrete similarity metric classes must inherit from this class.
11
+ """
12
+ _logger = logging.getLogger('Similarity_Metrics')
13
+ @abc.abstractmethod
14
+ def similarity_score(self, image1: np.ndarray, image2: np.ndarray) -> float:
15
+ """
16
+ Compute a similarity score between two images.
17
+
18
+ :param image1: First image
19
+ :param image2: Second image
20
+ :return: A similarity score
21
+ """
22
+ pass
23
+
24
+ class FeatureExtractorBase(abc.ABC):
25
+ """
26
+ Abstract interface for extracting features from images.
27
+
28
+ A feature extractor transforms an image (NumPy array) into a
29
+ set of feature vectors (NumPy array).
30
+ """
31
+ _logger = logging.getLogger("Feature_Extractor")
32
+ def __init__(self):
33
+ pass
34
+
35
+ @abc.abstractmethod
36
+ def __call__(self, image: np.ndarray) -> np.ndarray:
37
+ """
38
+ Extracts features from an image.
39
+
40
+ :param image: Input image (NumPy array).
41
+ :return: Feature descriptors (NumPy array).
42
+ """
43
+ raise NotImplementedError
44
+
45
+ @property
46
+ @abc.abstractmethod
47
+ def output_dim(self) -> int:
48
+ """
49
+ The dimensionality (D) of each feature vector, i.e., shape[1] of the output.
50
+ """
51
+ raise NotImplementedError
@@ -0,0 +1,56 @@
1
+ import logging
2
+ import logging.config
3
+ import pathlib
4
+
5
+ import yaml
6
+ import torch
7
+
8
+ # -Config for the dataset- #
9
+ ROOT = pathlib.Path(__file__).parent.parent
10
+ LOG_FILE_PATH = ROOT / "res/logs/log_msgs.log"
11
+
12
+ # - Device - #
13
+ ENFORCE_CUDA = True
14
+
15
+ def get_device():
16
+ """Get device (if available)"""
17
+ global ENFORCE_CUDA
18
+ if ENFORCE_CUDA:
19
+ if not torch.cuda.is_available():
20
+ raise RuntimeError("CUDA is not available. Please check your computer's configuration.")
21
+ return torch.device("cuda")
22
+ return torch.device("cuda" if torch.cuda.is_available() else "cpu")
23
+
24
+ DEVICE = get_device()
25
+ print(f"Device used: {DEVICE}")
26
+
27
+ # -Paths for the Excavator dataset- #
28
+ TRAIN_IMG_DATA_PATH_EXCAVATOR= rf"{ROOT}/excavator_dataset_w_masks/train"
29
+ TRAIN_MASK_DATA_PATH_EXCAVATOR = rf"{ROOT}/excavator_dataset_w_masks/train_annot"
30
+ TEST_IMG_DATA_PATH_EXCAVATOR = rf"{ROOT}/excavator_dataset_w_masks/test"
31
+ TEST_MASK_DATA_PATH_EXCAVATOR = rf"{ROOT}/excavator_dataset_w_masks/test_annot"
32
+ VALID_IMG_DATA_PATH_EXCAVATOR = None
33
+ VALID_MASK_DATA_PATH_EXCAVATOR = None
34
+
35
+ # -Paths for the Flower dataset- #
36
+ IMG_DATA_PATH_FLOWER = rf"{ROOT}/oxford_flower_dataset/images"
37
+ LABELS_PATH_FLOWER = rf"{ROOT}/oxford_flower_dataset/imagelabels.mat"
38
+ SETID_PATH_FLOWER = rf"{ROOT}/oxford_flower_dataset/setid.mat"
39
+
40
+
41
+ # - Logging - #
42
+ def setup_logging(default_path=rf"{ROOT}/res/logging_config.yaml", default_level=logging.INFO):
43
+ """Setup logging configuration"""
44
+ try:
45
+ with open(default_path, 'rt') as f:
46
+ config = yaml.safe_load(f.read())
47
+ try:
48
+ config["handlers"]["file_handler"]["filename"] = str(LOG_FILE_PATH)
49
+ except Exception as e:
50
+ print(f"Error in Logging Configuration: {e}. Cannot set output path for log file.")
51
+ logging.config.dictConfig(config)
52
+ except Exception as e:
53
+ print(f"Error in Logging Configuration: {e}")
54
+ logging.basicConfig(level=default_level, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
55
+
56
+
@@ -0,0 +1,10 @@
1
+ """
2
+ Includes exceptions for the package.
3
+ """
4
+
5
+ class InvalidImageError(Exception):
6
+ """
7
+ Raised when an image is not provided.
8
+ """
9
+ def __init__(self, message: str = "Input is not a valid image."):
10
+ super().__init__(message)