Skip to content
Snippets Groups Projects
Commit c32d6518 authored by Olegs NIKISINS's avatar Olegs NIKISINS
Browse files

Merge branch 'dev_branch' into 'master'

Removed temp stuff from setup.py, cleaning of sparse coding algorithms

See merge request !17
parents 8918becd eb9c26f7
No related branches found
No related tags found
1 merge request!17Removed temp stuff from setup.py, cleaning of sparse coding algorithms
Pipeline #
include README.rst bootstrap-buildout.py buildout.cfg COPYING version.txt requirements.txt
recursive-include bob/pad/face/lists *.*
recursive-include bob/pad/face/config/preprocessor/dictionaries *.hdf5
recursive-include doc *.py *.rst *.ico *.png
recursive-include bob/pad/face/test/data *.hdf5 *.png
#!/usr/bin/env python
from bob.pad.face.extractor import VideoHistOfSparseCodes
#=======================================================================================
# Define instances here:
METHOD = "mean"
extractor_mean = VideoHistOfSparseCodes(method = METHOD)
METHOD = "hist"
extractor_hist = VideoHistOfSparseCodes(method = METHOD)
File added
File added
File added
......@@ -2,7 +2,6 @@
from bob.pad.face.preprocessor import VideoSparseCoding
#=======================================================================================
# Define instances here:
......@@ -10,116 +9,19 @@ BLOCK_SIZE = 5
BLOCK_LENGTH = 10
MIN_FACE_SIZE = 50
NORM_FACE_SIZE = 64
DICTIONARY_FILE_NAMES = ["/idiap/user/onikisins/Projects/ODIN/Python/scripts/test_scripts/data/dictionary_front.hdf5",
"/idiap/user/onikisins/Projects/ODIN/Python/scripts/test_scripts/data/dictionary_hor.hdf5",
"/idiap/user/onikisins/Projects/ODIN/Python/scripts/test_scripts/data/dictionary_vert.hdf5"]
FRAME_STEP = 10
preprocessor = VideoSparseCoding(gblock_size = BLOCK_SIZE,
block_length = BLOCK_LENGTH,
min_face_size = MIN_FACE_SIZE,
norm_face_size = NORM_FACE_SIZE,
dictionary_file_names = DICTIONARY_FILE_NAMES,
frame_step = FRAME_STEP)
#=======================================================================================
BLOCK_SIZE = 5
BLOCK_LENGTH = 10
MIN_FACE_SIZE = 50
NORM_FACE_SIZE = 64
DICTIONARY_FILE_NAMES = ["/idiap/user/onikisins/Projects/ODIN/Python/scripts/test_scripts/data/dictionary_front_10_5_16.hdf5",
"/idiap/user/onikisins/Projects/ODIN/Python/scripts/test_scripts/data/dictionary_hor_10_5_16.hdf5",
"/idiap/user/onikisins/Projects/ODIN/Python/scripts/test_scripts/data/dictionary_vert_10_5_16.hdf5"]
FRAME_STEP = 2
EXTRACT_HISTOGRAMS_FLAG = True
preprocessor_10_5_16 = VideoSparseCoding(gblock_size = BLOCK_SIZE,
block_length = BLOCK_LENGTH,
min_face_size = MIN_FACE_SIZE,
norm_face_size = NORM_FACE_SIZE,
dictionary_file_names = DICTIONARY_FILE_NAMES,
frame_step = FRAME_STEP,
extract_histograms_flag = EXTRACT_HISTOGRAMS_FLAG)
BLOCK_SIZE = 5
BLOCK_LENGTH = 10
MIN_FACE_SIZE = 50
NORM_FACE_SIZE = 64
DICTIONARY_FILE_NAMES = ["/idiap/user/onikisins/Projects/ODIN/Python/scripts/test_scripts/data/dictionary_front_10_5_32.hdf5",
"/idiap/user/onikisins/Projects/ODIN/Python/scripts/test_scripts/data/dictionary_hor_10_5_32.hdf5",
"/idiap/user/onikisins/Projects/ODIN/Python/scripts/test_scripts/data/dictionary_vert_10_5_32.hdf5"]
FRAME_STEP = 2
EXTRACT_HISTOGRAMS_FLAG = True
preprocessor_10_5_32 = VideoSparseCoding(gblock_size = BLOCK_SIZE,
block_length = BLOCK_LENGTH,
min_face_size = MIN_FACE_SIZE,
norm_face_size = NORM_FACE_SIZE,
dictionary_file_names = DICTIONARY_FILE_NAMES,
frame_step = FRAME_STEP,
extract_histograms_flag = EXTRACT_HISTOGRAMS_FLAG)
BLOCK_SIZE = 5
BLOCK_LENGTH = 10
MIN_FACE_SIZE = 50
NORM_FACE_SIZE = 64
DICTIONARY_FILE_NAMES = ["/idiap/user/onikisins/Projects/ODIN/Python/scripts/test_scripts/data/dictionary_front_10_5_64.hdf5",
"/idiap/user/onikisins/Projects/ODIN/Python/scripts/test_scripts/data/dictionary_hor_10_5_64.hdf5",
"/idiap/user/onikisins/Projects/ODIN/Python/scripts/test_scripts/data/dictionary_vert_10_5_64.hdf5"]
FRAME_STEP = 2
EXTRACT_HISTOGRAMS_FLAG = True
preprocessor_10_5_64 = VideoSparseCoding(gblock_size = BLOCK_SIZE,
block_length = BLOCK_LENGTH,
min_face_size = MIN_FACE_SIZE,
norm_face_size = NORM_FACE_SIZE,
dictionary_file_names = DICTIONARY_FILE_NAMES,
frame_step = FRAME_STEP,
extract_histograms_flag = EXTRACT_HISTOGRAMS_FLAG)
BLOCK_SIZE = 5
BLOCK_LENGTH = 10
MIN_FACE_SIZE = 50
NORM_FACE_SIZE = 64
DICTIONARY_FILE_NAMES = ["/idiap/user/onikisins/Projects/ODIN/Python/scripts/test_scripts/data/dictionary_front_10_5_128.hdf5",
"/idiap/user/onikisins/Projects/ODIN/Python/scripts/test_scripts/data/dictionary_hor_10_5_128.hdf5",
"/idiap/user/onikisins/Projects/ODIN/Python/scripts/test_scripts/data/dictionary_vert_10_5_128.hdf5"]
FRAME_STEP = 2
EXTRACT_HISTOGRAMS_FLAG = True
preprocessor_10_5_128 = VideoSparseCoding(gblock_size = BLOCK_SIZE,
block_length = BLOCK_LENGTH,
min_face_size = MIN_FACE_SIZE,
norm_face_size = NORM_FACE_SIZE,
dictionary_file_names = DICTIONARY_FILE_NAMES,
frame_step = FRAME_STEP,
extract_histograms_flag = EXTRACT_HISTOGRAMS_FLAG)
#=======================================================================================
BLOCK_SIZE = 5
BLOCK_LENGTH = 10
MIN_FACE_SIZE = 50
NORM_FACE_SIZE = 64
DICTIONARY_FILE_NAMES = ["/idiap/user/onikisins/Projects/ODIN/Python/scripts/test_scripts/data/dictionary_front_10_5_64.hdf5",
"/idiap/user/onikisins/Projects/ODIN/Python/scripts/test_scripts/data/dictionary_hor_10_5_64.hdf5",
"/idiap/user/onikisins/Projects/ODIN/Python/scripts/test_scripts/data/dictionary_vert_10_5_64.hdf5"]
DICTIONARY_FILE_NAMES = ["./dictionaries/dictionary_front_10_5_128.hdf5",
"./dictionaries/dictionary_hor_10_5_128.hdf5",
"./dictionaries/dictionary_vert_10_5_128.hdf5"]
FRAME_STEP = 50 # (!) a small number of feature vectors will be computed
EXTRACT_HISTOGRAMS_FLAG = True
COMP_RECONSTRUCT_ERR_FLAG = True
preprocessor_10_5_64_rec_err = VideoSparseCoding(gblock_size = BLOCK_SIZE,
block_length = BLOCK_LENGTH,
min_face_size = MIN_FACE_SIZE,
norm_face_size = NORM_FACE_SIZE,
dictionary_file_names = DICTIONARY_FILE_NAMES,
frame_step = FRAME_STEP,
extract_histograms_flag = EXTRACT_HISTOGRAMS_FLAG,
comp_reconstruct_err_flag = COMP_RECONSTRUCT_ERR_FLAG)
COMP_RECONSTRUCT_ERR_FLAG = False
preprocessor_10_5_128 = VideoSparseCoding(gblock_size = BLOCK_SIZE,
block_length = BLOCK_LENGTH,
min_face_size = MIN_FACE_SIZE,
norm_face_size = NORM_FACE_SIZE,
dictionary_file_names = DICTIONARY_FILE_NAMES,
frame_step = FRAME_STEP,
extract_histograms_flag = EXTRACT_HISTOGRAMS_FLAG,
comp_reconstruct_err_flag = COMP_RECONSTRUCT_ERR_FLAG)
\ No newline at end of file
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 27 11:33:45 2017
@author: Olegs Nikisins
"""
#==============================================================================
# Import what is needed here:
from bob.bio.base.extractor import Extractor
import numpy as np
import bob.bio.video
from bob.pad.face.extractor import ImageQualityMeasure
#==============================================================================
# Main body:
class VideoHistOfSparseCodes(Extractor, object):
"""
This class is designed to extract histograms of sparse codes.
**Parameters:**
``method`` : :py:class:`str`
A method to use in the histogram computation. Two options are available:
"mean" and "hist". Default: "mean".
"""
#==========================================================================
def __init__(self,
method = "mean"):
super(VideoHistOfSparseCodes, self).__init__(method = method)
self.method = method
# extractor to process a single image/frame:
extractor = ImageQualityMeasure()
# This extractor is used only to write and read the feature vectors.
self.video_extractor = bob.bio.video.extractor.Wrapper(extractor)
#==========================================================================
def comp_hist_of_sparse_codes(self, frames, method):
"""
Compute the histograms of sparse codes.
"""
histograms = []
for frame_data in frames:
frame = frame_data[1]
if method == "mean":
frame_codes = np.mean(frame, axis=1)
if method == "hist":
frame_codes = np.mean(frame!=0, axis=1)
for idx, row in enumerate(frame_codes):
frame_codes[idx,:] = row/np.sum(row)
hist = frame_codes.flatten()
histograms.append(hist)
return histograms
#==========================================================================
def convert_sparse_codes_to_frame_container(self, list_of_arrays):
"""
Convert an input list of arrays into Frame Container.
**Parameters:**
``list_of_arrays`` : [:py:class:`numpy.ndarray`]
A list of arrays.
**Returns:**
``frame_container`` : FrameContainer
FrameContainer containing the feature vectors.
"""
frame_container = bob.bio.video.FrameContainer() # initialize the FrameContainer
for idx, item in enumerate(list_of_arrays):
frame_container.add(idx, item) # add frame to FrameContainer
return frame_container
#==========================================================================
def reduce_features_number(self, list_of_arrays):
"""
Reduce the number of features.
"""
return_list = []
for item in list_of_arrays:
return_list.append( item[1][32:] )
return return_list
#==========================================================================
def select_reconstruction_vector(self, frames, sorted_flag):
"""
Select either sorted or non-sorted reconstruction errors.
"""
return_list = []
if sorted_flag:
for item in frames:
return_list.append( item[1][1,:] )
else:
for item in frames:
return_list.append( item[1][0,:] )
# return_list = []
#
# for item in frames:
#
# return_list.append( np.max(item[1], axis=1) )
return return_list
#==========================================================================
def __call__(self, frames):
"""
Extract feature vectors.
**Parameters:**
``frames`` : FrameContainer or string.
Data stored in the FrameContainer,
see ``bob.bio.video.utils.FrameContainer`` for further details.
**Returns:**
``frame_container`` : FrameContainer
Histograms of sparse codes stored in the FrameContainer.
"""
# histograms = self.comp_hist_of_sparse_codes(frames, self.method)
# histograms = self.reduce_features_number(frames)
sorted_flag = False
list_of_error_vecs = self.select_reconstruction_vector(frames, sorted_flag)
frame_container = self.convert_sparse_codes_to_frame_container(list_of_error_vecs)
return frame_container
#==========================================================================
def write_feature(self, frames, file_name):
"""
Writes the given data (that has been generated using the __call__ function of this class) to file.
This method overwrites the write_data() method of the Extractor class.
**Parameters:**
``frames`` :
Data returned by the __call__ method of the class.
``file_name`` : :py:class:`str`
Name of the file.
"""
self.video_extractor.write_feature(frames, file_name)
#==========================================================================
def read_feature(self, file_name):
"""
Reads the preprocessed data from file.
This method overwrites the read_data() method of the Extractor class.
**Parameters:**
``file_name`` : :py:class:`str`
Name of the file.
**Returns:**
``frames`` : :py:class:`bob.bio.video.FrameContainer`
Frames stored in the frame container.
"""
frames = self.video_extractor.read_feature(file_name)
return frames
......@@ -4,7 +4,7 @@ from .ImageQualityMeasure import ImageQualityMeasure
from .VideoDataLoader import VideoDataLoader
from .VideoQualityMeasure import VideoQualityMeasure
from .FrameDiffFeatures import FrameDiffFeatures
from .VideoHistOfSparseCodes import VideoHistOfSparseCodes
def __appropriate__(*args):
"""Says object was actually declared here, and not in the import module.
......@@ -31,6 +31,5 @@ __appropriate__(
VideoQualityMeasure,
VideoDataLoader,
FrameDiffFeatures,
VideoHistOfSparseCodes,
)
__all__ = [_ for _ in dir() if not _.startswith('_')]
......@@ -103,14 +103,6 @@ setup(
# registered preprocessors:
'bob.pad.preprocessor': [
'empty-preprocessor = bob.pad.face.config.preprocessor.filename:empty_preprocessor', # no preprocessing
# The sparse coding based preprocessors
'sparse-coding-preprocessor = bob.pad.face.config.preprocessor.video_sparse_coding:preprocessor',
'sparse-coding-preprocessor-10-5-16 = bob.pad.face.config.preprocessor.video_sparse_coding:preprocessor_10_5_16',
'sparse-coding-preprocessor-10-5-32 = bob.pad.face.config.preprocessor.video_sparse_coding:preprocessor_10_5_32',
'sparse-coding-preprocessor-10-5-64 = bob.pad.face.config.preprocessor.video_sparse_coding:preprocessor_10_5_64',
'sparse-coding-preprocessor-10-5-128 = bob.pad.face.config.preprocessor.video_sparse_coding:preprocessor_10_5_128',
'sparse-coding-preprocessor-10-5-64-rec-err = bob.pad.face.config.preprocessor.video_sparse_coding:preprocessor_10_5_64_rec_err',
],
# registered extractors:
......@@ -118,10 +110,6 @@ setup(
'video-lbp-histogram-extractor-n8r1-uniform = bob.pad.face.config.extractor.video_lbp_histogram:video_lbp_histogram_extractor_n8r1_uniform',
'video-quality-measure-galbally-msu = bob.pad.face.config.extractor.video_quality_measure:video_quality_measure_galbally_msu',
'frame-diff-feat-extr-w20-over0 = bob.pad.face.config.extractor.frame_diff_features:frame_diff_feat_extr_w20_over0',
# extractors for sparse coding:
'hist-of-sparse-codes-mean = bob.pad.face.config.extractor.video_hist_of_sparse_codes:extractor_mean',
'hist-of-sparse-codes-hist = bob.pad.face.config.extractor.video_hist_of_sparse_codes:extractor_hist',
],
# registered algorithms:
......@@ -129,66 +117,6 @@ setup(
'video-svm-pad-algorithm-10k-grid-mean-std = bob.pad.face.config.algorithm.video_svm_pad_algorithm:video_svm_pad_algorithm_10k_grid_mean_std',
'video-svm-pad-algorithm-10k-grid-mean-std-frame-level = bob.pad.face.config.algorithm.video_svm_pad_algorithm:video_svm_pad_algorithm_10k_grid_mean_std_frame_level',
'video-svm-pad-algorithm-default-svm-param-mean-std-frame-level = bob.pad.face.config.algorithm.video_svm_pad_algorithm:video_svm_pad_algorithm_default_svm_param_mean_std_frame_level',
# for grid search experiments with cascade of SVMs N = 2
'algorithm-n2-gamma-02 = bob.pad.face.config.algorithm.video_cascade_svm_pad_algorithm:algorithm_n2_gamma_02',
'algorithm-n2-gamma-01 = bob.pad.face.config.algorithm.video_cascade_svm_pad_algorithm:algorithm_n2_gamma_01',
'algorithm-n2-gamma-005 = bob.pad.face.config.algorithm.video_cascade_svm_pad_algorithm:algorithm_n2_gamma_005',
'algorithm-n2-gamma-001 = bob.pad.face.config.algorithm.video_cascade_svm_pad_algorithm:algorithm_n2_gamma_001',
'algorithm-n2-gamma-01-video-level = bob.pad.face.config.algorithm.video_cascade_svm_pad_algorithm:algorithm_n2_gamma_01_video_level',
'algorithm-n2-two-class-svm-c1-gamma-001 = bob.pad.face.config.algorithm.video_cascade_svm_pad_algorithm:algorithm_n2_two_class_svm_c1_gamma_001',
# for grid search experiments with cascade of SVMs N = 10
'algorithm-n10-gamma-01 = bob.pad.face.config.algorithm.video_cascade_svm_pad_algorithm:algorithm_n10_gamma_01',
'algorithm-n10-gamma-005 = bob.pad.face.config.algorithm.video_cascade_svm_pad_algorithm:algorithm_n10_gamma_005',
'algorithm-n10-gamma-001 = bob.pad.face.config.algorithm.video_cascade_svm_pad_algorithm:algorithm_n10_gamma_001',
'algorithm-n10-gamma-0005 = bob.pad.face.config.algorithm.video_cascade_svm_pad_algorithm:algorithm_n10_gamma_0005',
# for grid search experiments with cascade of SVMs N = 20
'algorithm-n20-gamma-05 = bob.pad.face.config.algorithm.video_cascade_svm_pad_algorithm:algorithm_n20_gamma_05',
'algorithm-n20-gamma-02 = bob.pad.face.config.algorithm.video_cascade_svm_pad_algorithm:algorithm_n20_gamma_02',
'algorithm-n20-gamma-01 = bob.pad.face.config.algorithm.video_cascade_svm_pad_algorithm:algorithm_n20_gamma_01',
'algorithm-n20-gamma-005 = bob.pad.face.config.algorithm.video_cascade_svm_pad_algorithm:algorithm_n20_gamma_005',
'algorithm-n20-gamma-001 = bob.pad.face.config.algorithm.video_cascade_svm_pad_algorithm:algorithm_n20_gamma_001',
'algorithm-n20-gamma-0005 = bob.pad.face.config.algorithm.video_cascade_svm_pad_algorithm:algorithm_n20_gamma_0005',
'algorithm-n20-gamma-0001 = bob.pad.face.config.algorithm.video_cascade_svm_pad_algorithm:algorithm_n20_gamma_0001',
# for grid search experiments using GMM
'algorithm-gmm-2 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_2',
'algorithm-gmm-3 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_3',
'algorithm-gmm-4 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_4',
'algorithm-gmm-5 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_5',
'algorithm-gmm-6 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_6',
'algorithm-gmm-7 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_7',
'algorithm-gmm-8 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_8',
'algorithm-gmm-9 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_9',
'algorithm-gmm-10 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_10',
'algorithm-gmm-12 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_12',
'algorithm-gmm-14 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_14',
'algorithm-gmm-16 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_16',
'algorithm-gmm-18 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_18',
'algorithm-gmm-20 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_20',
'algorithm-gmm-25 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_25',
'algorithm-gmm-30 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_30',
'algorithm-gmm-35 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_35',
'algorithm-gmm-40 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_40',
'algorithm-gmm-45 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_45',
'algorithm-gmm-50 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_50',
'algorithm-gmm-60 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_60',
'algorithm-gmm-70 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_70',
'algorithm-gmm-80 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_80',
'algorithm-gmm-90 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_90',
'algorithm-gmm-100 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_100',
'algorithm-gmm-50-0 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_50_0',
'algorithm-gmm-50-1 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_50_1',
'algorithm-gmm-50-2 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_50_2',
'algorithm-gmm-50-3 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_50_3',
'algorithm-gmm-50-4 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_50_4',
'algorithm-gmm-50-5 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_50_5',
'algorithm-gmm-50-6 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_50_6',
'algorithm-gmm-50-7 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_50_7',
'algorithm-gmm-50-8 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_50_8',
'algorithm-gmm-50-9 = bob.pad.face.config.algorithm.video_gmm_pad_algorithm:algorithm_gmm_50_9',
],
# registered grid configurations:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment