Beispiel #1
0
 def prepBenchm():
     cb.clearMemory(m)
     for frame in frameset[:-1]:
         m(
             torch.autograd.Variable(frame,
                                     volatile=True,
                                     requires_grad=False))
     if cuda:
         torch.cuda.synchronize()
Beispiel #2
0
def inferFrameset(m, frameset, cuda=True, preprocessor=None, postproc=None):
    if preprocessor is not None:
        frameset = list(map(preprocessor, frameset))
    if cuda:
        frameset = [frm.cuda() for frm in frameset]
    cb.clearMemory(m)

    for frame in frameset:
        y = m(
            torch.autograd.Variable(frame, volatile=True, requires_grad=False))

    if postproc is not None:
        y = postproc(y)
    return y
Beispiel #3
0
    def getModels(experimentIdx):
        experimentIdx = 11
        modelBaseline = op.PoseModel.fromFile(T=2).eval()

        if experimentIdx <= 8:
            modelTest = torch.load('models/model3.net')
        elif experimentIdx == 9:
            modelTest = torch.load('models/model009.net')
        elif experimentIdx == 10:
            modelTest = torch.load('models/model010.net'
                                   )  # experiment 10 -- trained for recursive
        elif experimentIdx == 11:
            modelTest = torch.load(
                'models/model011c.net'
            )  # recursive AND with optimized threshold selection
            # a: straight-forward, b: ???, c: no pre-init of thresholds for whole block
        else:
            assert (False)
        pycbinfer.clearMemory(modelTest)

        return modelTest, modelBaseline
Beispiel #4
0
def inferFramesetPowerMeasurement(m,
                                  frameset,
                                  cuda=True,
                                  numFrames=0,
                                  preprocessor=None):
    if preprocessor is not None:
        frameset = list(map(preprocessor, frameset))
    if cuda:
        frameset = [frm.cuda() for frm in frameset]

    #create a longer sequence by going back-and-forth on the frames we have
    if numFrames > 0:
        frameset = frameset + frameset[-2:0:-1]
        frameset = math.ceil(numFrames / len(frameset)) * frameset
        frameset = frameset[:numFrames]
    frame = frameset[0]
    cb.clearMemory(m)
    m(torch.autograd.Variable(frame, volatile=True, requires_grad=False))
    if cuda:
        torch.cuda.synchronize()
    pl = tx2power.PowerLogger(
        interval=1.0,  #interval=0.05, 
        nodes=tx2power.getNodesByName(nameList=[
            'board/main',
            'module/main',
            #                                     'module/cpu','module/gpu','module/ddr'
        ]))
    pl.start()
    for fid, frame in enumerate(frameset[1:]):
        m(torch.autograd.Variable(frame, volatile=True, requires_grad=False))


#        torch.cuda.synchronize()
#        pl.recordEvent('completed frame %d' % (fid,))
    torch.cuda.synchronize()
    pl.stop()
    return pl
Beispiel #5
0
    for m in cbconvModules:
        m.feedbackLoop = False

#apply threshold factor
cbconvThresholds = list(map(lambda m: m.threshold, cbconvModules))
for th, m in zip(cbconvThresholds, cbconvModules):
    m.threshold = thFactor * th

#%% load data
import videoSequenceReader as vsr  # select data loader and thus dataset
frameset, target = vsr.getDataFrames(seqName=seqName, numFrames=numFrames)
#apply preprocessing
frameset = list(map(poseDetEvaluator.preprocessor, frameset))

#%% trace 1 & 2: accuracy / loss & no. operations
cb.clearMemory(modelTest)
for m in cbconvModules:
    m.gatherComputationStats = True

lossTrace, opsTrace, outpVarTrace = [], [], []
for t, frm in enumerate(frameset):
    outpRef = poseDetEvaluator.modelApply(frm, modelBaseline)
    outpAct = poseDetEvaluator.modelApply(frm, modelTest)
    loss = poseDetEvaluator.evaluator(
        [outpAct], [outpRef],
        method='maxAbsDiff')  # non_MSE metric is being used (!!)
    #    loss = poseDetEvaluator.evaluator([outpAct], [outpRef], method='mse')
    lossTrace.append(loss)
    outpVarTrace.append(outpRef.var())
    numOps = reduce(
        lambda u, v: u + v,
Beispiel #6
0
else:
    poseModel = op.PoseModel.fromFile(T=2)
    #    poseModel.timed = True # enable priting timing results
    #    finegrained = True
    if useCBinfer:
        poseModel.model0 = cb.convert(poseModel.model0)
        poseModel.model1_1 = cb.convert(poseModel.model1_1)
        poseModel.model1_2 = cb.convert(poseModel.model1_2)
        poseModel.model2_1 = cb.convert(poseModel.model2_1)
        poseModel.model2_2 = cb.convert(poseModel.model2_2)
poseModel.timed = measureTiming
if gpu:
    poseModel.cuda()
else:
    poseModel.cpu()
cb.clearMemory(poseModel)
poseDet = op.PoseDetector(poseModel)

#poseModel.model0[0].finegrained = True
#poseModel.model0[0].threshold *= 0.1

#visualize first change map: plt.imshow(poseModel.model0[0].changeMap.cpu().float().numpy())
# print run time: poseModel.timed = True

frames, _ = vsr.getDataFrames(seqName=seqName, numFrames=numFrame)
if gpu:
    torch.cuda.synchronize()

##ANALYSIS 1: visualize several changeMaps
#changeMapsVis = [str(v) for v in [0,2,12,25]]
#for cmi in changeMapsVis: