Skip to content

Commit 6bd9342

Browse files
MechaCritterclaude
andcommitted
docs: update READMEs for the params-at-init encoder API
Quickstart now configures the encoder from parameters, calls learn() and shows save_to_disk/load_from_disk with .encoder files. Document the kmeans_params/gmm_params/pca_params dictionaries in the encoders README and mark KMeansWeights/GMMWeights loading as deprecated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 6b4be33 commit 6bd9342

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ similarity_score = encoder.similarity_score(image1, image2)
5555

5656
print(f"Similarity Score: {similarity_score}")
5757
```
58+
59+
A fitted encoder can be saved to a `.encoder` file and restored later:
60+
61+
```python
62+
path = encoder.save_to_disk("vlad_oxford102") # writes vlad_oxford102.encoder
63+
encoder = VLADEncoder.load_from_disk(path)
64+
```
5865
You can also visit the [introduction notebook](examples/getting_started.ipynb) for more examples.
5966

6067
I also provided various notebooks for different use-cases. Feel free to check them out, and let me know if you
@@ -109,14 +116,19 @@ For more details on the dataset, please refer to the [documentation](pyvisim/dat
109116

110117
## Pretrained Models
111118

119+
> [!CAUTION]
120+
> **Deprecated:** Loading pretrained models via the `KMeansWeights`/`GMMWeights` enums is deprecated
121+
> and will be removed in a future release. Train an encoder with `learn()` and persist it with `save_to_disk()`/
122+
> `load_from_disk()` (`.encoder` files) instead.
123+
112124
The following pretrained models are provided for clustering and dimensionality reduction. All clustering
113125
models were trained with `k=256`. The choice of `k` was made arbitrarily
114126
based on the paper <sup>[5](#references)</sup>, where the authors tested with `k=32`, `64`, `128`, `256`, `512`, and so on.
115127
Since higher values would take too long, I chose `k=256` as a balance between performance and computational cost.
116128

117129
### KMeans Models
118130

119-
You can access these weights by importing `KMWeights` from the `pyvisim.encoders` module.
131+
You can access these weights by importing `KMeansWeights` from the `pyvisim.encoders` module.
120132

121133
| Model Name | Features Extracted From | PCA Applied | Feature Dimensions |
122134
|----------------------------------------|-------------------------|-------------|--------------------|

pyvisim/encoders/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,40 @@ differ in the way they aggregate these descriptors and the underlying clustering
2929
After the feature extraction step, the local features are aggregated to their respective cluster centers. The final
3030
encoding matrix is then flattened and normalized to produce the final feature vector representation of the image.
3131

32+
## Configuring Encoders
33+
34+
The encoders build their clustering models internally: VLAD always uses K-Means and the Fisher Vector encoder always
35+
uses a Gaussian Mixture Model (both implemented in `pyvisim.clustering`).
36+
37+
```python
38+
from pyvisim.encoders import VLADEncoder, FisherVectorEncoder
39+
40+
vlad = VLADEncoder(
41+
n_clusters=256,
42+
kmeans_params={"random_state": 42},
43+
pca_params={"n_components": 64},
44+
)
45+
fisher = FisherVectorEncoder(
46+
n_components=256,
47+
gmm_params={"random_state": 42},
48+
)
49+
```
50+
51+
Calling `learn(images)` fits the configured PCA (if any) and the clustering model. A fitted encoder can be saved to
52+
disk and restored later:
53+
54+
```python
55+
vlad.learn(images)
56+
path = vlad.save_to_disk("vlad") # writes vlad.encoder
57+
vlad = VLADEncoder.load_from_disk(path)
58+
```
59+
60+
The `.encoder` file stores the fitted clustering model, the PCA model and the normalization hyperparameters. The
61+
feature extractor and the similarity function are not serialized; provide them again when loading.
62+
63+
Loading pretrained models via the `KMeansWeights`/`GMMWeights` enums is deprecated and will be removed in a future
64+
release.
65+
3266
## Similarity Metric Pipeline
3367
The _Pipeline_ class is designed to handle multiple encoders simultaneously to compute feature vectors. It takes
3468
a list of encoders (instances of the ImageEncoderBase class defined in the '_base_encoder.py' file) and a function

0 commit comments

Comments
 (0)