示例#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
    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)
示例#3
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.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
示例#4
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