예제 #1
0
                pylab.figure(20)
                pylab.ioff()
                pylab.clf()
                pylab.axis("off")
                img = util.myimread(tsImages[ii]["name"])
                pylab.imshow(img, interpolation="nearest", animated=True)
                pylab.gca().set_ylim(0, img.shape[0])
                pylab.gca().set_xlim(0, img.shape[1])
                pylab.gca().set_ylim(pylab.gca().get_ylim()[::-1])
                tr.show(nfuse, parts=showlabel, thr=-0.5, maxnum=10)
                pylab.show()
        del itr

        #tp,fp,scr,tot=VOCpr.VOCprlistfastscore(tsImages,detlist,numim=cfg.maxpostest,show=False,ovr=0.5)
        tp, fp, scr, tot = VOCpr.VOCprRecord(tsImages,
                                             detlist,
                                             show=False,
                                             ovr=0.5)
        pylab.figure(15)
        pylab.clf()
        rc, pr, ap = VOCpr.drawPrfast(tp, fp, tot)
        pylab.draw()
        pylab.show()
        pylab.savefig("%s_ap%d.png" % (testname, it))
        #util.savemat("%s_ap%d.mat"%(testname,it),{"tp":tp,"fp":fp,"scr":scr,"tot":tot,"rc":rc,"pr":pr,"ap":ap})
        tinit = ((time.time() - initime) / 3600.0)
        tpar = ((time.time() - partime) / 3600.0)
        print "AP(it=", it, ")=", ap
        print "Training Time: %.3f h" % (tinit)
        rpres.report(testname + ".rpt.txt", "a", "Results")
예제 #2
0
                else:
                    showlabel = False
                pylab.figure(20)
                pylab.ioff()
                pylab.clf()
                pylab.axis("off")
                img = util.myimread(tsImages[ii]["name"])
                pylab.imshow(img, interpolation="nearest", animated=True)
                pylab.gca().set_ylim(0, img.shape[0])
                pylab.gca().set_xlim(0, img.shape[1])
                pylab.gca().set_ylim(pylab.gca().get_ylim()[::-1])
                tr.show(nfuse, parts=showlabel, thr=-0.5, maxnum=10)
                pylab.show()
        del itr

        #tp,fp,scr,tot=VOCpr.VOCprlistfastscore(tsImages,detlist,numim=cfg.maxpostest,show=False,ovr=0.5)
        tp, fp, scr, tot = VOCpr.VOCprRecord(
            tsImages, detlist, show=False, ovr=0.5)
        pylab.figure(15)
        pylab.clf()
        rc, pr, ap = VOCpr.drawPrfast(tp, fp, tot)
        pylab.draw()
        pylab.show()
        pylab.savefig("%s_ap%d.png" % (testname, it))
        #util.savemat("%s_ap%d.mat"%(testname,it),{"tp":tp,"fp":fp,"scr":scr,"tot":tot,"rc":rc,"pr":pr,"ap":ap})
        tinit = ((time.time() - initime) / 3600.0)
        tpar = ((time.time() - partime) / 3600.0)
        print "AP(it=", it, ")=", ap
        print "Training Time: %.3f h" % (tinit)
        rpres.report(testname + ".rpt.txt", "a", "Results")
예제 #3
0
    pylab.ion()
    pylab.draw()
    pylab.show()  
    print [x["scr"] for x in im[1]]
    raw_input()
    if False:
        pylab.savefig("./video/detSCRBU/"+tsImages[i]["name"].split("/")[-1].split(".")[0]+".png")  
    #raw_input()   
    for l in im[1]:
        detlist.append([tsImages[i]["name"].split("/")[-1].split(".")[0],l["scr"],l["bbox"][1],l["bbox"][0],l["bbox"][3],l["bbox"][2]])
