Пример #1
0
def detectWrap(a):
    t=time.time()
    i=a[0]
    imname=a[1]
    bbox=a[2]
    m=a[3]
    cfg=a[4]
    if cfg.show:
        img=util.myimread(imname)
        pylab.figure(10)
        pylab.ioff()
        pylab.clf()
        pylab.axis("off")
        pylab.imshow(img, interpolation="nearest", animated=True) 
    if bbox!=None:
        gtbbox=[{"bbox":x} for x in bbox]   
    else:
        gtbbox=None
    img=util.myimread(imname,resize=RSZ)
    f=pyrHOG2.pyrHOG(img,interv=10,savedir=cfg.savedir+"/hog/",notload=not(cfg.loadfeat),notsave=not(cfg.savefeat),hallucinate=cfg.hallucinate,cformat=True)
    res=pyrHOG2.detect(f,m,gtbbox,hallucinate=cfg.hallucinate,initr=cfg.initr,ratio=cfg.ratio,deform=cfg.deform,posovr=cfg.posovr,bottomup=cfg.bottomup,usemrf=cfg.usemrf,numneg=cfg.numneg,thr=cfg.thr,inclusion=cfg.inclusion,small=cfg.small,show=cfg.show,usefather=cfg.usefather,useprior=cfg.useprior,nms=cfg.ovr,K=cfg.k)
    if cfg.show:
        pylab.show()
#        raw_input()
    print "Detect Wrap:",time.time()-t
    return res
Пример #2
0
def detectWrap(a):
    t = time.time()
    i = a[0]
    imname = a[1]
    bbox = a[2]
    m = a[3]
    cfg = a[4]
    if cfg.show:
        img = util.myimread(imname)
        pylab.figure(10)
        pylab.ioff()
        pylab.clf()
        pylab.axis("off")
        pylab.imshow(img, interpolation="nearest", animated=True)
    if bbox != None:
        gtbbox = [{"bbox": x} for x in bbox]
    else:
        gtbbox = None
    img = util.myimread(imname, resize=RSZ)
    f = pyrHOG2.pyrHOG(img,
                       interv=10,
                       savedir=cfg.savedir + "/hog/",
                       notload=not (cfg.loadfeat),
                       notsave=not (cfg.savefeat),
                       hallucinate=cfg.hallucinate,
                       cformat=True)
    res = pyrHOG2.detect(f,
                         m,
                         gtbbox,
                         hallucinate=cfg.hallucinate,
                         initr=cfg.initr,
                         ratio=cfg.ratio,
                         deform=cfg.deform,
                         posovr=cfg.posovr,
                         bottomup=cfg.bottomup,
                         usemrf=cfg.usemrf,
                         numneg=cfg.numneg,
                         thr=cfg.thr,
                         inclusion=cfg.inclusion,
                         small=cfg.small,
                         show=cfg.show,
                         usefather=cfg.usefather,
                         useprior=cfg.useprior,
                         nms=cfg.ovr,
                         K=cfg.k)
    if cfg.show:
        pylab.show()


#        raw_input()
    print "Detect Wrap:", time.time() - t
    return res
Пример #3
0
def loadDetectionsRamanan(fn):
    f = util.loadmat(fn)
    ids = f['ids']
    scores = []
    if f.has_key('sc'):
        scores = f['sc']
    boxes = f['BB']
    n = len(ids)

    det = []
    for i in range(n):
        this_id = ids[i][0][0].split(".")[0]
        if not scores == []:
            this_score = scores[i][0]
        else:
            this_score = 1.0
        box = boxes[:, i]
        x1 = float(box[0])
        y1 = float(box[1])
        x2 = float(box[2])
        y2 = float(box[3])
        det.append([this_id, this_score, x1, y1, x2, y2])
        if 0:
            im = util.myimread(
                "/users/visics/mpederso/databases/afw/testimages/" + this_id +
                ".jpg")
            pylab.clf()
            pylab.imshow(im)
            util.box([y1, x1, y2, x2])
            pylab.draw()
            pylab.show()
            raw_input()
    dets = sorted(det, key=itemgetter(1), reverse=True)
    return dets
Пример #4
0
def detectWrap(a):
    i=a[0]
    imname=a[1]
    bbox=a[2]
    models=a[3]
    cfg=a[4]
    if cfg.show:
        img=util.myimread(imname)
        pylab.figure(10)
        pylab.ioff()
        pylab.clf()
        pylab.axis("off")
        pylab.imshow(img,interpolation="nearest",animated=True) 
    if bbox!=None:
        gtbbox=[{"bbox":x} for x in bbox]   
    else:
        gtbbox=None
    notsave=False
    #if cfg.__dict__.has_key("test"):
    #    notsave=cfg.test
    f=pyrHOG2.pyrHOG(imname,interv=10,savedir=cfg.auxdir+"/hog/",notsave=not(cfg.savefeat),notload=not(cfg.loadfeat),hallucinate=cfg.hallucinate,cformat=True)
    res=[]
    for clm,m in enumerate(models):
        res.append(pyrHOG2.detect(f,m,gtbbox,hallucinate=cfg.hallucinate,initr=cfg.initr,ratio=cfg.ratio,deform=cfg.deform,bottomup=cfg.bottomup,usemrf=cfg.usemrf,numneg=cfg.numneg,thr=cfg.thr,posovr=cfg.posovr,minnegincl=cfg.minnegincl,small=cfg.small,show=cfg.show,cl=clm,mythr=cfg.mythr,mpos=cfg.mpos,usefather=cfg.usefather,useprior=cfg.useprior,K=cfg.k))
    if cfg.show:
        pylab.show()
    return res
Пример #5
0
def detectWrap(a):
    i=a[0]
    imname=a[1]
    bbox=a[2]
    models=a[3]
    cfg=a[4]
    if cfg.show:
        img=util.myimread(imname)
        pylab.figure(10)
        pylab.ioff()
        pylab.clf()
        pylab.axis("off")
        pylab.imshow(img,interpolation="nearest",animated=True) 
    if bbox!=None:
        gtbbox=[{"bbox":x,"img":imname.split("/")[-1]} for x in bbox]   
    else:
        gtbbox=None
    notsave=False
    #if cfg.__dict__.has_key("test"):
    #    notsave=cfg.test
    f=pyrHOG2.pyrHOG(imname,interv=10,savedir=cfg.auxdir+"/hog/",notsave=not(cfg.savefeat),notload=not(cfg.loadfeat),hallucinate=cfg.hallucinate,cformat=True)
    res=[]
    for clm,m in enumerate(models):
        res.append(pyrHOG2.detect(f,m,gtbbox,hallucinate=cfg.hallucinate,initr=cfg.initr,ratio=cfg.ratio,deform=cfg.deform,bottomup=cfg.bottomup,usemrf=cfg.usemrf,numneg=cfg.numneg,thr=cfg.thr,posovr=cfg.posovr,minnegincl=cfg.minnegincl,small=cfg.small,show=cfg.show,cl=clm,mythr=cfg.mythr,mpos=cfg.mpos,usefather=cfg.usefather,useprior=cfg.useprior,emptybb=False,K=cfg.k))
    if cfg.show:
        pylab.show()
    return res
Пример #6
0
def loadDetectionsRamanan(fn):
    f = util.loadmat(fn)
    ids = f['ids']
    scores = []
    if f.has_key('sc'):
        scores = f['sc']
    boxes = f['BB']
    n = len(ids)

    det = []
    for i in range(n):
        this_id = ids[i][0][0].split(".")[0]
        if not scores == []:
            this_score = scores[i][0]
        else:
            this_score = 1.0
        box = boxes[:, i]
        x1 = float(box[0])
        y1 = float(box[1])
        x2 = float(box[2])
        y2 = float(box[3])
        det.append([this_id, this_score, x1, y1, x2, y2])
        if 0:
            im = util.myimread(
                "/users/visics/mpederso/databases/afw/testimages/" + this_id + ".jpg")
            pylab.clf()
            pylab.imshow(im)
            util.box([y1, x1, y2, x2])
            pylab.draw()
            pylab.show()
            raw_input()
    dets = sorted(det, key=itemgetter(1), reverse=True)
    return dets
Пример #7
0
def collec_posamples_2(minA,trPosImagesNoTrunc,cfg):
    lfy=cfg.fy;lfx=cfg.fx
    check = False
    dratios=numpy.array(lfy[:cfg.numcl])/numpy.array(lfx[:cfg.numcl])
    hogp=[[] for x in range(cfg.numcl*2)]
    #hogpcl=[]
    annp=[[] for x in range(cfg.numcl*2)]

    #from scipy.ndimage import zoom
    from extra import myzoom as zoom
    for im in trPosImagesNoTrunc: # for each image

        #print im["name"]
        aim=util.myimread(im["name"])  
        for bb in im["bbox"]: # for each bbox (y1,x1,y2,x2)
            imy=bb[2]-bb[0]
            imx=bb[3]-bb[1]
            cropratio= imy/float(imx)
            #select the right model based on aspect ratio
            idm=numpy.argmin(abs(dratios-cropratio))
            area=imy*imx
            usesmall=False
            if area/16/cfg.N**2<minA[idm]:#use small model if there
                idm=idm+cfg.numcl
            fy=lfy[idm];fx=lfx[idm]
            crop=aim[max(0,bb[0]-imy/fy/2):min(bb[2]+imy/fy/2,aim.shape[0]),max(0,bb[1]-imx/fx/2):min(bb[3]+imx/fx/2,aim.shape[1])]
            #crop=extra.getfeat(aim,abb[0]-imy/(lfy[idm]*2),bb[2]+imy/(lfy[idm]*2),bb[1]-imx/(cfg.fx[idm]*2),bb[3]+imx/(cfg.fx[idm]*2))
            imy=crop.shape[0]
            imx=crop.shape[1]
            zcim=zoom(crop,(((fy*cfg.N+2)*8/float(imy)),((fx*cfg.N+2)*8/float(imx)),1),order=1)
            hogp[idm].append(numpy.ascontiguousarray(pyrHOG2.hog(zcim)))
            if cfg.trunc:
                hogp[idm][-1]=numpy.concatenate((hogp[idm][-1],numpy.zeros((hogp[idm][-1].shape[0],hogp[idm][-1].shape[1],1))),2)
            #hogpcl.append(idm)
            annp[idm].append({"file":im["name"],"bbox":bb})
            if check:
                print "Aspect:",idm,"Det Size",fy*cfg.N,fx*cfg.N,"Shape:",zcim.shape
                pl.figure(1,figsize=(20,5))
                pl.clf()
                pl.subplot(1,3,1)
                pl.imshow(aim,interpolation="nearest")            
                pl.subplot(1,3,2)
                pl.imshow(zcim,interpolation="nearest")
                pl.subplot(1,3,3)
                import drawHOG
                imh=drawHOG.drawHOG(hogp[-1])
                pl.imshow(imh,interpolation="nearest")
                pl.draw()
                pl.show()
                raw_input()
    return hogp
Пример #8
0
                auxcl = tr.mixture(nfuseneg)[0]
                dns = buildense([aux], [auxcl], cumsize)[0]
                dscr = numpy.sum(dns * w)
                #print "Scr:",nfuseneg[0]["scr"],"DesneSCR:",dscr,"Diff:",abs(nfuseneg[0]["scr"]-dscr)
                if abs(nfuseneg[0]["scr"] - dscr) > 0.0001:
                    print "Warning: the two scores must be the same!!!"
                    print "Scr:", nfuseneg[0][
                        "scr"], "DesneSCR:", dscr, "Diff:", abs(
                            nfuseneg[0]["scr"] - dscr)
                    raw_input()
            if cfg.show:
                pylab.figure(20)
                pylab.ioff()
                pylab.clf()
                pylab.axis("off")
                img = util.myimread(trPosImages[ii]["name"])
                pylab.imshow(img, interpolation="nearest", animated=True)
                tr.show(nfuse, parts=cfg.show)
                pylab.show()
                #raw_input()
        del itr

        #fulltrpos=trpos
        #fulltrposcl=trposcl
        #trpos=remove_empty(fulltrpos)
        #trposcl=remove_empty(fulltrposcl)
        numoldtrpos = len(trpos)
        if it > 0:
            moldloss = loss_pos(trpos, trposcl, cumsize)
        else:
            moldloss = 1
Пример #9
0
def detectWrap(a):
    i = a[0]
    imname = a[1]
    bbox = a[2]
    models = a[3]
    cfg = a[4]
    if len(a) <= 5:
        imageflip = False
    else:
        imageflip = a[5]
    img = util.myimread(imname, resize=cfg.resize)
    if imageflip:
        img = util.myimread(imname, True, resize=cfg.resize)
        if bbox != None:
            bbox = util.flipBBox(img, bbox)
    if bbox != None:
        gtbbox = [{"bbox": x, "img": imname.split("/")[-1]} for x in bbox]
    else:
        gtbbox = None
    if cfg.show:
        img = util.myimread(imname, imageflip, resize=cfg.resize)
        pylab.figure(10)
        pylab.ioff()
        pylab.clf()
        pylab.axis("off")
        pylab.imshow(img, interpolation="nearest", animated=True)
    notsave = False
    #if cfg.__dict__.has_key("test"):
    #    notsave=cfg.test
    #f=pyrHOG2.pyrHOG(imname,interv=10,savedir=cfg.auxdir+"/hog/",notsave=not(cfg.savefeat),notload=not(cfg.loadfeat),hallucinate=cfg.hallucinate,cformat=True,flip=imageflip,resize=cfg.resize)
    f = pyrHOG2.pyrHOG(img,
                       interv=10,
                       savedir=cfg.auxdir + "/hog/",
                       notsave=not (cfg.savefeat),
                       notload=not (cfg.loadfeat),
                       hallucinate=cfg.hallucinate,
                       cformat=True)  #,flip=imageflip,resize=cfg.resize)
    res = []
    for clm, m in enumerate(models):
        if cfg.useRL:
            res.append(
                pyrHOG2RL.detectflip(f,
                                     m,
                                     gtbbox,
                                     hallucinate=cfg.hallucinate,
                                     initr=cfg.initr,
                                     ratio=cfg.ratio,
                                     deform=cfg.deform,
                                     bottomup=cfg.bottomup,
                                     usemrf=cfg.usemrf,
                                     numneg=cfg.numneg,
                                     thr=cfg.thr,
                                     posovr=cfg.posovr,
                                     minnegincl=cfg.minnegincl,
                                     small=cfg.small,
                                     show=cfg.show,
                                     cl=clm,
                                     mythr=cfg.mythr,
                                     mpos=cfg.mpos,
                                     usefather=cfg.usefather,
                                     useprior=cfg.useprior,
                                     K=cfg.k))
        else:
            res.append(
                pyrHOG2.detect(f,
                               m,
                               gtbbox,
                               hallucinate=cfg.hallucinate,
                               initr=cfg.initr,
                               ratio=cfg.ratio,
                               deform=cfg.deform,
                               bottomup=cfg.bottomup,
                               usemrf=cfg.usemrf,
                               numneg=cfg.numneg,
                               thr=cfg.thr,
                               posovr=cfg.posovr,
                               minnegincl=cfg.minnegincl,
                               small=cfg.small,
                               show=cfg.show,
                               cl=clm,
                               mythr=cfg.mythr,
                               mpos=cfg.mpos,
                               usefather=cfg.usefather,
                               useprior=cfg.useprior,
                               emptybb=False,
                               K=cfg.k))
    if cfg.show:
        pylab.draw()
        pylab.show()
    return res
Пример #10
0
                auxcl = tr.mixture(nfuseneg)[0]
                dns = buildense([aux], [auxcl], cumsize)[0]
                dscr = numpy.sum(dns * w)
                #print "Scr:",nfuseneg[0]["scr"],"DesneSCR:",dscr,"Diff:",abs(nfuseneg[0]["scr"]-dscr)
                if abs(nfuseneg[0]["scr"] - dscr) > 0.0001:
                    print "Warning: the two scores must be the same!!!"
                    print "Scr:", nfuseneg[0][
                        "scr"], "DesneSCR:", dscr, "Diff:", abs(
                            nfuseneg[0]["scr"] - dscr)
                    raw_input()
            if cfg.show:
                pylab.figure(20)
                pylab.ioff()
                pylab.clf()
                pylab.axis("off")
                img = util.myimread(trPosImages[ii / 2]["name"], flip=ii % 2)
                pylab.imshow(img, interpolation="nearest", animated=True)
                tr.show(nfuse, parts=cfg.show)
                pylab.show()
                #raw_input()
        del itr

        #fulltrpos=trpos
        #fulltrposcl=trposcl
        #trpos=remove_empty(fulltrpos)
        #trposcl=remove_empty(fulltrposcl)
        numoldtrpos = len(trpos)
        if it > 0:
            moldloss, oldscr = loss_pos(trpos, trposcl, cumsize)
        else:
            moldloss = 1
Пример #11
0
                auxcl = tr.mixture(nfuseneg)[0]
                dns = buildense([aux], [auxcl], cumsize)[0]
                dscr = numpy.sum(dns * w)
                #print "Scr:",nfuseneg[0]["scr"],"DesneSCR:",dscr,"Diff:",abs(nfuseneg[0]["scr"]-dscr)
                if abs(nfuseneg[0]["scr"] - dscr) > 0.0001:
                    print "Warning: the two scores must be the same!!!"
                    print "Scr:", nfuseneg[0][
                        "scr"], "DesneSCR:", dscr, "Diff:", abs(
                            nfuseneg[0]["scr"] - dscr)
                    raw_input()
            if cfg.show:
                pylab.figure(20)
                pylab.ioff()
                pylab.clf()
                pylab.axis("off")
                img = util.myimread(trPosImages[ii]["name"])
                pylab.imshow(img, interpolation="nearest", animated=True)
                tr.show(nfuse, parts=cfg.show)
                pylab.show()
                #raw_input()
        del itr

        #fulltrpos=trpos
        #fulltrposcl=trposcl
        #trpos=remove_empty(fulltrpos)
        #trposcl=remove_empty(fulltrposcl)
        numoldtrpos = len(trpos)
        if it > 0:
            moldloss = loss_pos(trpos, trposcl, cumsize)
        else:
            moldloss = 1
Пример #12
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
Пример #13
0
    cpit=0
    cnit=0
    print "Starting from scratch"
    lg.info("Starting from scratch")
    ############################ initialize positive using cropped bounidng boxes
    check = False
    dratios=numpy.array(cfg.fy)/numpy.array(cfg.fx)
    hogp=[[] for x in range(cfg.numcl)]
    hogpcl=[]
    annp=[[] for x in range(cfg.numcl)]

    #from scipy.ndimage import zoom
    from extra import myzoom as zoom
    for im in trPosImagesNoTrunc: # for each image

        aim=util.myimread(im["name"])  
        for bb in im["bbox"]: # for each bbox (y1,x1,y2,x2)
            imy=bb[2]-bb[0]
            imx=bb[3]-bb[1]
            cropratio= imy/float(imx)
            #select the right model based on aspect ratio
            idm=numpy.argmin(abs(dratios-cropratio))
            crop=aim[max(0,bb[0]-imy/cfg.fy[idm]/2):min(bb[2]+imy/cfg.fy[idm]/2,aim.shape[0]),max(0,bb[1]-imx/cfg.fx[idm]/2):min(bb[3]+imx/cfg.fx[idm]/2,aim.shape[1])]
            #crop=extra.getfeat(aim,abb[0]-imy/(cfg.fy[idm]*2),bb[2]+imy/(cfg.fy[idm]*2),bb[1]-imx/(cfg.fx[idm]*2),bb[3]+imx/(cfg.fx[idm]*2))
            imy=crop.shape[0]
            imx=crop.shape[1]
            zcim=zoom(crop,(((cfg.fy[idm]*cfg.N+2)*8/float(imy)),((cfg.fx[idm]*cfg.N+2)*8/float(imx)),1),order=1)
            hogp[idm].append(numpy.ascontiguousarray(pyrHOG2.hog(zcim)))
            if cfg.trunc:
                hogp[idm][-1]=numpy.concatenate((hogp[idm][-1],numpy.zeros((hogp[idm][-1].shape[0],hogp[idm][-1].shape[1],1))),2)
            #hogpcl.append(idm)
Пример #14
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
Пример #15
0
 def getImage(self, i):
     item = self.ann[i][0][0]
     return myimread((self.imagepath + item))
Пример #16
0
 def getImageByName(self, name):
     return myimread(name)
Пример #17
0
 def getImage(self, i):
     item = self.selines[i]
     return myimread((self.imagepath + item.split(" ")[0]) + ".jpg")
Пример #18
0
    #det=util.load("/users/visics/mpederso/code/git/condor-run/N2C2_posthr105/CRFdet/data/CRF/12_10_21/%s2_N2C2k01_final.det"%(cfg.cls))["det"]
    #det=util.load("/users/visics/mpederso/code/git/condor-run/N2C2_posthr105/CRFdet/data/CRF/12_10_20/%s2_N2C2_final.det"%(cfg.cls))["det"]
    #det=util.load("/users/visics/mpederso/code/git/condor-run/N2C2_posthr105/CRFdet/data/CRF/12_10_20/%s2_N2C26.det"%(cfg.cls))["det"]
    #cfg.N=4
    #det=util.load("/users/visics/mpederso/code/git/condor-run/N3C2_highres/CRFdet/data/CRF/12_11_10/%s2_N2C2highres2_final.det"%cfg.cls)["det"]
    #det=util.load("/users/visics/mpederso/code/git/condor-run/N3C2_highres/CRFdet/data/CRF/12_11_10/%s2_N2C2highres26.det"%cfg.cls)["det"]
    #det=util.load("/users/visics/mpederso/code/git/condor-run/N2C2_highres/CRFdet/data/CRF/12_11_01/bicycle2_N1C2highres2.det")["det"];cfg.N=1
    #det=util.load("/users/visics/mpederso/code/git/CRFdet/data/afterCVPR/12_01_10/%s2_force-bb3.det"%cfg.cls)["det"]
    #det=util.load("./data/condor/%s2_condor10.det"%cfg.cls)["det"]sftp://[email protected]/users/visics/mpederso/code/git/fastDP/CRFdet/data/debug2/car2_FULLsmall4.det
    det=util.load("./data/debug2/%s2_higherlimit2.det"%cfg.cls)["det"]
    imgpath=cfg.dbpath+"VOC2007/VOCdevkit/VOC2007/JPEGImages/"
    #imgpath=cfg.dbpath+"/buffy/images/"
    line=True
    cfg.N=3
    for idl,l in enumerate(det):
        img=util.myimread(imgpath+l["idim"])
#just for buffy
#        try:
#           img=util.myimread(imgpath+"buffy_s5e2/"+l["idim"])
#        except:
#            try:    
#                img=util.myimread(imgpath+"buffy_s5e3/"+l["idim"])
#            except:
#                try:
#                    img=util.myimread(imgpath+"buffy_s5e4/"+l["idim"])
#                except:
#            try:
#                img=util.myimread(imgpath+"buffy_s5e5/"+l["idim"])
#            except:
#                try:
#                    img=util.myimread(imgpath+"buffy_s5e6/"+l["idim"])
Пример #19
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
Пример #20
0
             else:
                 aux=tr.descr(nfuseneg)[0]
             auxcl=tr.mixture(nfuseneg)[0]
             dns=buildense([aux],[auxcl],cumsize)[0]
             dscr=numpy.sum(dns*w)
             #print "Scr:",nfuseneg[0]["scr"],"DesneSCR:",dscr,"Diff:",abs(nfuseneg[0]["scr"]-dscr)
             if abs(nfuseneg[0]["scr"]-dscr)>0.0001:
                 print "Warning: the two scores must be the same!!!"
                 print "Scr:",nfuseneg[0]["scr"],"DesneSCR:",dscr,"Diff:",abs(nfuseneg[0]["scr"]-dscr)
                 raw_input()
         if cfg.show:
             pylab.figure(20)
             pylab.ioff()
             pylab.clf()
             pylab.axis("off")
             img=util.myimread(trPosImages[ii/2]["name"],flip=ii%2)
             pylab.imshow(img,interpolation="nearest",animated=True)
             tr.show(nfuse,parts=cfg.show)      
             pylab.show()
             #raw_input()
     del itr
 
     #fulltrpos=trpos
     #fulltrposcl=trposcl
     #trpos=remove_empty(fulltrpos)
     #trposcl=remove_empty(fulltrposcl)
     numoldtrpos=len(trpos)
     if it>0:
         moldloss,oldscr=loss_pos(trpos,trposcl,cumsize)
     else:
         moldloss=1
