Esempio n. 1
0
def accuPerPlate(nom, c_list, n_big_fold, n_fold, tdict, plate, sol, newFrameLot): 
    r = np.zeros(shape=(len(c_list),len(EVENTS), 2), dtype=np.int)
    r2 = np.zeros(shape=(len(c_list), len(EVENTS), len(EVENTS)), dtype=np.int)
    compteur = np.zeros(shape=(len(c_list),len(EVENTS),2))
    j=0

    for p in c_list:
        #ii. predire et changer la forme de new_sol pour qu'elles soient exploitables
        if tdict is not None:
            sol = filtre2(sol, tdict, plate)
        new_sol = tracking.sousProcessClassify(sol, loadingFolder, loadingFile= None, i=p, n_f=n_fold, n_big_f=n_big_fold)

        #iii. construire le doublet source, target pour chaque frame, avec uniquement les hypotheses concernant les individus du training set
        acc, acc2, compt, visu = calcAccuracy(new_sol, newFrameLot, tdict)
        r[j]+=acc ; r2[j]+=acc2; compteur[j] +=compt
        j+=1
    del sol ;del newFrameLot ; del new_sol ; del tdict; gc.collect()
            
#    print>>outputTotal, "n fold", n_fold, "plate", plate, "c list :", c_list
#    for k in range(len(c_list)):
#        print>>outputTotal, r[k] 
#    #print>>outputTotal, d
#    outputTotal.close()
        
    return r, r2, compteur
Esempio n. 2
0
def accu(nom, c_list, nb_fold = -1):
    global nb_folds
    #i: charger les data
    r = [np.zeros(shape=(len(EVENTS), 2), dtype=np.int) for x in range(len(c_list))]
    r2 = [np.zeros(shape=(len(EVENTS), len(EVENTS)), dtype=np.int) for x in range(len(c_list))]
    compteur = [np.zeros(shape=(len(EVENTS),2)) for x in range(len(c_list))]
    #ACCURACY POUR TOUT LE MONDE
    if nb_fold == -1:
        listD = os.listdir('/media/lalil0u/New/workspace2/Tracking/data/raw')
        first = True
        for plate in listD:
            output2=open(nom+plate+'.pkl', 'w')
            sol, newFrameLot = gettingSolu(first, plate)
            
            fichier = open(loadingFolder+"minMax_data_all.pkl", "r")  
            minMax = pickle.load(fichier)
            fichier.close()
            sol.normalisation(minMax)
            
            first = False
            j=0
            for p in c_list:
                #ii. predire et changer la forme de new_sol pour qu'elles soient exploitables
                print loadingFolder
                new_sol = tracking.sousProcessClassify(sol, loadingFolder, integers=True, loadingFile= None, i=p)
                dicTraj =tracking.trajBuilder(new_sol)
                tracking.outputTrajXml(dicTraj, loadingFolder+'/predictions/')

                #iii. construire le doublet source, target pour chaque frame, avec uniquement les hypotheses concernant les individus du training set
                acc, acc2, c, visu = calcAccuracy(new_sol, newFrameLot)
                #pickle.dump(visu, open('visu'+plate+'_'+str(p)+'.pkl', 'w'))
                
                #ecrireXml(visu, p)
                
                print acc, acc2, c
                r[j]+=acc; r2[j]+=acc2; compteur[j] +=c
                j+=1
            sol = None ;newFrameLot = None ; new_sol = None
                
            pickle.dump(postProcessing(r, r2, compteur[0]), output2)
            output2.close()
            
    elif nb_fold == nb_folds:
        first = True
        outputTotal = open(nom+"TOTALE.txt", 'w')
        output2=open(nom+'TOTALE.pkl', 'w')
        listD = os.listdir('/media/lalil0u/New/workspace2/Tracking/data/raw')
        for plate in listD:
            sol, newFrameLot = gettingSolu(first, plate)
            first = False; firstFold=True
            for n_fold in range(nb_fold):
                fichier = open("../results/data_TEST_fold"+str(n_fold)+".pkl", 'r')
                tdict = pickle.load(fichier); fichier.close()
                if plate not in tdict:
                    continue

                if not firstFold:
                    sol.denormalisation(minMax)

                print "normalization"
    
                fichier = open(loadingFolder+"minMax"+str(n_fold)+".pkl", "r")  
                minMax = pickle.load(fichier)
                fichier.close()
                sol.normalisation(minMax)

                firstFold=False

                print "TIME TIME TIME after normalization", time.clock()
                
                
                acc, acc2, compt = accuPerPlate(nom, c_list, n_fold, tdict, plate, sol, newFrameLot)
                for pou in range(len(r)):
                    r[pou]+=acc[pou]; r2[pou]+=acc2[pou]
                    compteur[pou]+=compt[pou]
                    
            outputPlate = open(nom+str(plate)+'.pkl', 'w')
            pickle.dump(postProcessing(r, r2, compteur[0]), outputPlate)
            outputPlate.close()
        print>>outputTotal, "c list :", c_list
        for k in range(len(c_list)):
            print>>outputTotal, r[k], compteur[k]
            #print>>outputTotal, d
        outputTotal.close()
        pickle.dump(postProcessing(r, r2, compteur[0]), output2)
        output2.close()
    return r, r2, compteur