del itr
mypool.close()
tp,fp,scr,tot=VOCpr.VOCprRecord(tsImages,detlist,show=False,ovr=0.5)#solved a problem that was giving around 1-2 point less
pylab.figure(16)
pylab.clf()
fppi,miss,ap=VOCpr.drawMissRatePerImage(tp,fp,tot,len(tsImages))
pylab.draw()
pylab.show()
pylab.figure(15)
pylab.clf()
rc,pr,ap=VOCpr.drawPrfast(tp,fp,tot)
pylab.draw()
pylab.show()
#pylab.savefig("%s_ap%d_test.png"%(testname,it))
#pylab.savefig("%s_miss%d_test.png"%(testname,it))
tinit=((time.time()-initime))#/3600.0)
print "Average Detection Time:",numpy.mean(dettime)
print "Number of Computed HOGS",numhog
print "AP(it=",it,")=",ap
print "Test Time: %.3fs"%tinit
#rpres.report(testname+".rpt.txt","a","Results")
예제 #4
0
파일: testIVANRL.py 프로젝트: moloned/CFdet
def test(thr, cfg, it=9):

    #cfg.test=True
    import util
    #it=it
    models = util.load("%s%d.model" % (cfg.testname, it))
    #skip occlusion
    #for l in models:
    #    del l["occl"]

    w = []
    rho = []
    cfg.mythr = thr
    #for l in range(cfg.numcl):
    #    w.append(util.ModeltoW(models[l],cfg.usemrf,cfg.usefather,cfg.k,lastlev=1))
    #    rho.append(models[l]["rho"])
    #cfg.mythr=cfg.mythr*numpy.mean([numpy.sum(x**2) for x in w])#-numpy.mean(rho)
    #raw_input()
    #cfg.mythr=cfg.mythr#-numpy.mean(rho)
    if cfg.multipr == 1:
        numcore = None
    else:
        numcore = cfg.multipr

    mypool = Pool(numcore)

    if cfg.cls == "inria":
        if cfg.select == "pos":
            tsImages = getRecord(InriaTestData(basepath=cfg.dbpath),
                                 cfg.maxtest)
        else:
            tsImages = getRecord(InriaTestFullData(basepath=cfg.dbpath),
                                 cfg.maxtest)
        if select == "dir":  #"." or select[0]=="/"
            import glob
            #lst=glob.glob("/home/marcopede/ivan/zebra/CVC_Zebra1/*.jpeg")[150:]
            lst = glob.glob(
                "/media/ca0567b8-ee6d-4590-8462-0d093addb4cf/video/*.png")
            lst.sort()
            lst = lst[3900:]
            total = len(lst)
            tsImages = numpy.zeros(total,
                                   dtype=[("id", numpy.int32),
                                          ("name", object), ("bbox", list)])
            for idl, l in enumerate(lst):
                tsImages[idl]["id"] = idl
                tsImages[idl]["name"] = l  #l.split("/")[-1]
                tsImages[idl]["bbox"] = None
        else:
            tsImages = getRecord(
                VOC07Data(
                    select=cfg.select,
                    cl="%s_test.txt" % cfg.cls,
                    basepath=cfg.dbpath,  #"/home/databases/",
                    usetr=True,
                    usedf=False),
                cfg.maxtest)
    elif cfg.cls == "cvc02":
        #tsImages=getRecord(CVC02test(),cfg.maxtest)
        tsImages = getRecord(
            CVC02test(
                basepath="/media/OS/data/DATASET-CVC-02/CVC-02-System/",
                images="/sequence-15/color/",
                annotations="/sequence-15/annotations/",
            ), cfg.maxtest)
        tsImagesFull = tsImages
    elif cfg.cls == "ivan":
        stest = 10000
        #tsImages=getRecord(ImgFile("/media/OS/data/PVTRA101/CLEAR06_PVTRA101a01_502_Bbox.txt",imgpath="/media/OS/data/PVTRA101/images/"),stest+cfg.maxtest)[stest:]
        #tsImages=getRecord(ImgFile("/media/OS/data/PVTRA101a19/GrTr_CLEAR06_PVTRA101a19.txt",imgpath="/media/OS/data/PVTRA101a19/CLEAR06_PVTRA101a19/",sort=True,amin=1000),cfg.maxtest)[:600]#[:1950]#the other frames do not have GT
        #tsImages=getRecord(ImgFile("/media/OS/data/PVTRA101a19/GrTr_CLEAR06_PVTRA101a19_only12.txt",imgpath="/media/OS/data/PVTRA101a19/CLEAR06_PVTRA101a19/",sort=True,amin=100),cfg.maxtest)[:(1950/12)]#the other frames do not have GT
        #tsImages=getRecord(ImgFile("/media/OS/data/PVTRA101a19/CLEAR06_PVTRA101a19_people_Celik_allfr.txt",imgpath="/media/OS/data/PVTRA101a19/CLEAR06_PVTRA101a19/",sort=True,amin=100),cfg.maxtest)#pedestrian
        tsImages = getRecord(
            ImgFile(
                "/media/OS/data/PVTRA101a19/CLEAR06_PVTRA101a19_vehicles_Celik_allfr.txt",
                imgpath="/media/OS/data/PVTRA101a19/CLEAR06_PVTRA101a19/",
                sort=True,
                amin=100), cfg.maxtest)  #vechicles
        #tsImages=getRecord(ImgFile("/media/OS/data/PVTRA101a19/CLEAR06_PVTRA101a19_PV_Celik_allfr.txt",imgpath="/media/OS/data/PVTRA101a19/CLEAR06_PVTRA101a19/",sort=True,amin=100),cfg.maxtest)#pedestrian+vechicles
        tsImagesFull = tsImages

    #mypool = Pool(numcore)

    print "Test"
    print "Pruning Threshold:", cfg.mythr
    numhog = 0
    initime = time.time()
    detlist = []
    mycfg = copy.copy(cfg)
    mycfg.numneg = 0
    mycfg.show = False
    arg = [[i, tsImages[i]["name"], None, models, mycfg]
           for i in range(len(tsImages))]
    t = time.time()
    if not (cfg.multipr):
        itr = itertools.imap(detectWrap, arg)
    else:
        itr = mypool.imap(detectWrap, arg)
    pylab.figure(20)
    pylab.clf()
    ax = pylab.subplot(111)
    img = util.myimread(tsImages[0]["name"], resize=cfg.resize)
    pylab.ioff()
    axes = pylab.Axes(pylab.gcf(), [
        .0, .0, 1.0, 1.0
    ])  # [left, bottom, width, height] where each value is between 0 and 1
    pylab.gcf().add_axes(axes)
    pylab.axis("off")
    aim = pylab.imshow(img, interpolation="nearest", animated=True)
    pylab.axis((0, img.shape[1], img.shape[0], 0))
    pylab.draw()
    pylab.show()
    for ii, res in enumerate(itr):
        totneg = 0
        fuse = []
        for mix in res:
            tr = mix[0]
            fuse += mix[1]
            numhog += mix[3]
        #for h in fuse:
        #    h["scr"]+=models[h["cl"]]["ra"]
        rfuse = tr.rank(fuse, maxnum=300)
        nfuse = tr.cluster(rfuse, ovr=cfg.ovrasp, inclusion=False)
        #print "----Test Image %d----"%ii
        print "----Test Image %s----" % tsImages[ii]["name"].split("/")[-1]
        for idl, l in enumerate(nfuse):
            #print "DET:",l["bbox"]
            #raw_input()
            #if l["bbox"][0]/cfg.resize<125:
            #    nfuse.pop(idl)
            #    continue
            detlist.append([
                tsImages[ii]["name"].split("/")[-1].split(".")[0], l["scr"],
                l["bbox"][1] / cfg.resize, l["bbox"][0] / cfg.resize,
                l["bbox"][3] / cfg.resize, l["bbox"][2] / cfg.resize
            ])
        print "Detections:", len(nfuse)
        if cfg.show:
            if cfg.show == True:
                showlabel = False  #"Parts"#False#"Parts"
            else:
                showlabel = False
            pylab.figure(20)
            xx = pylab.gca()
            del xx.texts[:]
            del xx.lines[:]
            #print pylab.gca().images
            #pylab.ioff()
            #            axes=pylab.Axes(pylab.gcf(), [.0,.0,1.0,1.0]) # [left, bottom, width, height] where each value is between 0 and 1
            #            pylab.gcf().add_axes(axes)
            #            pylab.axis("off")
            #img=util.myimread(tsImages[ii]["name"],resize=cfg.resize)
            img = pylab.imread(
                tsImages[ii]["name"])  #myimread has memory problems!!!!!!!
            #pylab.clf()
            aim.set_array(img)
            #ims=pylab.imshow(img,interpolation="nearest",animated=True)
            tr.show(nfuse, parts=showlabel, thr=0, maxnum=100)
            pylab.axis((0, img.shape[1], img.shape[0], 0))
            pylab.draw()
            pylab.show()
            #print ax.images
            #raw_input()
        showGT = True
        if showGT:
            bb = tsImages[ii]["bbox"]
            for mbb in bb:
                util.box(mbb[0], mbb[1], mbb[2], mbb[3], col='r', lw=2)
            pylab.axis((0, img.shape[1], img.shape[0], 0))
            pylab.draw()
            #raw_input()
        if select == "dir":
            #RSZ=0.5
            f = pylab.figure(11, figsize=(9, 5))
            pylab.ioff()
            pylab.clf()
            axes = pylab.Axes(
                f, [.0, .0, 1.0, 1.0]
            )  # [left, bottom, width, height] where each value is between 0 and 1
            f.add_axes(axes)
            img = util.myimread(tsImages[ii]["name"], resize=cfg.resize)
            pylab.imshow(img, interpolation="nearest", animated=True)
            #raw_input()
            pylab.axis("off")
            tr.show(nfuse, parts=True, thr=-0.99, scr=True)
            pylab.axis((0, img.shape[1], img.shape[0], 0))
            pylab.ion()
            pylab.draw()
            pylab.show()
            #raw_input()
            pylab.savefig(
                "/media/ca0567b8-ee6d-4590-8462-0d093addb4cf/video/det/" +
                tsImages[ii]["name"].split("/")[-1].split(".")[0] + ".png")
    del itr

    #tp,fp,scr,tot=VOCpr.VOCprlistfastscore(tsImages,detlist,numim=cfg.maxpostest,show=False,ovr=0.5)
    #tp,fp,scr,tot=VOCpr.VOCprRecord_wrong(tsImages,detlist,show=False,ovr=0.5)
    tp, fp, scr, tot = VOCpr.VOCprRecord(tsImages,
                                         detlist,
                                         show=False,
                                         ovr=0.5)
    pylab.figure(15)
    pylab.clf()
    rc, pr, ap = VOCpr.drawPrfast(tp, fp, tot)
    pylab.figure(16)
    pylab.clf()
    fppi, miss, ap = VOCpr.drawMissRatePerImage(tp, fp, tot, len(tsImages))
    pylab.draw()
    pylab.show()
    sfdsd
    #pylab.savefig("%s_ap%d_test%s%.1f.png"%(testname,it,select,cfg.mythr))
    tottime = ((time.time() - initime))
    print "Threshold used:", cfg.mythr
    print "Total number of HOG:", numhog
    print "AP(it=", it, ")=", ap
    print "Testing Time: %.3f s" % tottime  #/3600.0)
    #results={"det":detlist,"ap":ap,"tp":tp,"fp":fp,"pr":pr,"rc":rc,"numhog":numhog,"mythr":cfg.mythr,"time":tottime}
    #util.savemat("%s_ap%d_test_thr_%.3f.mat"%(cfg.testname,it,cfg.mythr),results)
    #util.save("%s_ap%d_test_thr_%.3f.dat"%(testname,it,cfg.mythr),results)
    #util.savedetVOC(detlist,"%s_ap%d_test_thr_%.3f.txt"%(testname,it,cfg.mythr))
    #fd=open("%s_ap%d_test%s.txt"%(cfg.testname,it,select),"a")
    #fd.write("Threshold used:%f\n"%cfg.mythr)
    #fd.write("Total number of HOG:%d\n"%numhog)
    #fd.write("Average precision:%f\n"%ap)
    #fd.write("Testing Time: %.3f s\n\n"%tottime)
    #fd.close()
    return ap, numhog
예제 #5
0
def test(thr,cfg,it=9):
    
    #cfg.test=True
    import util
    #it=it
    models=util.load("%s%d.model"%(cfg.testname,it))
    #skip occlusion
    #for l in models:
    #    del l["occl"]

    w=[]
    rho=[]
    cfg.mythr=thr
    #for l in range(cfg.numcl):
    #    w.append(util.ModeltoW(models[l],cfg.usemrf,cfg.usefather,cfg.k,lastlev=1))
    #    rho.append(models[l]["rho"])
    #cfg.mythr=cfg.mythr*numpy.mean([numpy.sum(x**2) for x in w])#-numpy.mean(rho)
    #raw_input()    
    #cfg.mythr=cfg.mythr#-numpy.mean(rho)
    if cfg.multipr==1:
        numcore=None
    else:
        numcore=cfg.multipr

    mypool = Pool(numcore)
    if cfg.db=="inria":
        if cfg.select=="pos":
            tsImages=getRecord(InriaTestData(basepath=cfg.dbpath),cfg.maxtest)
        else:
            tsImages=getRecord(InriaTestFullData(basepath=cfg.dbpath),cfg.maxtest)
        if select=="dir":#"." or select[0]=="/"
            import glob
            #lst=glob.glob("/home/marcopede/ivan/zebra/CVC_Zebra1/*.jpeg")[150:]
            lst=glob.glob("/media/ca0567b8-ee6d-4590-8462-0d093addb4cf/video/*.png")
            lst.sort()
            lst=lst[3900:]
            total=len(lst)
            tsImages=numpy.zeros(total,dtype=[("id",numpy.int32),("name",object),("bbox",list)])
            for idl,l in enumerate(lst):
                tsImages[idl]["id"]=idl
                tsImages[idl]["name"]=l#l.split("/")[-1]
                tsImages[idl]["bbox"]=None             
        else:
            tsImages=getRecord(VOC07Data(select=cfg.select,cl="%s_test.txt"%cfg.cls,
                    basepath=cfg.dbpath,#"/home/databases/",
                    usetr=True,usedf=False),cfg.maxtest)
    elif cfg.db=="cvc02":
        #tsImages=getRecord(CVC02test(),cfg.maxtest)
        tsImages=getRecord(CVC02test(basepath="/media/OS/data/DATASET-CVC-02/CVC-02-System/",
                images="/sequence-15/color/",
                annotations="/sequence-15/annotations/",),cfg.maxtest)
        tsImagesFull=tsImages
    elif cfg.db=="ivan":
        stest=10000
        #tsImages=getRecord(ImgFile("/media/OS/data/PVTRA101/CLEAR06_PVTRA101a01_502_Bbox.txt",imgpath="/media/OS/data/PVTRA101/images/"),stest+cfg.maxtest)[stest:]
        #tsImages=getRecord(ImgFile("/media/OS/data/PVTRA101a19/GrTr_CLEAR06_PVTRA101a19.txt",imgpath="/media/OS/data/PVTRA101a19/CLEAR06_PVTRA101a19/",sort=True,amin=1000),cfg.maxtest)[:600]#[:1950]#the other frames do not have GT
        #tsImages=getRecord(ImgFile("/media/OS/data/PVTRA101a19/GrTr_CLEAR06_PVTRA101a19_only12.txt",imgpath="/media/OS/data/PVTRA101a19/CLEAR06_PVTRA101a19/",sort=True,amin=100),cfg.maxtest)[:(1950/12)]#the other frames do not have GT
        #tsImages=getRecord(ImgFile("/media/OS/data/PVTRA101a19/CLEAR06_PVTRA101a19_people_Celik_allfr.txt",imgpath="/media/OS/data/PVTRA101a19/CLEAR06_PVTRA101a19/",sort=True,amin=100),cfg.maxtest)#pedestrian
        #tsImages=getRecord(ImgFile("/media/OS/data/PVTRA101a19/CLEAR06_PVTRA101a19_vehicles_Celik_allfr.txt",imgpath="/media/OS/data/PVTRA101a19/CLEAR06_PVTRA101a19/",sort=True,amin=100),cfg.maxtest)#vechicles
        tsImages=getRecord(ImgFile("/media/OS/data/PVTRA101a19/CLEAR06_PVTRA101a19_PV_Celik_allfr.txt",imgpath="/media/OS/data/PVTRA101a19/CLEAR06_PVTRA101a19/",sort=True,amin=100),cfg.maxtest)#pedestrian+vechicles
        tsImagesFull=tsImages
        
    #mypool = Pool(numcore)
 
    print "Test"
    print "Pruning Threshold:",cfg.mythr
    numhog=0
    initime=time.time()
    detlist=[]
    mycfg=copy.copy(cfg)
    mycfg.numneg=0
    mycfg.show=False
    arg=[[i,tsImages[i]["name"],None,models,mycfg] for i in range(len(tsImages))]
    t=time.time()
    if not(cfg.multipr):
        itr=itertools.imap(detectWrap,arg)        
    else:
        itr=mypool.imap(detectWrap,arg)
    pylab.figure(20)
    pylab.clf()
    ax = pylab.subplot(111)
    img=util.myimread(tsImages[0]["name"],resize=cfg.resize)
    pylab.ioff()
    axes=pylab.Axes(pylab.gcf(), [.0,.0,1.0,1.0]) # [left, bottom, width, height] where each value is between 0 and 1
    pylab.gcf().add_axes(axes) 
    pylab.axis("off")          
    aim=pylab.imshow(img,interpolation="nearest",animated=True)
    pylab.axis((0,img.shape[1],img.shape[0],0))           
    pylab.draw()
    pylab.show()
    for ii,res in enumerate(itr):
        totneg=0
        fuse=[]
        for mix in res:
            tr=mix[0]
            fuse+=mix[1]
            numhog+=mix[3]
        #for h in fuse:
        #    h["scr"]+=models[h["cl"]]["ra"]
        rfuse=tr.rank(fuse,maxnum=300)
        nfuse=tr.cluster(rfuse,ovr=cfg.ovrasp,inclusion=False)
        #print "----Test Image %d----"%ii
        print "----Test Image %s----"%tsImages[ii]["name"].split("/")[-1]
        for idl,l in enumerate(nfuse):
            #print "DET:",l["bbox"]
            #raw_input()
            #if l["bbox"][0]/cfg.resize<125:
            #    nfuse.pop(idl)
            #    continue
            detlist.append([tsImages[ii]["name"].split("/")[-1].split(".")[0],l["scr"],l["bbox"][1]/cfg.resize,l["bbox"][0]/cfg.resize,l["bbox"][3]/cfg.resize,l["bbox"][2]/cfg.resize])
        print "Detections:",len(nfuse)
        if cfg.show:
            if cfg.show==True:
                showlabel=False#"Parts"#False#"Parts"
            else:
                showlabel=False
            pylab.figure(20)
            xx=pylab.gca()            
            del xx.texts[:]
            del xx.lines[:]
            #print pylab.gca().images
            #pylab.ioff()
#            axes=pylab.Axes(pylab.gcf(), [.0,.0,1.0,1.0]) # [left, bottom, width, height] where each value is between 0 and 1
#            pylab.gcf().add_axes(axes) 
#            pylab.axis("off")
            #img=util.myimread(tsImages[ii]["name"],resize=cfg.resize)
            img=pylab.imread(tsImages[ii]["name"])#myimread has memory problems!!!!!!!
            #pylab.clf()
            aim.set_array(img)
            #ims=pylab.imshow(img,interpolation="nearest",animated=True)
            tr.show(nfuse,parts=showlabel,thr=0,maxnum=100)
            pylab.axis((0,img.shape[1],img.shape[0],0))           
            pylab.draw()
            pylab.show()
            #print ax.images
            #raw_input()
        showGT=True
        if showGT:
            bb=tsImages[ii]["bbox"]
            for mbb in bb:
                util.box(mbb[0], mbb[1], mbb[2], mbb[3], col='r', lw=2)
            pylab.axis((0,img.shape[1],img.shape[0],0))
            pylab.draw()
            #raw_input()
        if select=="dir":
            #RSZ=0.5
            f=pylab.figure(11,figsize=(9,5))
            pylab.ioff()
            pylab.clf()
            axes=pylab.Axes(f, [.0,.0,1.0,1.0]) # [left, bottom, width, height] where each value is between 0 and 1
            f.add_axes(axes) 
            img=util.myimread(tsImages[ii]["name"],resize=cfg.resize)
            pylab.imshow(img,interpolation="nearest",animated=True)
            #raw_input()
            pylab.axis("off")
            tr.show(nfuse,parts=True,thr=-0.99,scr=True)
            pylab.axis((0,img.shape[1],img.shape[0],0))
            pylab.ion()
            pylab.draw()
            pylab.show()  
            #raw_input()
            pylab.savefig("/media/ca0567b8-ee6d-4590-8462-0d093addb4cf/video/det/"+tsImages[ii]["name"].split("/")[-1].split(".")[0]+".png")  
    del itr
    
    #tp,fp,scr,tot=VOCpr.VOCprlistfastscore(tsImages,detlist,numim=cfg.maxpostest,show=False,ovr=0.5)
    #tp,fp,scr,tot=VOCpr.VOCprRecord_wrong(tsImages,detlist,show=False,ovr=0.5)
    tp,fp,scr,tot=VOCpr.VOCprRecord(tsImages,detlist,show=False,ovr=0.5)
    pylab.figure(15)
    pylab.clf()
    rc,pr,ap=VOCpr.drawPrfast(tp,fp,tot)
    pylab.figure(16)
    pylab.clf()
    fppi,miss,ap=VOCpr.drawMissRatePerImage(tp,fp,tot,len(tsImages))
    pylab.draw()
    pylab.show()
    sfdsd
    #pylab.savefig("%s_ap%d_test%s%.1f.png"%(testname,it,select,cfg.mythr))
    tottime=((time.time()-initime))
    print "Threshold used:",cfg.mythr
    print "Total number of HOG:",numhog
    print "AP(it=",it,")=",ap
    print "Testing Time: %.3f s"%tottime#/3600.0)
    #results={"det":detlist,"ap":ap,"tp":tp,"fp":fp,"pr":pr,"rc":rc,"numhog":numhog,"mythr":cfg.mythr,"time":tottime}
    #util.savemat("%s_ap%d_test_thr_%.3f.mat"%(cfg.testname,it,cfg.mythr),results)
    #util.save("%s_ap%d_test_thr_%.3f.dat"%(testname,it,cfg.mythr),results)
    #util.savedetVOC(detlist,"%s_ap%d_test_thr_%.3f.txt"%(testname,it,cfg.mythr))
    #fd=open("%s_ap%d_test%s.txt"%(cfg.testname,it,select),"a")
    #fd.write("Threshold used:%f\n"%cfg.mythr)
    #fd.write("Total number of HOG:%d\n"%numhog)
    #fd.write("Average precision:%f\n"%ap)
    #fd.write("Testing Time: %.3f s\n\n"%tottime)
    #fd.close()
    return ap,numhog
예제 #6
0
파일: testINRIA.py 프로젝트: moloned/CFdet
    print[x["scr"] for x in im[1]]
    raw_input()
    if False:
        pylab.savefig("./video/detSCRBU/" +
                      tsImages[i]["name"].split("/")[-1].split(".")[0] +
                      ".png")
    #raw_input()
    for l in im[1]:
        detlist.append([
            tsImages[i]["name"].split("/")[-1].split(".")[0], l["scr"],
            l["bbox"][1], l["bbox"][0], l["bbox"][3], l["bbox"][2]
        ])
del itr
mypool.close()
tp, fp, scr, tot = VOCpr.VOCprRecord(
    tsImages, detlist, show=False,
    ovr=0.5)  #solved a problem that was giving around 1-2 point less
pylab.figure(16)
pylab.clf()
fppi, miss, ap = VOCpr.drawMissRatePerImage(tp, fp, tot, len(tsImages))
pylab.draw()
pylab.show()
pylab.figure(15)
pylab.clf()
rc, pr, ap = VOCpr.drawPrfast(tp, fp, tot)
pylab.draw()
pylab.show()
#pylab.savefig("%s_ap%d_test.png"%(testname,it))
#pylab.savefig("%s_miss%d_test.png"%(testname,it))
tinit = ((time.time() - initime))  #/3600.0)
print "Average Detection Time:", numpy.mean(dettime)
예제 #7
0
def runtest(models,tsImages,cfg,parallel=True,numcore=4,detfun=detectCRF.test,save=False,show=False,pool=None):

    #parallel=True
    #cfg.show=not(parallel)
    #numcore=4
    #mycfg=
    if parallel:
        if pool!=None:
            mypool=pool #use already created pool
        else:
            mypool = Pool(numcore)
    arg=[]

    for idl,l in enumerate(tsImages):
        #bb=l["bbox"]
        #for idb,b in enumerate(bb):
        arg.append({"idim":idl,"file":l["name"],"idbb":0,"bbox":[],"models":models,"cfg":cfg,"flip":False})    

    print "----------Test-----------"
    ltdet=[];
    if not(parallel):
        #itr=itertools.imap(detectCRF.test,arg)        
        #itr=itertools.imap(lambda x:detectCRF.test(x,numhyp=1),arg) #this can also be used       
        itr=itertools.imap(detfun,arg)
    else:
        #itr=mypool.map(detectCRF.test,arg)
        itr=mypool.imap(detfun,arg) #for parallle lambda does not work

    for ii,res in enumerate(itr):
        if show:
            im=myimread(arg[ii]["file"])
            if tsImages[ii]["bbox"]!=[]:
                detectCRF.visualize2(res[:3],cfg.N,im,bb=tsImages[ii]["bbox"][0])
            else:
                detectCRF.visualize2(res[:3],cfg.N,im)
            print [x["scr"] for x in res[:5]]
        ltdet+=res

    if parallel:
        if pool==None:
            mypool.close() 
            mypool.join() 

    #sort detections
    ltosort=[-x["scr"] for x in ltdet]
    lord=numpy.argsort(ltosort)
    aux=[]
    for l in lord:
        aux.append(ltdet[l])
    ltdet=aux

    #save on a file and evaluate with annotations
    detVOC=[]
    for l in ltdet:
        detVOC.append([l["idim"].split("/")[-1].split(".")[0],l["scr"],l["bbox"][1],l["bbox"][0],l["bbox"][3],l["bbox"][2]])

    #plot AP
    tp,fp,scr,tot=VOCpr.VOCprRecord(tsImages,detVOC,show=False,ovr=0.5)
    pylab.figure(15,figsize=(4,4))
    pylab.clf()
    rc,pr,ap=VOCpr.drawPrfast(tp,fp,tot)
    pylab.draw()
    pylab.show()
    #save in different formats
    if type(save)==str:
        testname=save
        util.savedetVOC(detVOC,testname+".txt")
        util.save(testname+".det",{"det":ltdet[:500]})#takes a lot of space use only first 500
        util.savemat(testname+".mat",{"tp":tp,"fp":fp,"scr":scr,"tot":tot,"rc":rc,"pr":pr,"ap":ap})
        pylab.savefig(testname+".png")
    return ap
