Skip to content
Snippets Groups Projects

Added unit tests for all preprocessors, extractors, algorithms, excluding qualitymeasure related stuff

Merged Olegs NIKISINS requested to merge dev_branch into master
9 files
+ 361
56
Compare changes
  • Side-by-side
  • Inline
Files
9
@@ -210,9 +210,9 @@ class VideoSvmPadAlgorithm(Algorithm):
@@ -210,9 +210,9 @@ class VideoSvmPadAlgorithm(Algorithm):
else:
else:
uniform_step = features.shape[0]/n_samples
uniform_step = np.int(features.shape[0]/n_samples)
features_subset = features[0 : uniform_step*n_samples : uniform_step, :]
features_subset = features[0 : np.int(uniform_step*n_samples) : uniform_step, :]
return features_subset
return features_subset
@@ -240,7 +240,7 @@ class VideoSvmPadAlgorithm(Algorithm):
@@ -240,7 +240,7 @@ class VideoSvmPadAlgorithm(Algorithm):
Selected subset of cross-validation features.
Selected subset of cross-validation features.
"""
"""
half_samples_num = features.shape[0]/2
half_samples_num = np.int(features.shape[0]/2)
features_train = features[ 0 : half_samples_num, : ]
features_train = features[ 0 : half_samples_num, : ]
features_cv = features[ half_samples_num : 2 * half_samples_num + 1, : ]
features_cv = features[ half_samples_num : 2 * half_samples_num + 1, : ]
@@ -446,7 +446,8 @@ class VideoSvmPadAlgorithm(Algorithm):
@@ -446,7 +446,8 @@ class VideoSvmPadAlgorithm(Algorithm):
machine_type = 'C_SVC', kernel_type = 'RBF',
machine_type = 'C_SVC', kernel_type = 'RBF',
trainer_grid_search_params = { 'cost': [2**p for p in range(-5, 16, 2)], 'gamma': [2**p for p in range(-15, 4, 2)]},
trainer_grid_search_params = { 'cost': [2**p for p in range(-5, 16, 2)], 'gamma': [2**p for p in range(-15, 4, 2)]},
mean_std_norm_flag = False,
mean_std_norm_flag = False,
projector_file = ""):
projector_file = "",
 
save_debug_data_flag = True):
"""
"""
First, this function tunes the hyper-parameters of the SVM classifier using
First, this function tunes the hyper-parameters of the SVM classifier using
grid search on the sub-sets of training data. Train and cross-validation
grid search on the sub-sets of training data. Train and cross-validation
@@ -487,6 +488,10 @@ class VideoSvmPadAlgorithm(Algorithm):
@@ -487,6 +488,10 @@ class VideoSvmPadAlgorithm(Algorithm):
be save in this path. This file contains information, which might be
be save in this path. This file contains information, which might be
usefull for debugging.
usefull for debugging.
 
``save_debug_data_flag`` : :py:class:`bool`
 
Save the data, which might be usefull for debugging if ``True``.
 
Default: ``True``.
 
**Returns:**
**Returns:**
``machine`` : object
``machine`` : object
@@ -544,16 +549,18 @@ class VideoSvmPadAlgorithm(Algorithm):
@@ -544,16 +549,18 @@ class VideoSvmPadAlgorithm(Algorithm):
setattr(trainer, key, selected_params[key]) # set the params of trainer
setattr(trainer, key, selected_params[key]) # set the params of trainer
# Save the data, which is usefull for debugging.
# Save the data, which is usefull for debugging.
debug_file = os.path.join( os.path.split(projector_file)[0], "debug_data.hdf5" )
if save_debug_data_flag:
debug_dict = {}
debug_dict['precisions_train'] = precisions_train
debug_file = os.path.join( os.path.split(projector_file)[0], "debug_data.hdf5" )
debug_dict['precisions_cv'] = precisions_cv
debug_dict = {}
debug_dict['cost'] = selected_params['cost']
debug_dict['precisions_train'] = precisions_train
debug_dict['gamma'] = selected_params['gamma']
debug_dict['precisions_cv'] = precisions_cv
f = bob.io.base.HDF5File(debug_file, 'w') # open hdf5 file to save the debug data
debug_dict['cost'] = selected_params['cost']
for key in debug_dict.keys():
debug_dict['gamma'] = selected_params['gamma']
f.set(key, debug_dict[key])
f = bob.io.base.HDF5File(debug_file, 'w') # open hdf5 file to save the debug data
del f
for key in debug_dict.keys():
 
f.set(key, debug_dict[key])
 
del f
# training_features[0] - training features for the REAL class.
# training_features[0] - training features for the REAL class.
real = self.convert_list_of_frame_cont_to_array(training_features[0]) # output is array
real = self.convert_list_of_frame_cont_to_array(training_features[0]) # output is array
Loading