Commit 46d2efd8 authored by E144069X's avatar E144069X

Added args to vary the threshold in temporal accuracy

parent 205be22c
......@@ -101,7 +101,7 @@ def updateMetrDict(metrDict,metrDictSample):
return metrDict
def binaryToMetrics(output,target,transition_matrix=None,videoNames=None,onlyPairsCorrelation=True,videoMode=True):
def binaryToMetrics(output,target,paramDict,transition_matrix=None,videoNames=None,onlyPairsCorrelation=True,videoMode=True):
''' Computes metrics over a batch of targets and predictions
Args:
......@@ -138,11 +138,11 @@ def binaryToMetrics(output,target,transition_matrix=None,videoNames=None,onlyPai
metDict = {"Accuracy":acc,'Accuracy (Viterbi)':accViterb}
if not videoNames is None and videoMode:
metDict["Correlation"],metDict["Temp Accuracy"] = correlation(pred,target,videoNames,onlyPairs=onlyPairsCorrelation)
metDict["Correlation"],metDict["Temp Accuracy"] = correlation(pred,target,videoNames,paramDict,onlyPairs=onlyPairsCorrelation)
return metDict
def correlation(predBatch,target,videoNames,onlyPairs=True):
def correlation(predBatch,target,videoNames,paramDict,onlyPairs=True):
''' Computes the times at which the model predicts the developpement phase is changing and
compare it to the real times where the phase is changing. Computes a correlation between those
two list of numbers.
......@@ -158,19 +158,26 @@ def correlation(predBatch,target,videoNames,onlyPairs=True):
phasesTargDict = phaseToTime(target[0],timeElapsedTensor)
commonPhases = list(set(list(phasesPredDict.keys())).intersection(set(list(phasesTargDict.keys()))))
timePairs = []
accuracy = 0
for phase in commonPhases:
timePairs.append((phasesPredDict[phase],phasesTargDict[phase]))
if np.abs(phasesPredDict[phase]-phasesTargDict[phase]) <= 1:
accuracy +=1
accuracy /= len(phasesTargDict.keys())
tempDic = paramDict["Temp Accuracy"]
step = (tempDic["maxThres"]-tempDic["minThres"])/tempDic["thresNb"]
thresList = np.arange(tempDic["minThres"],tempDic["maxThres"],step)
accList = []
for i in range(len(thresList)):
timePairs = []
accuracy = 0
for phase in commonPhases:
timePairs.append((phasesPredDict[phase],phasesTargDict[phase]))
if np.abs(phasesPredDict[phase]-phasesTargDict[phase]) <= thresList[i]:
accuracy +=1
accuracy /= len(phasesTargDict.keys())
accList.append(accuracy)
if onlyPairs:
return timePairs,accuracy
return timePairs,accList
else:
timePairs = np.array(timePairs)
return np.corrcoef(timePairs[:,0],timePairs[:,1])[0,1],accuracy
return np.corrcoef(timePairs[:,0],timePairs[:,1])[0,1],accList
def phaseToTime(phaseList,timeElapsedTensor):
changingPhaseFrame = np.concatenate(([1],(phaseList[1:]-phaseList[:-1]) > 0),axis=0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment