def createGTUnique(classesDict, length, gtList): """ Create ground truth array where only one label is allowed per point @param classesDict: @param length: length of the final array (=length of prediction array) @param gtList: @return: """ y_GT = np.empty([length]) y_GT.fill(-1) #-1 corresponds to no label given classesNotTrained = [] for i in range(len(gtList)): """ Fill array from start to end of each ground truth label with the correct label: """ if gtList[i][2] == "start": tmpContext = gtList[i][1] start = getIndex(float(gtList[i][0])) # Find the end time of this context: for j in range(i,len(gtList)): if ((gtList[j][1] == tmpContext) and (gtList[j][2] == "end")): end = getIndex(float(gtList[j][0])) if end >= y_GT.shape[0]: end = y_GT.shape[0] - 1 """ Fill ground truth array, and check if our classifier was trained with all labels of the test file, if not give warning: """ if gtList[i][1] not in classesDict.keys(): classesNotTrained.append(gtList[i][1]) y_GT[start:end+1].fill(-1) else: y_GT[start:end+1].fill(classesDict[tmpContext]) break if classesNotTrained: for el in set(classesNotTrained): print("The classifier wasn't trained with class '" + el + "'. It will not be considered for testing.") return y_GT
def createGTMulti(classesDict, length, gtList): """ Create ground truth array that allows multiple labels per point @param classesDict: @param length: length of the final array (=length of prediction array) @param gtList: @return: """ """ Create array containing label for sample point: """ n_maxLabels = 5 #maximum number of labels that can be assign to one point y_GT = np.empty([length,n_maxLabels]) y_GT.fill(-1) #-1 corresponds to no label given classesNotTrained = [] for i in range(len(gtList)): """ Fill array from start to end of each ground truth label with the correct label: """ gtList[i][2] if gtList[i][2] == "start": tmpContext = gtList[i][1] start = getIndex(float(gtList[i][0])) # Find the end time of this context: for j in range(i,len(gtList)): if ((gtList[j][1] == tmpContext) and (gtList[j][2] == "end")): end = getIndex(float(gtList[j][0])) if end >= y_GT.shape[0]: end = y_GT.shape[0] - 1 """ Fill ground truth array, and check if our classifier was trained with all labels of the test file, if not give warning: """ if (gtList[i][1] not in classesDict.keys()): classesNotTrained.append(gtList[i][1]) else: # Check if we can write into the first column of the y_GT array: if ((len(np.unique(y_GT[start:end+1,0])) == 1) and (np.unique(y_GT[start:end+1,0])[0] == -1)): y_GT[start:end+1,0].fill(classesDict[gtList[i][1]]) # Check if we can write into the second column of the y_GT array: elif ((len(np.unique(y_GT[start:end+1,1])) == 1) and (np.unique(y_GT[start:end+1,1])[0] == -1)): y_GT[start:end+1,1].fill(classesDict[gtList[i][1]]) # Check if we can write into the third column of the y_GT array: elif ((len(np.unique(y_GT[start:end+1,2])) == 1) and (np.unique(y_GT[start:end+1,2])[0] == -1)): y_GT[start:end+1,2].fill(classesDict[gtList[i][1]]) # Check if we can write into the third column of the y_GT array: elif ((len(np.unique(y_GT[start:end+1,3])) == 1) and (np.unique(y_GT[start:end+1,3])[0] == -1)): y_GT[start:end+1,3].fill(classesDict[gtList[i][1]]) # Check if we can write into the third column of the y_GT array: elif ((len(np.unique(y_GT[start:end+1,4])) == 1) and (np.unique(y_GT[start:end+1,4])[0] == -1)): y_GT[start:end+1,4].fill(classesDict[gtList[i][1]]) else: pdb.set_trace() print("Problem occurred when filling ground truth array!") break if classesNotTrained: for el in set(classesNotTrained): print("The classifier wasn't trained with class '" + el + "'. It will not be considered for testing.") return y_GT