newtrneg = [] newtrnegcl = [] negratio = [-1] posratio = [-1] nexratio = [-1] fobj = [] cumsize = None last_round = False w = None oldprloss = numpy.zeros((0, 6)) totPosEx = 0 for i in range(len(trPosImages)): totPosEx += len(trPosImages[i]["bbox"]) totPosEx *= 2 pyrHOG2.setK(cfg.k) #pyrHOG2.setDENSE(cfg.dense) for it in range(cfg.posit): if last_round: print "Finished!!!!" break #trpos=[] #numoldtrpos=len(trpos) #trpos=fulltrpos #trposcl=fulltrposcl #numoldtrposcl=len(trposcl) #trposcl=[] #just for test newtrneg = [] newtrnegcl = [] cntnochange = 0
def detectflip(f,m,gtbbox=None,auxdir=".",hallucinate=1,initr=1,ratio=1,deform=False,bottomup=False,usemrf=False,numneg=0,thr=-2,posovr=0.7,minnegincl=0.5,small=True,show=False,cl=0,mythr=-10,nms=0.5,inclusion=False,usefather=True,mpos=1,useprior=False,K=1.0,occl=False,trunc=0): """Detect objects with RL flip used for both test --> gtbbox=None and trainig --> gtbbox = list of bounding boxes """ #build flip pyrHOG2.setK(K) m1=flip(m) t=time.time() if gtbbox!=None and gtbbox!=[] and useprior: pr=f.buildPrior(gtbbox,m["fy"],m["fx"]) else: pr=None t=time.time() f.resetHOG() if deform: if bottomup: scr,pos=f.scanRCFLDefBU(m,initr=initr,ratio=ratio,small=small,usemrf=usemrf) scr1,pos1=f.scanRCFLDefBU(m1,initr=initr,ratio=ratio,small=small,usemrf=usemrf) else: #scr,pos=f.scanRCFLDefThr(m,initr=initr,ratio=ratio,small=small,usemrf=usemrf,mythr=mythr) scr,pos=f.scanRCFLDef(m,initr=initr,ratio=ratio,small=small,usemrf=usemrf,trunc=trunc) #scr1,pos1=f.scanRCFLDefThr(m1,initr=initr,ratio=ratio,small=small,usemrf=usemrf,mythr=mythr) scr1,pos1=f.scanRCFLDef(m1,initr=initr,ratio=ratio,small=small,usemrf=usemrf,trunc=trunc) else: scr,pos=f.scanRCFL(m,initr=initr,ratio=ratio,small=small,trunc=trunc) scr1,pos1=f.scanRCFL(m1,initr=initr,ratio=ratio,small=small,trunc=trunc) lr=[] fscr=[] for idl,l in enumerate(scr): auxscr=numpy.zeros((l.shape[0],l.shape[1],2),numpy.float32) auxscr[:,:,0]=scr[idl] auxscr[:,:,1]=scr1[idl] fscr.append(numpy.max(auxscr,2)) lr.append(numpy.argmax(auxscr,2)) if 0: pylab.figure(101) pylab.clf() print auxscr[:,:,0] print auxscr[:,:,1] pylab.imshow(lr[-1]) pylab.show() raw_input() if deform: tr=TreatDefRL(f,fscr,pos,pos1,lr,initr,m["fy"],m["fx"],occl=occl,trunc=trunc) else: tr=TreatRL(f,fscr,pos,pos1,lr,initr,m["fy"],m["fx"],occl=occl,trunc=trunc) numhog=f.getHOG() if gtbbox==None: if show==True: showlabel="Parts" else: showlabel=False ref=0#enable TD+BU if ref: t1=time.time() det=tr.doall(thr=thr,rank=100,refine=True,rawdet=False,cluster=False,show=False,inclusion=inclusion,cl=cl) detR=[];detL=[] for d in det: if d["rl"]==1: detR.append(d) else: detL.append(d) samplesR=tr.goodsamples(detR,initr=initr,ratio=ratio) samplesL=tr.goodsamples(detL,initr=initr,ratio=ratio) scrR,posR=f.scanRCFLDefBU(m,initr=initr,ratio=ratio,small=small,usemrf=usemrf,mysamples=samplesR) scrL,posL=f.scanRCFLDefBU(m1,initr=initr,ratio=ratio,small=small,usemrf=usemrf,mysamples=samplesL) lr=[];fscr=[] for idl,l in enumerate(scrR): auxscr=numpy.zeros((l.shape[0],l.shape[1],2),numpy.float32) auxscr[:,:,0]=scrR[idl] auxscr[:,:,1]=scrL[idl] fscr.append(numpy.max(auxscr,2)) lr.append(numpy.argmax(auxscr,2)) print "Refine Time:",time.time()-t1 tr=TreatDefRL(f,fscr,posR,posL,lr,initr,m["fy"],m["fx"],occl=occl) det=tr.doall(thr=thr,rank=100,refine=True,rawdet=False,cluster=nms,show=False,inclusion=inclusion,cl=cl) else: det=tr.doall(thr=thr,rank=100,refine=True,rawdet=False,cluster=nms,show=False,inclusion=inclusion,cl=cl) dettime=time.time()-t if show: tr.show(det,parts=showlabel,thr=-1.0,maxnum=0) print "Detect: %.3f"%(time.time()-t) return tr,det,dettime,numhog else: best1,worste1=tr.doalltrain(gtbbox,thr=thr,rank=1000,show=show,mpos=mpos,numpos=1,posovr=posovr,numneg=numneg,minnegovr=0,minnegincl=minnegincl,cl=cl) ipos=[];ineg=[] if False and show and len(best1)>0: import util ds=tr.descr(best1,flip=False,usemrf=usemrf,usefather=usefather,k=K) pylab.figure(120) pylab.clf() mm=tr.model(ds[0],0,len(m1["ww"]),31) util.drawModel(mm["ww"]) pylab.show() #raw_input() print "Detect: %.3f"%(time.time()-t) return tr,best1,worste1,ipos,ineg
newtrneg = [] newtrnegcl = [] negratio = [-1] posratio = [-1] nexratio = [-1] fobj = [] cumsize = None last_round = False w = None oldprloss = numpy.zeros((0, 6)) totPosEx = 0 for i in range(len(trPosImages)): totPosEx += len(trPosImages[i]["bbox"]) #totPosEx*=2 pyrHOG2.setK(cfg.k) #pyrHOG2.setDENSE(cfg.dense) for it in range(cfg.posit): if last_round: print "Finished!!!!" break #trpos=[] #numoldtrpos=len(trpos) #trpos=fulltrpos #trposcl=fulltrposcl #numoldtrposcl=len(trposcl) #trposcl=[] #just for test newtrneg = [] newtrnegcl = [] cntnochange = 0
def detectflip(f, m, gtbbox=None, auxdir=".", hallucinate=1, initr=1, ratio=1, deform=False, bottomup=False, usemrf=False, numneg=0, thr=-2, posovr=0.7, minnegincl=0.5, small=True, show=False, cl=0, mythr=-10, nms=0.5, inclusion=False, usefather=True, mpos=1, useprior=False, K=1.0, occl=False, trunc=0): """Detect objects with RL flip used for both test --> gtbbox=None and trainig --> gtbbox = list of bounding boxes """ #build flip pyrHOG2.setK(K) m1 = flip(m) t = time.time() if gtbbox != None and gtbbox != [] and useprior: pr = f.buildPrior(gtbbox, m["fy"], m["fx"]) else: pr = None t = time.time() f.resetHOG() if deform: if bottomup: scr, pos = f.scanRCFLDefBU(m, initr=initr, ratio=ratio, small=small, usemrf=usemrf) scr1, pos1 = f.scanRCFLDefBU(m1, initr=initr, ratio=ratio, small=small, usemrf=usemrf) else: #scr,pos=f.scanRCFLDefThr(m,initr=initr,ratio=ratio,small=small,usemrf=usemrf,mythr=mythr) scr, pos = f.scanRCFLDef(m, initr=initr, ratio=ratio, small=small, usemrf=usemrf, trunc=trunc) #scr1,pos1=f.scanRCFLDefThr(m1,initr=initr,ratio=ratio,small=small,usemrf=usemrf,mythr=mythr) scr1, pos1 = f.scanRCFLDef(m1, initr=initr, ratio=ratio, small=small, usemrf=usemrf, trunc=trunc) else: scr, pos = f.scanRCFL(m, initr=initr, ratio=ratio, small=small, trunc=trunc) scr1, pos1 = f.scanRCFL(m1, initr=initr, ratio=ratio, small=small, trunc=trunc) lr = [] fscr = [] for idl, l in enumerate(scr): auxscr = numpy.zeros((l.shape[0], l.shape[1], 2), numpy.float32) auxscr[:, :, 0] = scr[idl] auxscr[:, :, 1] = scr1[idl] fscr.append(numpy.max(auxscr, 2)) lr.append(numpy.argmax(auxscr, 2)) if 0: pylab.figure(101) pylab.clf() print auxscr[:, :, 0] print auxscr[:, :, 1] pylab.imshow(lr[-1]) pylab.show() raw_input() if deform: tr = TreatDefRL(f, fscr, pos, pos1, lr, initr, m["fy"], m["fx"], occl=occl, trunc=trunc) else: tr = TreatRL(f, fscr, pos, pos1, lr, initr, m["fy"], m["fx"], occl=occl, trunc=trunc) numhog = f.getHOG() if gtbbox == None: if show == True: showlabel = "Parts" else: showlabel = False ref = 0 #enable TD+BU if ref: t1 = time.time() det = tr.doall(thr=thr, rank=100, refine=True, rawdet=False, cluster=False, show=False, inclusion=inclusion, cl=cl) detR = [] detL = [] for d in det: if d["rl"] == 1: detR.append(d) else: detL.append(d) samplesR = tr.goodsamples(detR, initr=initr, ratio=ratio) samplesL = tr.goodsamples(detL, initr=initr, ratio=ratio) scrR, posR = f.scanRCFLDefBU(m, initr=initr, ratio=ratio, small=small, usemrf=usemrf, mysamples=samplesR) scrL, posL = f.scanRCFLDefBU(m1, initr=initr, ratio=ratio, small=small, usemrf=usemrf, mysamples=samplesL) lr = [] fscr = [] for idl, l in enumerate(scrR): auxscr = numpy.zeros((l.shape[0], l.shape[1], 2), numpy.float32) auxscr[:, :, 0] = scrR[idl] auxscr[:, :, 1] = scrL[idl] fscr.append(numpy.max(auxscr, 2)) lr.append(numpy.argmax(auxscr, 2)) print "Refine Time:", time.time() - t1 tr = TreatDefRL(f, fscr, posR, posL, lr, initr, m["fy"], m["fx"], occl=occl) det = tr.doall(thr=thr, rank=100, refine=True, rawdet=False, cluster=nms, show=False, inclusion=inclusion, cl=cl) else: det = tr.doall(thr=thr, rank=100, refine=True, rawdet=False, cluster=nms, show=False, inclusion=inclusion, cl=cl) dettime = time.time() - t if show: tr.show(det, parts=showlabel, thr=-1.0, maxnum=0) print "Detect: %.3f" % (time.time() - t) return tr, det, dettime, numhog else: best1, worste1 = tr.doalltrain(gtbbox, thr=thr, rank=1000, show=show, mpos=mpos, numpos=1, posovr=posovr, numneg=numneg, minnegovr=0, minnegincl=minnegincl, cl=cl) ipos = [] ineg = [] if False and show and len(best1) > 0: import util ds = tr.descr(best1, flip=False, usemrf=usemrf, usefather=usefather, k=K) pylab.figure(120) pylab.clf() mm = tr.model(ds[0], 0, len(m1["ww"]), 31) util.drawModel(mm["ww"]) pylab.show() #raw_input() print "Detect: %.3f" % (time.time() - t) return tr, best1, worste1, ipos, ineg