pyanomaly/datatools/evaluate/utils.py
def compute_auc_psnr(loss_file, logger, cfg, score_type='normal'):
    '''
    For psnr, score_type is always 'normal', means that the higher PSNR, the higher normality 
    '''
    if not os.path.isdir(loss_file):
        loss_file_list = [loss_file]
    else:
        loss_file_list = os.listdir(loss_file)
        loss_file_list = [os.path.join(loss_file, sub_loss_file) for sub_loss_file in loss_file_list]

    optimal_results = RecordResult()
    DECIDABLE_IDX = cfg.DATASET.decidable_idx
    for sub_loss_file in loss_file_list:
        # the name of dataset, loss, and ground truth
        dataset, psnr_records, score_records, gt, num_videos = load_pickle_results(loss_file=sub_loss_file, cfg=cfg)

        # the number of videos
        assert num_videos == len(score_records), 'The num of video is not equal'

        scores = np.array([], dtype=np.float32)
        labels = np.array([], dtype=np.int8)
        
        # video normalization
        for i in range(num_videos):
            distance = psnr_records[i]
            scores = np.concatenate((scores, distance[DECIDABLE_IDX:]), axis=0)
            labels = np.concatenate((labels, gt[i][DECIDABLE_IDX:]), axis=0)
        '''
        Normalization is in the process of calculate the scores, instead of beforing getting the AUC
        '''
        # if cfg.DATASET.score_normalize:
        #     smin = scores.min()
        #     smax = scores.max()
        #     scores = scores - scores.min()  # scores = (scores - min) / (max - min)
        #     scores = scores / (smax - smin)
        fpr, tpr, thresholds = metrics.roc_curve(labels, scores, pos_label=0)
        auc = metrics.auc(fpr, tpr)

        results = RecordResult(fpr, tpr, thresholds, auc, dataset, sub_loss_file)

        if optimal_results < results:
            optimal_results = results

        if os.path.isdir(loss_file):
            print(results)
    logger.info(f'##### optimal result and model = {optimal_results}')
    return optimal_results

    For psnr, score_type is always 'normal', means that the higher PSNR, the higher normality 
    
For psnr, score_type is always 'normal', means that the higher PSNR, the higher normality
For psnr score_type is always ' normal ' means that the higher PSNR the higher normality
def compute_auc_psnr(loss_file, logger, cfg, score_type='normal'):
    if not os.path.isdir(loss_file):
        loss_file_list = [loss_file]
    else:
        loss_file_list = os.listdir(loss_file)
        loss_file_list = [os.path.join(loss_file, sub_loss_file) for sub_loss_file in loss_file_list]
    optimal_results = RecordResult()
    DECIDABLE_IDX = cfg.DATASET.decidable_idx
    for sub_loss_file in loss_file_list:
        dataset, psnr_records, score_records, gt, num_videos = load_pickle_results(loss_file=sub_loss_file, cfg=cfg)
        assert num_videos == len(score_records), 'The num of video is not equal'
        scores = np.array([], dtype=np.float32)
        labels = np.array([], dtype=np.int8)
        for i in range(num_videos):
            distance = psnr_records[i]
            scores = np.concatenate((scores, distance[DECIDABLE_IDX:]), axis=0)
            labels = np.concatenate((labels, gt[i][DECIDABLE_IDX:]), axis=0)
        fpr, tpr, thresholds = metrics.roc_curve(labels, scores, pos_label=0)
        auc = metrics.auc(fpr, tpr)
        results = RecordResult(fpr, tpr, thresholds, auc, dataset, sub_loss_file)
        if optimal_results < results:
            optimal_results = results
        if os.path.isdir(loss_file):
            print(results)
    logger.info(f'##### optimal result and model = {optimal_results}')
    return optimal_results
def compute_auc_psnr ( loss_file , logger , cfg , score_type = 'normal' ) : if not os . path . isdir ( loss_file ) : loss_file_list = [ loss_file ] else : loss_file_list = os . listdir ( loss_file ) loss_file_list = [ os . path . join ( loss_file , sub_loss_file ) for sub_loss_file in loss_file_list ] optimal_results = RecordResult ( ) DECIDABLE_IDX = cfg . DATASET . decidable_idx for sub_loss_file in loss_file_list : dataset , psnr_records , score_records , gt , num_videos = load_pickle_results ( loss_file = sub_loss_file , cfg = cfg ) assert num_videos == len ( score_records ) , 'The num of video is not equal' scores = np . array ( [ ] , dtype = np . float32 ) labels = np . array ( [ ] , dtype = np . int8 ) for i in range ( num_videos ) : distance = psnr_records [ i ] scores = np . concatenate ( ( scores , distance [ DECIDABLE_IDX : ] ) , axis = 0 ) labels = np . concatenate ( ( labels , gt [ i ] [ DECIDABLE_IDX : ] ) , axis = 0 ) '''
        Normalization is in the process of calculate the scores, instead of beforing getting the AUC
        ''' fpr , tpr , thresholds = metrics . roc_curve ( labels , scores , pos_label = 0 ) auc = metrics . auc ( fpr , tpr ) results = RecordResult ( fpr , tpr , thresholds , auc , dataset , sub_loss_file ) if optimal_results < results : optimal_results = results if os . path . isdir ( loss_file ) : print ( results ) logger . info ( f'##### optimal result and model = {optimal_results}' ) return optimal_results
For psnr, score_type is always 'normal', means that the higher PSNR, the higher normality
For psnr score_type is always ' normal ' means that the higher PSNR the higher normality
'''
    For psnr, score_type is always 'normal', means that the higher PSNR, the higher normality 
    ''' # the name of dataset, loss, and ground truth
 # the number of videos
 # video normalization
 '''
        Normalization is in the process of calculate the scores, instead of beforing getting the AUC
        ''' # if cfg.DATASET.score_normalize:
 #     smin = scores.min()
 #     smax = scores.max()
 #     scores = scores - scores.min()  # scores = (scores - min) / (max - min)
 #     scores = scores / (smax - smin)

loss_file
logger
cfg
score_type