Пример #21
0
else:
    itr = mypool.imap(detectWrap, arg)
for i, im in enumerate(itr):
    print "---- Image %d----" % i
    print "Detections:", len(im[1])
    dettime.append(im[2])
    numhog += im[3]
    tr = im[0]
    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[i]["name"], resize=RSZ)
    pylab.imshow(img, interpolation="nearest", animated=True)
    pylab.axis("off")
    tr.show(im[1], parts=True, thr=-0.5, scr=True, maxnum=3)
    pylab.axis((0, img.shape[1], img.shape[0], 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]:
Пример #22
0
 def getImage(self, i):
     i = i + int(self.total / self.totalfold) * self.fold
     item = self.selines[i]
     return myimread((self.imagepath + item.split(" ")[0]))
Пример #23
0
       

    import pylab as pl
    import util
    import detectCRF
    #det=util.load("./data/CRF/12_10_02_parts_full/bicycle2_testN1_final.det")["det"]
    #det=util.load("./data/CRF/12_10_02_parts_full/bicycle2_testN2_final.txt")
    #fl=open("./data/CRF/12_10_02_parts_full/bicycle2_testN2_final.txt")
    fl=open("./data/inria1_inria3.txt")
    det=fl.readlines()
    imgpath=cfg.dbpath+"VOC2007/VOCdevkit/VOC2007/JPEGImages/"#VOC
    imgpath=cfg.dbpath+"INRIAPerson/Test/pos/"#inria
    for idl,l in enumerate(det):
        imname,scr,b0,b1,b2,b3=l.split()
        try:
            img=util.myimread(imgpath+imname+".png")
        except:
            img=util.myimread(imgpath+imname+".jpg")
        pl.figure(100)        
        pl.clf()
        pl.imshow(img)
        util.box(int(b1),int(b0),int(b3),int(b2),"w",lw=2)
        pl.title("Rank:%d Scr:%.3f"%(idl,float(scr)))
        pl.axis([0,img.shape[1],img.shape[0],0])
        #detectCRF.visualize2([l],2,img,text="rank:%d"%(idl))
        pl.draw()
        pl.show()
        raw_input()


Пример #24
0
 def getImage(self, i):
     self.cur.execute(
         "SELECT filepath FROM FaceImages WHERE file_id = '%s'" %
         self.items[i][0])
     impath = self.cur.fetchall()
     return myimread((impath))
Пример #25
0
if not(cfg.multipr):
    itr=itertools.imap(detectWrap,arg)        
else:
    itr=mypool.imap(detectWrap,arg)
for i,im in enumerate(itr):
    print "---- Image %d----"%i
    print "Detections:", len(im[1]) 
    dettime.append(im[2])
    numhog+=im[3]
    tr=im[0]
    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[i]["name"],resize=RSZ)
    pylab.imshow(img,interpolation="nearest",animated=True)
    pylab.axis("off")
    tr.show(im[1],parts=True,thr=-0.5,scr=True,maxnum=3)
    pylab.axis((0,img.shape[1],img.shape[0],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
Пример #26
0
 def getImageByName2(self, name):
     return myimread(self.imagepath + name + ".jpg")
Пример #27
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