Skip to main content

Label Consistent Fisher Vectors (LCFV)

Project description

Label Consistent Fisher Vectors (LCFV)

View Label Consistent Fisher Vectors (LCFV) on File Exchange Octave application

Table of Contents

Overview

Label Consistent Fisher Vectors (LCFV) is a method for adding supervised information to Fisher vectors. This package provides implementations in both MATLAB/Octave and Python.

This package provides a complete pipeline for:

  1. Feature Extraction: Dense SIFT descriptors.
  2. Encoding: Fisher Vector encoding (GMM + PCA).
  3. Optimization: Learning the LCFV transformation matrix.

LCFV Logo

Video demo

YouTube Demo

Matlab / Octave Implementation

Installation

Simply clone the repository. The code is written in pure MATLAB/Octave and requires no external compilation.

git clone https://github.com/wq2012/LCFV.git

Demos

We provide three levels of demos:

  1. Synthetic End-to-End: code/run_synthetic_end2end_demo.m
    • Generates synthetic data, trains GMM, computes FV, and applies LCFV.
  2. CIFAR-10 Subset Real World: code/run_cifar10_end2end_demo.m
    • Extracts Dense SIFT from a subset of CIFAR-10 images, computes FV, and applies LCFV.
  3. LCFV Core: code/run_LCFV_demo.m
    • Shows how to use solve_LCFV1 and solve_LCFV2 on pre-computed descriptors.

Usage

1. Extract Features & Compute Fisher Vectors

You can use the built-in tools in code/fisher_vector/ to generate features from images.

addpath(genpath('code'));

% 1. Extract Dense SIFT from an image
img = imread('image.jpg');
descs = compute_dense_sift(img); % 128 x N matrix

% 2. Train GMM and PCA (using a set of training descriptors)
% all_descs: 128 x N_total matrix
K = 64; % Number of Gaussian components
pca_dim = 64; % PCA dimension
[w, mu, sigma, pca_transform, pca_mean] = fv_train(all_descs, K, pca_dim);

% 3. Encode Fisher Vector for a new image
% img_descs: 128 x N descriptors for the image
% Apply PCA projection first
img_descs_pca = pca_transform * bsxfun(@minus, img_descs, pca_mean);
% Encode
fv = fv_encode(img_descs_pca, w, mu, sigma);

2. Apply Label Consistent Fisher Vectors (LCFV)

Once you have Fisher Vectors for your training set, you can learn the LCFV transformation.

% G: D x N matrix of Fisher Vectors (column vectors)
% labels: N x 1 vector of class labels
% alpha: Regularization parameter (e.g., 10)

% Create label comparison matrix
C1 = repmat(labels, 1, length(labels));
C2 = repmat(labels', length(labels), 1);
C = double(C1 == C2);

% LCFV-1 (Sparse)
[M1, W1] = solve_LCFV1(G, C, alpha);
lcfv_features = M1 * G;

% LCFV-2 (Dense)
M2 = solve_LCFV2(G, C, alpha);
lcfv_features = M2 * G;

Python Implementation

We provide a mirror implementation in Python located in the python/ directory.

Installation

Install from source:

cd python
pip install .

Or install from PyPI:

pip install lcfv

Usage

import numpy as np
import cv2
from lcfv import compute_dense_sift, fv_encode, solve_lcfv1, fv_train

# 1. Feature Extraction
# compute_dense_sift expects HxW or HxWx3 image
img = cv2.imread('image.jpg')
descs = compute_dense_sift(img) # 128 x N numpy array

# 2. Train GMM/PCA
# all_descs: 128 x N_total
K = 64
w, mu, sigma, pca_transform, pca_mean = fv_train(all_descs, K, pca_dim=64)

# 3. Encode
# Apply PCA first
descs_centered = all_descs - pca_mean[:, None]
descs_pca = np.dot(pca_transform, descs_centered)

fv = fv_encode(descs_pca, w, mu, sigma) # (2*D*K) x 1

# 4. LCFV
# G: D x N matrix of FVs
# C: Label consistency matrix
M1, W1 = solve_lcfv1(G, C, alpha=10)
lcfv_feats = np.dot(M1, G)

Copyright and Citation

Copyright (C) 2012 Quan Wang <wangq10@rpi.edu>,
Signal Analysis and Machine Perception Laboratory,
Department of Electrical, Computer, and Systems Engineering,
Rensselaer Polytechnic Institute, Troy, NY 12180, USA

This software was developed as part of the following research. If you use this software in your research, please cite:

Plain Text:

Quan Wang, Xin Shen, Meng Wang, and Kim L. Boyer. "Label consistent fisher vectors for supervised feature aggregation." In 2014 22nd International Conference on Pattern Recognition, pp. 3588-3593. IEEE, 2014.

Quan Wang. Exploiting Geometric and Spatial Constraints for Vision and Lighting Applications. Ph.D. dissertation, Rensselaer Polytechnic Institute, 2014.

BibTeX:

@inproceedings{wang2014label,
  title={Label consistent Fisher vectors for supervised feature aggregation},
  author={Wang, Quan and Shen, Xin and Wang, Meng and Boyer, Kim L},
  booktitle={Pattern Recognition (ICPR), 2014 22nd International Conference on},
  pages={2507--2512},
  year={2014},
  organization={IEEE}
}

@phdthesis{wang2014exploiting,
  title={Exploiting Geometric and Spatial Constraints for Vision and Lighting Applications},
  author={Quan Wang},
  year={2014},
  school={Rensselaer Polytechnic Institute},
}

This library is also available at MathWorks: https://www.mathworks.com/matlabcentral/fileexchange/47730-label-consistent-fisher-vectors-lcfv

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lcfv-0.1.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lcfv-0.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file lcfv-0.1.0.tar.gz.

File metadata

  • Download URL: lcfv-0.1.0.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for lcfv-0.1.0.tar.gz
Algorithm Hash digest
SHA256 16acb53133bc42ce4c8dd35a09ba79d3b38e459b8dcf33858468d1e684bf933e
MD5 fc5c04808c38e0ce1dc4c2cdade9e6c7
BLAKE2b-256 d1600999cf21069aee0f3114e8d71e30253db4c067c492c2f121e692c1bc2d53

See more details on using hashes here.

File details

Details for the file lcfv-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lcfv-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for lcfv-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 670f538f8b3aa1163f524af7948dd3c0438399c32f28bb62cd192094ce057fe7
MD5 102c3259b3632413cba32b0a359f565f
BLAKE2b-256 064b09bd7c38e7b7a9a18ac6f1f735838f9449564c950b5142e86ae3471ee5b8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page