Fisher Vectors based on Gaussian Mixture Model with TensorFlow deep learning support
Project description
DeepFV - Fisher Vectors with Deep Learning
A TensorFlow-based implementation of Improved Fisher Vectors as described in [1]. This package provides a modern, scalable approach to computing Fisher Vectors using deep learning techniques. For a concise description of Fisher Vectors see [2].
Features
- Full & Diagonal Covariance Support: Model complex elliptical clusters with full covariance matrices, or use diagonal covariance for faster training
- Mini-batch Training: Scalable to large datasets with mini-batch gradient descent
- BIC-based Model Selection: Automatically determine optimal number of GMM components
- GPU Acceleration: Built on TensorFlow 2.x for fast training on GPUs
- MiniBatchKMeans Initialization: Smart initialization using scikit-learn's MiniBatchKMeans
- Save/Load Models: Persist trained models for reuse
- Normalized Fisher Vectors: Implements improved Fisher Vector normalization
Installation
Install from PyPI:
pip install DeepFV
Or install from source:
git clone https://github.com/sidhomj/DeepFV.git
cd DeepFV
pip install -r requirements.txt
pip install -e .
Quick Start
1. Prepare your data
import numpy as np
# Example: SIFT image features
shape = [300, 20, 32] # (n_images, n_features_per_image, feature_dim)
image_data = np.concatenate([
np.random.normal(-np.ones(30), size=shape),
np.random.normal(np.ones(30), size=shape)
], axis=0)
2. Train with mini-batch gradient descent
from DeepFV import FisherVectorDL
# Create model with FULL covariance support
fv_dl = FisherVectorDL(
n_kernels=10,
feature_dim=32,
covariance_type='full' # or 'diag' for diagonal covariance
)
# Fit with mini-batch training
fv_dl.fit_minibatch(
image_data,
epochs=100,
batch_size=1024*6,
learning_rate=0.001,
verbose=True
)
3. BIC-based model selection
# Automatically select optimal number of components
fv_dl = FisherVectorDL(feature_dim=32, covariance_type='full')
fv_dl.fit_by_bic(
image_data,
choices_n_kernels=[2, 5, 10, 20],
epochs=80,
batch_size=1024,
verbose=True
)
print(f"Selected {fv_dl.n_kernels} components")
4. Compute Fisher Vectors
# Compute normalized Fisher Vectors
image_data_test = image_data[:20]
fisher_vectors = fv_dl.predict_fisher_vector(image_data_test, normalized=True)
# Output shape: (n_images, 2*n_kernels, feature_dim)
print(f"Fisher vector shape: {fisher_vectors.shape}")
5. Save and load models
# Save trained model
fv_dl.save_model('my_model.pkl')
# Load model later
from DeepFV import FisherVectorDL
fv_dl_loaded = FisherVectorDL.load_model('my_model.pkl')
Why FisherVectorDL?
Advantages over traditional GMM implementations:
- Full Covariance Support: Model rotated/tilted elliptical clusters, not just axis-aligned ones
- Scalability: Mini-batch training handles datasets too large to fit in memory
- Speed: GPU acceleration via TensorFlow for faster training
- Flexibility: Customizable learning rate, batch size, and number of epochs
- Modern Stack: Built on TensorFlow 2.x with eager execution
- Smart Initialization: Uses MiniBatchKMeans for better starting parameters
Testing
Run the test script to see a 2D visualization:
python test_fishervector_dl.py
This will:
- Generate 3 elliptical Gaussian clusters
- Train a GMM with full covariance
- Use BIC to select optimal number of components
- Compute and visualize Fisher Vectors
- Save visualizations as PNG files
Example Results
GMM Clustering with BIC Selection:
The plot shows how full covariance GMMs can model rotated elliptical clusters. The BIC criterion automatically selects the optimal number of components.
Fisher Vector Visualization:
Left: Original 2D data colored by true cluster labels. Right: Fisher Vectors projected back to 2D using PCA, showing how the representation captures cluster structure.
Contributors
- John-William Sidhom (https://github.com/sidhomj/) - Main contributor, TensorFlow implementation with full covariance support
Original Contributors:
- Jonas Rothfuss (https://github.com/jonasrothfuss/) - Original implementation
- Fabio Ferreira (https://github.com/ferreirafabio/) - Original implementation
References
- [1] Perronnin, F., Sánchez, J., & Mensink, T. (2010). Improving the fisher kernel for large-scale image classification. In European conference on computer vision (pp. 143-156). Springer, Berlin, Heidelberg. https://www.robots.ox.ac.uk/~vgg/rg/papers/peronnin_etal_ECCV10.pdf
- [2] Fisher Vector Fundamentals - VLFeat Documentation: http://www.vlfeat.org/api/fisher-fundamentals.html
License
MIT License - see LICENSE file for details
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file deepfv-0.2.2.tar.gz.
File metadata
- Download URL: deepfv-0.2.2.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
046226d69356e2f6a9b20339ab3cf5bebfc484089fb26387e9f7227b778acec6
|
|
| MD5 |
e83f5b0a5d0aaa99f263b683e39addf8
|
|
| BLAKE2b-256 |
fde108056337eca50700e96b940fb165d31c37ad6edb0bb2991603eafc43f16b
|
File details
Details for the file deepfv-0.2.2-py3-none-any.whl.
File metadata
- Download URL: deepfv-0.2.2-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec9f486d73183f120b8b8dfa23acad076e3197a82d41495013910918998c550f
|
|
| MD5 |
b0f3b1682fc1342c28d347f6d4ec002b
|
|
| BLAKE2b-256 |
4b1ef5e6f7f9b1871d4ec81d4ebd531c656b3734bb34eafaf081f6d7e69ca751
|