예제 #8
0
def test(thr, cfg):

    #cfg.test=True
    import util
    it = 7
    models = util.load("%s%d.model" % (cfg.testname, it))
    w = []
    rho = []
    cfg.mythr = thr
    #for l in range(cfg.numcl):
    #    w.append(util.ModeltoW(models[l],cfg.usemrf,cfg.usefather,cfg.k,lastlev=1))
    #    rho.append(models[l]["rho"])
    #cfg.mythr=cfg.mythr*numpy.mean([numpy.sum(x**2) for x in w])#-numpy.mean(rho)
    #raw_input()
    #cfg.mythr=cfg.mythr#-numpy.mean(rho)

    if cfg.multipr == 1:
        numcore = None
    else:
        numcore = cfg.multipr

    mypool = Pool(numcore)

    if cfg.cls == "inria":
        if cfg.select == "pos":
            tsImages = getRecord(InriaTestData(basepath=cfg.dbpath),
                                 cfg.maxtest)
        else:
            tsImages = getRecord(InriaTestFullData(basepath=cfg.dbpath),
                                 cfg.maxtest)
    else:
        tsImages = getRecord(
            VOC07Data(
                select=cfg.select,
                cl="%s_test.txt" % cfg.cls,
                basepath=cfg.dbpath,  #"/home/databases/",
                usetr=True,
                usedf=False),
            cfg.maxtest)

    mypool = Pool(numcore)

    print "Test"
    print "Pruning Threshold:", cfg.mythr
    numhog = 0
    initime = time.time()
    detlist = []
    mycfg = copy.copy(cfg)
    mycfg.numneg = 0
    arg = [[i, tsImages[i]["name"], None, models, mycfg]
           for i in range(len(tsImages))]
    t = time.time()
    if not (cfg.multipr):
        itr = itertools.imap(detectWrap, arg)
    else:
        itr = mypool.imap(detectWrap, arg)
    for ii, res in enumerate(itr):
        totneg = 0
        fuse = []
        for mix in res:
            tr = mix[0]
            fuse += mix[1]
            numhog += mix[3]
        #for h in fuse:
        #    h["scr"]+=models[h["cl"]]["ra"]
        rfuse = tr.rank(fuse, maxnum=300)
        nfuse = tr.cluster(rfuse, ovr=0.3, inclusion=False)
        print "----Test Image %d----" % ii
        for l in nfuse:
            detlist.append([
                tsImages[ii]["name"].split("/")[-1].split(".")[0], l["scr"],
                l["bbox"][1], l["bbox"][0], l["bbox"][3], l["bbox"][2]
            ])
        print "Detections:", len(nfuse)
        if cfg.show:
            if cfg.show == True:
                showlabel = "Parts"
            else:
                showlabel = False
            pylab.figure(20)
            pylab.ioff()
            pylab.clf()
            pylab.axis("off")
            img = util.myimread(tsImages[ii]["name"])
            pylab.imshow(img, interpolation="nearest", animated=True)
            pylab.gca().set_ylim(0, img.shape[0])
            pylab.gca().set_xlim(0, img.shape[1])
            pylab.gca().set_ylim(pylab.gca().get_ylim()[::-1])
            tr.show(nfuse, parts=showlabel, thr=-0.8, maxnum=10)
            pylab.show()
            #raw_input()
    del itr

    #tp,fp,scr,tot=VOCpr.VOCprlistfastscore(tsImages,detlist,numim=cfg.maxpostest,show=False,ovr=0.5)
    #tp,fp,scr,tot=VOCpr.VOCprRecord_wrong(tsImages,detlist,show=False,ovr=0.5)
    tp, fp, scr, tot = VOCpr.VOCprRecord(tsImages,
                                         detlist,
                                         show=False,
                                         ovr=0.5)
    pylab.figure(15)
    pylab.clf()
    rc, pr, ap = VOCpr.drawPrfast(tp, fp, tot)
    pylab.draw()
    pylab.show()
    #pylab.savefig("%s_ap%d_test%s%.1f.png"%(testname,it,select,cfg.mythr))
    tottime = ((time.time() - initime))
    print "Threshold used:", cfg.mythr
    print "Total number of HOG:", numhog
    print "AP(it=", it, ")=", ap
    print "Testing Time: %.3f s" % tottime  #/3600.0)
    #results={"det":detlist,"ap":ap,"tp":tp,"fp":fp,"pr":pr,"rc":rc,"numhog":numhog,"mythr":cfg.mythr,"time":tottime}
    #util.savemat("%s_ap%d_test_thr_%.3f.mat"%(cfg.testname,it,cfg.mythr),results)
    #util.save("%s_ap%d_test_thr_%.3f.dat"%(testname,it,cfg.mythr),results)
    #util.savedetVOC(detlist,"%s_ap%d_test_thr_%.3f.txt"%(testname,it,cfg.mythr))
    #fd=open("%s_ap%d_test%s.txt"%(cfg.testname,it,select),"a")
    #fd.write("Threshold used:%f\n"%cfg.mythr)
    #fd.write("Total number of HOG:%d\n"%numhog)
    #fd.write("Average precision:%f\n"%ap)
    #fd.write("Testing Time: %.3f s\n\n"%tottime)
    #fd.close()
    return ap, numhog
예제 #9
0
def test(thr, cfg):

    # cfg.test=True
    import util

    it = 7
    models = util.load("%s%d.model" % (cfg.testname, it))
    w = []
    rho = []
    cfg.mythr = thr
    # for l in range(cfg.numcl):
    #    w.append(util.ModeltoW(models[l],cfg.usemrf,cfg.usefather,cfg.k,lastlev=1))
    #    rho.append(models[l]["rho"])
    # cfg.mythr=cfg.mythr*numpy.mean([numpy.sum(x**2) for x in w])#-numpy.mean(rho)
    # raw_input()
    # cfg.mythr=cfg.mythr#-numpy.mean(rho)

    if cfg.multipr == 1:
        numcore = None
    else:
        numcore = cfg.multipr

    mypool = Pool(numcore)

    if cfg.cls == "inria":
        if cfg.select == "pos":
            tsImages = getRecord(InriaTestData(basepath=cfg.dbpath), cfg.maxtest)
        else:
            tsImages = getRecord(InriaTestFullData(basepath=cfg.dbpath), cfg.maxtest)
    else:
        tsImages = getRecord(
            VOC07Data(
                select=cfg.select,
                cl="%s_test.txt" % cfg.cls,
                basepath=cfg.dbpath,  # "/home/databases/",
                usetr=True,
                usedf=False,
            ),
            cfg.maxtest,
        )

    mypool = Pool(numcore)

    print "Test"
    print "Pruning Threshold:", cfg.mythr
    numhog = 0
    initime = time.time()
    detlist = []
    mycfg = copy.copy(cfg)
    mycfg.numneg = 0
    arg = [[i, tsImages[i]["name"], None, models, mycfg] for i in range(len(tsImages))]
    t = time.time()
    if not (cfg.multipr):
        itr = itertools.imap(detectWrap, arg)
    else:
        itr = mypool.imap(detectWrap, arg)
    for ii, res in enumerate(itr):
        totneg = 0
        fuse = []
        for mix in res:
            tr = mix[0]
            fuse += mix[1]
            numhog += mix[3]
        # for h in fuse:
        #    h["scr"]+=models[h["cl"]]["ra"]
        rfuse = tr.rank(fuse, maxnum=300)
        nfuse = tr.cluster(rfuse, ovr=0.3, inclusion=False)
        print "----Test Image %d----" % ii
        for l in nfuse:
            detlist.append(
                [
                    tsImages[ii]["name"].split("/")[-1].split(".")[0],
                    l["scr"],
                    l["bbox"][1],
                    l["bbox"][0],
                    l["bbox"][3],
                    l["bbox"][2],
                ]
            )
        print "Detections:", len(nfuse)
        if cfg.show:
            if cfg.show == True:
                showlabel = "Parts"
            else:
                showlabel = False
            pylab.figure(20)
            pylab.ioff()
            pylab.clf()
            pylab.axis("off")
            img = util.myimread(tsImages[ii]["name"])
            pylab.imshow(img, interpolation="nearest", animated=True)
            pylab.gca().set_ylim(0, img.shape[0])
            pylab.gca().set_xlim(0, img.shape[1])
            pylab.gca().set_ylim(pylab.gca().get_ylim()[::-1])
            tr.show(nfuse, parts=showlabel, thr=-0.8, maxnum=10)
            pylab.show()
            # raw_input()
    del itr

    # tp,fp,scr,tot=VOCpr.VOCprlistfastscore(tsImages,detlist,numim=cfg.maxpostest,show=False,ovr=0.5)
    # tp,fp,scr,tot=VOCpr.VOCprRecord_wrong(tsImages,detlist,show=False,ovr=0.5)
    tp, fp, scr, tot = VOCpr.VOCprRecord(tsImages, detlist, show=False, ovr=0.5)
    pylab.figure(15)
    pylab.clf()
    rc, pr, ap = VOCpr.drawPrfast(tp, fp, tot)
    pylab.draw()
    pylab.show()
    # pylab.savefig("%s_ap%d_test%s%.1f.png"%(testname,it,select,cfg.mythr))
    tottime = time.time() - initime
    print "Threshold used:", cfg.mythr
    print "Total number of HOG:", numhog
    print "AP(it=", it, ")=", ap
    print "Testing Time: %.3f s" % tottime  # /3600.0)
    # results={"det":detlist,"ap":ap,"tp":tp,"fp":fp,"pr":pr,"rc":rc,"numhog":numhog,"mythr":cfg.mythr,"time":tottime}
    # util.savemat("%s_ap%d_test_thr_%.3f.mat"%(cfg.testname,it,cfg.mythr),results)
    # util.save("%s_ap%d_test_thr_%.3f.dat"%(testname,it,cfg.mythr),results)
    # util.savedetVOC(detlist,"%s_ap%d_test_thr_%.3f.txt"%(testname,it,cfg.mythr))
    # fd=open("%s_ap%d_test%s.txt"%(cfg.testname,it,select),"a")
    # fd.write("Threshold used:%f\n"%cfg.mythr)
    # fd.write("Total number of HOG:%d\n"%numhog)
    # fd.write("Average precision:%f\n"%ap)
    # fd.write("Testing Time: %.3f s\n\n"%tottime)
    # fd.close()
    return ap, numhog