pyvisim 0.1.0__py3-none-any.whl
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/__init__.py +5 -0
- pyvisim/_base_classes.py +51 -0
- pyvisim/_config.py +56 -0
- pyvisim/_errors.py +10 -0
- pyvisim/_utils.py +948 -0
- pyvisim/datasets/__init__.py +1 -0
- pyvisim/datasets/datasets.py +141 -0
- pyvisim/encoders/__init__.py +9 -0
- pyvisim/encoders/_base_encoder.py +275 -0
- pyvisim/encoders/fisher_vector.py +110 -0
- pyvisim/encoders/pipeline.py +126 -0
- pyvisim/encoders/vlad.py +97 -0
- pyvisim/eval.py +145 -0
- pyvisim/features/__init__.py +2 -0
- pyvisim/features/_features.py +290 -0
- pyvisim/losses/__init__.py +0 -0
- pyvisim/losses/_losses.py +204 -0
- pyvisim-0.1.0.dist-info/LICENSE +21 -0
- pyvisim-0.1.0.dist-info/METADATA +158 -0
- pyvisim-0.1.0.dist-info/RECORD +22 -0
- pyvisim-0.1.0.dist-info/WHEEL +5 -0
- pyvisim-0.1.0.dist-info/top_level.txt +1 -0
pyvisim/__init__.py
ADDED
pyvisim/_base_classes.py
ADDED
|
@@ -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
|
pyvisim/_config.py
ADDED
|
@@ -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
|
+
|
pyvisim/_errors.py
ADDED