Skip to content

Commit

Permalink
adding documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Anwarvic committed May 6, 2019
1 parent 7b0bce4 commit 05eb884
Showing 1 changed file with 32 additions and 38 deletions.
70 changes: 32 additions & 38 deletions model_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


class SidekitModel():
"""This class is just an interface for my models to inherit"""

def __init__(self, conf_filepath):
self.conf = parse_yaml(conf_filepath)
Expand All @@ -19,6 +20,16 @@ def __init__(self, conf_filepath):


def createFeatureServer(self, group=None):
"""
This methos is used to crate FeatureServer object which is an object for
features management. It loads datasets from a HDF5 files ( produced by
a FeaturesExtractor object)
Args:
group (string): the group of features to manage. If None, then it
will create a generic FeatureServer over the feat directory.
Returns:
server: which is the FeatureServer object
"""
if group:
feat_dir = os.path.join(self.BASE_DIR, "feat", group)
else:
Expand Down Expand Up @@ -52,24 +63,24 @@ def evaluate(self):
def plotDETcurve(self):
pass

def getAccuracy(self, speakers, test_files, scores, mode=2, threshold=0):
def getAccuracy(self, speakers, test_files, scores, threshold=0):
"""
This private method is used to get the accuracy of a model
given five pieces of information:
-> speakers: list of speakers
-> test_files: list of filenames that used to evaluate model
-> scores: score numpy matrix obtained by the model
-> mode: which is one of these values [0, 1, 2] where:
-> 0: means get verification accuracy.
-> 1: means get recognition accuracy.
-> 2: means get both accuracy, verification and recognition.
-> threshold: the value above which we will consider the verification
This method is used to get the accuracy of a model over a bunch of data
files. The accuracy is returned in percentage.
NOTE: The file is considered to be correct if the correct speaker has the
max score (that's in case the speaker is in the training set). And also
if the max score is below threshold (that's in case the speaker is not
in the training set).
Args
speakers: list of speakers
test_files: list of filenames that used to evaluate model
scores: the score numpy matrix obtained by the model
threshold: the value above which we will consider the verification
is done correctly. In other words, if the score>threshold, then
the answer is considered; otherwise, the answer is not considered
And it should return the accuracy of the model in percentage
Returns
accuracy (float): accuracy of the model in percentage
"""
assert mode in [0, 1, 2],\
"The model variable must be one of these values[0, 1, 2]"
assert scores.shape == (len(speakers), len(test_files)),\
"The dimensions of the input don't match"
accuracy = 0.
Expand All @@ -80,28 +91,11 @@ def getAccuracy(self, speakers, test_files, scores, mode=2, threshold=0):
test_filename = test_filename.decode() #convert from byte to string
actual_speaker = test_filename.split("/")[-1].split(".")[0]
predicted_speaker = speakers[max_indices[idx]]
#TODO:
########## JUST VERIFICATION ##########
if mode == 0:
if max_scores[idx] < threshold:
continue
else:
accuracy += 1.
########## JUST RECOGNITION ##########
elif mode == 1:
#skip speakers outside the training
#evaluate the test data file
if max_scores[idx] < threshold:
if actual_speaker not in speakers:
continue
else:
if predicted_speaker == actual_speaker:
accuracy += 1.
########## VERIFICATION & RECOGNITION ##########
elif mode == 2:
#skip speakers outside the training
if max_scores[idx] < threshold:
continue
else:
if predicted_speaker == actual_speaker:
accuracy += 1.

return accuracy/len(test_files)
accuracy += 1
else:
if predicted_speaker == actual_speaker:
accuracy += 1.
return accuracy*100./len(test_files)

0 comments on commit 05eb884

Please sign in to comment.