In [ ]:
# Quantization
Attemps to reduce the feature vector size from $200*32 = 6400$ bits to a lower size.
In [1]:
%pylab inline
from tools import *
from stats import *
Using uniform LBP with WPCA as descriptor.
In [2]:
descs = np.load("descriptors/ulbp_wpca.npy")
In [3]:
quantization_labels = ["No quantization"]
quantization_rocs = [descs]
In [12]:
def binary_quantization(descs):
quantized_descs = np.array(descs, copy=True)
for i in range(quantized_descs.shape[0]):
quantized_descs[i][quantized_descs[i] >= 0] = 1.0
quantized_descs[i][quantized_descs[i] < 0] = -1.0
quantized_descs[i] = quantized_descs[i] / np.linalg.norm(quantized_descs[i])
return quantized_descs
In [13]:
quantization_labels.append("Binary quantization")
quantization_rocs.append(binary_quantization(descs))
In [14]:
print descs[:2,:5]
print binary_quantization(descs[:2,:5])
Simple reconstruction method : for each feature vector $x$, for each of its dimension, $x_k= \overline{x_k^{+}}$ if $x_k \geq 0$ otherwise $x_k = \overline{x_k^{-}}$ where $\overline{x_k^+}$ is the mean of the positive values for the dimension #k and $\overline{x_k^-}$ is the mean of the negative values for the dimension #k.
Brings the feature vector's size to : 200 + 2*32 = 264 bits
In [7]:
def compute_means(descs):
pos_means = np.zeros(descs.shape[1])
neg_means = np.zeros(descs.shape[1])
for i in range(descs.shape[1]):
values = descs[:,i]
pos_means[i] = np.mean(values[values >= 0.0])
neg_means[i] = np.mean(values[values < 0.0])
return pos_means,neg_means
def simple_reconstruction(descs, pos_means, neg_means):
quantized_descs = np.array(descs, copy=True)
for i in range(quantized_descs.shape[0]):
for j in range(quantized_descs.shape[1]):
if quantized_descs[i,j] >= 0:
quantized_descs[i,j] = pos_means[j]
else:
quantized_descs[i,j] = neg_means[j]
quantized_descs[i] = quantized_descs[i] / np.linalg.norm(quantized_descs[i])
return quantized_descs
In [8]:
quantization_labels.append("Simple reconstruction")
pos_means, neg_means = compute_means(descs)
quantization_rocs.append(simple_reconstruction(descs, pos_means, neg_means))
In [9]:
print descs[:2,:5]
print simple_reconstruction(descs[:2,:5], pos_means, neg_means)
In [ ]:
In [10]:
"""
quantization_labels.append("ITQ")
"""
Out[10]:
In [11]:
from dataset import loadSetsGroundTruth
sets_ground_truth = loadSetsGroundTruth()
rocs = computeMeanROC(quantization_rocs, sets_ground_truth)
In [12]:
plotROC(rocs, quantization_labels, title="ROC curve for several quantization methods")
In [12]: