Пример #1
0
    def model_evaluate(self):
        # evaluate the model

        ## preprocess: find test_users and candidate_items
        test_users = np.unique(self.test_tuple[:,0])                     # all users in the test set
        allItems_train = np.unique(self.train_tuple[:,1])                # all items in the train set
        allItems_test = np.unique(self.test_tuple[:,1])                  # all items in the test set
        candidate_items = np.union1d(allItems_train,allItems_test)  # all items in the train and test set

        recEval = Evaluate(self.userFactors,self.itemFactors,self.train_matrix,self.test_matrix,test_users,candidate_items)
        ret = recEval.CalcMetrics()
        print 'AUC =',ret[0],'Prec@5 =',ret[1],'Prec@10 =',ret[2], 'MAP =', ret[3], 'Rec@5 =', ret[4], 'Rec@10 =', ret[5], 'NDCG =', ret[6], 'MRR =', ret[7]
        return ret
Пример #2
0
def Utility(GT_path, evaluated_path,num_path):
    '''
    Function to evaulate the your resutls for SBMnet dataset, this code will generate a 'cm.txt' file in your result path to save all the metrics.
    input:  GT_path: the path of the groundtruth folder.
    evaluated_path: the path of your evaluated results folder.
    '''
    result_file = os.path.join(evaluated_path, 'cm.txt')

    with open(result_file, 'w') as fid:
        fid.write('\t\timage_name\tPSNR\tSSIM\tMSE\tMAE\r\n')

    m_AGE = 0
    m_pEPs = 0
    m_pCEPs = 0
    m_MSSSIM = 0
    m_PSNR = 0
    m_SSIM = 0
    m_MSE = 0
    m_MAE = 0
    # ipdb.set_trace()
    
    c_AGE = 0
    c_pEPs = 0
    c_pCEPs = 0
    c_MSSSIM = 0
    c_PSNR = 0
    c_SSIM = 0
    c_MSE = 0
    c_MAE = 0
        
    image_num = 0
    
    for root, dirs, files in os.walk(evaluated_path):
        MSSSIM_max = 0
        for i in files:
            # 判断是否以.jpg结尾
            if i.endswith('.JPG') or i.endswith('.jpg') or i.endswith('.PNG') or i.endswith('.png'):
                picname = i.split('.')[0]
                print("picname:",picname)
                num = picname.split('_')[0]
            
                #if more than one GT exists for the video, we keep the
                #metrics with the highest MSSSIM value.
                if(num_path==2000):
                    GT_img = scipy.misc.imread(GT_path+num+".jpg")       #background ground truth
                    result_img = scipy.misc.imread(evaluated_path+num+".jpg")
                if(num_path==1080):
                    GT_img = scipy.misc.imread(GT_path+num+"_gt.png")       #background ground truth
                    result_img = scipy.misc.imread(evaluated_path+picname+".png")
               
                AGE, pEPs, pCEPs, MSSSIM, PSNR, SSIM, MSE,MAE = Evaluate.Evaluate(GT_img, result_img);
                if MSSSIM > MSSSIM_max:
                    MSSSIM_max = MSSSIM
                v_AGE = AGE
                v_pEPs = pEPs
                v_pCEPs = pCEPs
                v_MSSSIM = MSSSIM
                v_PSNR = PSNR
                v_SSIM = SSIM
                v_MSE = MSE
                v_MAE = MAE
                
                
                #save the video evaluation results
                with open(result_file, 'a+') as fid:
                    fid.write('\t\t' + picname + ':\t' + str(round(v_PSNR, 4)) + '\t' + str(round(v_SSIM, 4)) + '\t' + str(round(v_MSE, 4)) + '\t' + str(round(v_MAE, 4)) + '\r\n')

                c_AGE = c_AGE + v_AGE
                c_pEPs = c_pEPs + v_pEPs
                c_pCEPs = c_pCEPs + v_pCEPs
                c_MSSSIM = c_MSSSIM + v_MSSSIM
                c_PSNR = c_PSNR + v_PSNR
                c_SSIM = c_SSIM + v_SSIM
                c_MSE = c_MSE + v_MSE
                c_MAE = c_MAE + v_MAE
                image_num = image_num + 1

        c_AGE = c_AGE / float(image_num)
        c_pEPs = c_pEPs / float(image_num)
        c_pCEPs = c_pCEPs / float(image_num)
        c_MSSSIM = c_MSSSIM / float(image_num)
        c_PSNR = c_PSNR / float(image_num)
        c_SSIM = c_SSIM / float(image_num)
        c_MSE = c_MSE / float(image_num)
        c_MAE = c_MAE / float(image_num)

        #save the category evaluation results
        with open(result_file, 'a+') as fid:
            fid.write('\t\timage_name\tPSNR\tSSIM\tMSE\tMAE\r\n')
            fid.write('\r\n' + 'gt' + '_AVG::\t\t' + str(round(c_PSNR, 4)) + '\t' + str(round(c_SSIM, 4)) + '\t' + str(round(c_MSE, 4))+ '\t' + str(round(c_MAE, 4)) + '\r\n\r\n')

        m_AGE = m_AGE + c_AGE
        m_pEPs = m_pEPs + c_pEPs
        m_pCEPs = m_pCEPs + c_pCEPs
        m_MSSSIM = m_MSSSIM + c_MSSSIM
        m_PSNR = m_PSNR + c_PSNR
        m_SSIM = m_SSIM + c_SSIM
        m_MSE = m_MSE + c_MSE
        m_MAE = m_MAE + c_MAE

   

    with open(result_file, 'a+') as fid:
        fid.write('Total:\t\t\t' + str(round(m_PSNR, 4)) + '\t' + str(round(m_SSIM*100, 4)) + '\t' + str(round(m_MSE, 4)) + '\t' + str(round(m_MAE*100, 4)) + '\r\n')
Пример #3
0
            essay = Essay(text, prompt, grade, stop_words)

            essay.set_words()
            #essay.get_tagged()
            essay.grammar = grammar
            #print(files)

            c1, a = essay.get_length()
            b = essay.get_spellingmistakes()
            #c1 = essay.get_sv_agreement()
            c2 = essay.get_verb_usage()
            c3 = essay.get_sentence_formation()
            d1 = essay.get_coherence()
            d2 = essay.get_topic_relevance()

            evaluate = Evaluate(a, b, c1, c2, c3, d1, d2)
            final_score = evaluate.get_score()

            if not files in results_dict:
                results_dict[files] = [
                    a, b, c1, c2, c3, d1, d2, final_score, grade
                ]

# Dump raw values to csv
with open('../dump/results.csv', 'w') as csv_file:
    writer = csv.writer(csv_file)
    for key, value in results_dict.items():
        li = []
        li.append(key)
        for v in value:
            li.append(v)
Пример #4
0
    args = parser.parse_args()
    stock_code = args.code
    expect_tag = args.label
    method = args.method

    stockcodes_list = ['000001']
    filenames_list = ["5min/000001.csv"]

    expect_day = '2018-01-18'
    his_num = 5
    # print(stock_code)

    fast_data_searcher = FastResearchData(stock_code, stockcodes_list,
                                          filenames_list)
    stock_data = fast_data_searcher.run()

    # calculator = CalCorrMatrix()
    data_preparer = PreProcessor(stock_data, expect_day, expect_tag, his_num)
    valid_set, train_set, valid_tag, train_tag = data_preparer.run()

    regress = Regression(valid_set, train_set, valid_tag, train_tag, method)
    pred_result = regress.run()

    print(pred_result)

    evaluator = Evaluate(valid_set, valid_tag, pred_result, expect_tag, method)
    evaluator.run()

    drawer = PicDrawer(method, valid_tag, pred_result)
    drawer.picDrawer()
Пример #5
0
def Utility(GT_path, evaluated_path):
    '''
    Function to evaulate the your resutls for SBMnet dataset, this code will generate a 'cm.txt' file in your result path to save all the metrics.
    input:  GT_path: the path of the groundtruth folder.
    evaluated_path: the path of your evaluated results folder.
    '''

    category_list = [
        'backgroundMotion', 'basic', 'clutter', 'illuminationChanges',
        'intermittentMotion', 'jitter', 'veryLong', 'veryShort'
    ]
    category_num = len(category_list)
    result_file = os.path.join(evaluated_path, 'cm.txt')

    with open(result_file, 'w') as fid:
        fid.write('\t\tvideo\tAGE\tpEPs\tpCEPs\tMSSSIM\tPSNR\tCQM\r\n')

    m_AGE = 0
    m_pEPs = 0
    m_pCEPs = 0
    m_MSSSIM = 0
    m_PSNR = 0
    m_CQM = 0
    ipdb.set_trace()
    for category in category_list:
        print(category)
        c_AGE = 0
        c_pEPs = 0
        c_pCEPs = 0
        c_MSSSIM = 0
        c_PSNR = 0
        c_CQM = 0

        GT_category_path = os.path.join(GT_path, category)
        evaluated_category_path = os.path.join(evaluated_path, category)

        video_num = 0

        with open(result_file, 'a+') as fid:
            fid.write(category[0:min(8, len(category))] + ': \r\n')

        for video in os.listdir(GT_category_path):

            GT_video_path = os.path.join(GT_category_path, video)
            GTs = os.listdir(os.path.join(GT_video_path))
            GT_exist = False
            MSSSIM_max = 0

            for file in GTs:
                if file.endswith('.jpg'):
                    GT_exist = True

                    #if more than one GT exists for the video, we keep the
                    #metrics with the highest MSSSIM value.

                    GT_img = scipy.misc.imread(
                        os.path.join(GT_video_path,
                                     file))  #background ground truth
                    evaluated_video_path = os.path.join(
                        evaluated_category_path, video)
                    files = os.listdir(os.path.join(evaluated_video_path))

                    for file in files:  #read the first image in the video folder
                        if file.endswith('.jpg'):
                            result_img = scipy.misc.imread(
                                os.path.join(evaluated_video_path, file))
                            break
                    ipdb.set_trace()

                    AGE, pEPs, pCEPs, MSSSIM, PSNR, CQM = Evaluate.Evaluate(
                        GT_img, result_img)
                    if MSSSIM > MSSSIM_max:
                        v_AGE = AGE
                        v_pEPs = pEPs
                        v_pCEPs = pCEPs
                        v_MSSSIM = MSSSIM
                        v_PSNR = PSNR
                        v_CQM = CQM
                        MSSSIM_max = MSSSIM
            if GT_exist:
                #save the video evaluation results
                with open(result_file, 'a+') as fid:
                    fid.write('\t\t' + video[0:min(5, len(video))] + ':\t' +
                              str(round(v_AGE, 4)) + '\t' +
                              str(round(v_pEPs, 4)) + '\t' +
                              str(round(v_pCEPs, 4)) + '\t' +
                              str(round(v_MSSSIM, 4)) + '\t' +
                              str(round(v_PSNR, 4)) + '\t' +
                              str(round(v_CQM, 4)) + '\r\n')

                c_AGE = c_AGE + v_AGE
                c_pEPs = c_pEPs + v_pEPs
                c_pCEPs = c_pCEPs + v_pCEPs
                c_MSSSIM = c_MSSSIM + v_MSSSIM
                c_PSNR = c_PSNR + v_PSNR
                c_CQM = c_CQM + v_CQM
                video_num = video_num + 1

        c_AGE = c_AGE / float(video_num)
        c_pEPs = c_pEPs / float(video_num)
        c_pCEPs = c_pCEPs / float(video_num)
        c_MSSSIM = c_MSSSIM / float(video_num)
        c_PSNR = c_PSNR / float(video_num)
        c_CQM = c_CQM / float(video_num)

        #save the category evaluation results
        with open(result_file, 'a+') as fid:
            fid.write('\r\n' + category[0:min(8, len(category))] +
                      '_AVG::\t\t' + str(round(c_AGE, 4)) + '\t' +
                      str(round(c_pEPs, 4)) + '\t' + str(round(c_pCEPs, 4)) +
                      '\t' + str(round(c_MSSSIM, 4)) + '\t' +
                      str(round(c_PSNR, 4)) + '\t' + str(round(c_CQM, 4)) +
                      '\r\n\r\n')

        m_AGE = m_AGE + c_AGE
        m_pEPs = m_pEPs + c_pEPs
        m_pCEPs = m_pCEPs + c_pCEPs
        m_MSSSIM = m_MSSSIM + c_MSSSIM
        m_PSNR = m_PSNR + c_PSNR
        m_CQM = m_CQM + c_CQM

    #save the method evaluation results
    m_AGE = m_AGE / float(category_num)
    m_pEPs = m_pEPs / float(category_num)
    m_pCEPs = m_pCEPs / float(category_num)
    m_MSSSIM = m_MSSSIM / float(category_num)
    m_PSNR = m_PSNR / float(category_num)
    m_CQM = m_CQM / float(category_num)

    with open(result_file, 'a+') as fid:
        fid.write('Total:\t\t\t' + str(round(m_AGE, 4)) + '\t' +
                  str(round(m_pEPs, 4)) + '\t' + str(round(m_pCEPs, 4)) +
                  '\t' + str(round(m_MSSSIM, 4)) + '\t' +
                  str(round(m_PSNR, 4)) + '\t' + str(round(m_CQM, 4)) + '\r\n')