Skip to content

Commit

Permalink
generalize prediction averaging
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidDoukhan committed Jun 11, 2023
1 parent 5483d0d commit 9d38027
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions inaFaceAnalyzer/face_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

import numpy as np
import pandas as pd
import re
import numbers
from abc import ABC, abstractmethod
import tensorflow
Expand Down Expand Up @@ -109,16 +110,22 @@ def output_cols(self):
self._output_cols = list(self(fake_input, False).columns)
return self._output_cols

def average_results(self, df):
def average_results(self, df, groupcol='face_id'):
if len(df) == 0:
for c in self.output_cols:
df[c] = []

# remove pre-existing averages (in case of re-clustering)
for k in df.columns:
if re.match('.*_avg$', k):
del df[k]

# columns to be averaged end with _decfunc (decision functions)
cols = [e for e in df.columns if e.endswith('_decfunc')]
gbm = df.groupby('face_id')[cols].mean()
gbm = df.groupby(groupcol)[cols].mean()
gbm = self.decisionfunction2labels(gbm)

return df.join(gbm, on='face_id', rsuffix='_avg')
return df.join(gbm, on=groupcol, rsuffix='_avg')

# TODO : Keras trick for async READ ?
# bench execution time : time spent in read/exce . CPU vs GPU
Expand Down

0 comments on commit 9d38027

Please sign in to comment.