def save_for_matconvnet(modelIter=60000, isSlowness=False, concatLayer='fc6', trnSeq=[], convConcat=False): modelIter = modelIter outDir = '/data1/pulkitag/others/joao/' if trnSeq != []: trnStr = 'trnSeq' + ''.join(['-%d' % t for t in trnSeq]) else: trnStr = '' print (trnStr) if not isSlowness: prms = ku.get_prms(poseType='sigMotion', maxFrameDiff=7, imSz=None, isNewExpDir=True, trnSeq=trnSeq) cPrms = get_caffe_prms(concatLayer=concatLayer, convConcat=convConcat) outName = 'kitti-' + trnStr + '-iter' + '%d.mat' % modelIter else: prms = ku.get_prms(poseType='slowness', maxFrameDiff=7, imSz=None, lossType='contrastive', nrmlzType='none', trnSeq=trnSeq) cPrms = get_caffe_prms(concatLayer=concatLayer, contrastiveMargin=1, convConcat=convConcat) outName = 'kitti_slowness_concat%s_ctMrgn%d-%d.mat' % (concatLayer, 1, modelIter) exp = setup_experiment(prms, cPrms) snapFile = exp.get_snapshot_name(modelIter) defFile = '/work4/pulkitag-code/pkgs/caffe-v2-2/modelFiles/kitti/base_files/kitti_finetune_fc6_deploy_input.prototxt' print snapFile net = mp.MyNet(defFile, snapFile) outName = os.path.join(outDir, outName) matlabRefFile = '/home/carreira/imagenet-caffe-alex.mat' mpio.save_weights_for_matconvnet(net, outName, matlabRefFile=matlabRefFile)
def train(poseType, concatLayer, maxFrameDiff, isNewExpDir, trnSeq, convConcat): prms = ku.get_prms(poseType=poseType, concatLayer=concatLayer, isNewExpDir=isNewExpDir, maxFrameDiff=maxFrameDiff, trnSeq=trnSeq, imSz=None) cPrms = kn.get_caffe_prms(concatLayer=concatLayer, convConcat=convConcat) kn.run_experiment(prms, cPrms)
def run_sun_layerwise(deviceId=1, runNum=2, addFc=True, addDrop=True, fine_base_lr=0.001, imgntMean=False, stepsize=20000, resumeIter=None): #maxLayers = ['fc6', 'pool5', 'relu4', 'relu3', 'pool2', 'pool1'] #lrAbove = ['fc6', 'conv5', 'conv4', 'conv3', 'conv2', 'conv2'] maxLayers = ['fc6'] lrAbove = ['conv1'] prms = ku.get_prms(poseType='sigMotion', maxFrameDiff=7, imSz=None, isNewExpDir=True) for mxl, abv in zip(reversed(maxLayers), reversed(lrAbove)): cPrms = get_caffe_prms(concatLayer='fc6', fineMaxLayer=mxl, lrAbove=abv, fineMaxIter=40000, deviceId=deviceId, fineRunNum=runNum, fine_base_lr=fine_base_lr, extraFc=addFc, addDrop=addDrop, imgntMean=imgntMean) #exp = make_experiment(prms, cPrms, True, resumeIter=resumeIter) run_experiment(prms, cPrms, True, resumeIter=resumeIter)
def get_default_prms(netType='kitti', poseType='sigMotion', trnSeq=[]): ''' netType : 'kitti'- for net trained on kitti poseType: 'sigMotion' - for training with kitti with description in paper 'slowness' - the slowness n/w - used as baseline in paper trnSeq: [] - to use the default n/w [0] - for 25% of data (appx) [0,8] - for 45% of data (appx) ''' kwargs = {} kwargs['concatLayer'] = 'conv5' kwargs['maxFrameDiff'] = 7 kwargs['imSz'] = None kwargs['trnSeq'] = trnSeq kwargs['poseType'] = poseType kwargs['isNewExpDir'] = False if 'conv' in kwargs['concatLayer']: convConcat = True else: convConcat = False if netType == 'kitti': prms = ku.get_prms(**kwargs) cPrms = kn.get_caffe_prms(concatLayer='conv5', convConcat=convConcat) else: raise Exception('netType not recognized') return prms, cPrms
def run_sun_finetune(deviceId=1, runNum=2, addFc=True, addDrop=True, fine_base_lr=0.001, imgntMean=True, stepsize=20000, resumeIter=None, fineMaxIter=100000, concatLayer='fc6', sourceModelIter=150000): #Set the prms prms = ku.get_prms(poseType='sigMotion', maxFrameDiff=7, imSz=None, isNewExpDir=True) #Get CaffePrms cPrms = get_caffe_prms(concatLayer=concatLayer, sourceModelIter=sourceModelIter, fineMaxIter=fineMaxIter, fine_base_lr=fine_base_lr, extraFc=addFc, addDrop=addDrop, fineRunNum=runNum, deviceId=deviceId, imgntMean=imgntMean) run_experiment(prms, cPrms, True, resumeIter)
def make_window_file_rotOnly(trnSeq=[]): prms = ku.get_prms(poseType='rotOnly', concatLayer='conv5', isNewExpDir=True, maxFrameDiff=7, trnSeq=trnSeq, imSz=None) kn.make_window_file(prms)
def run_sun_scratch(deviceId=1, runNum=1, addDrop=True, addFc=True, fine_base_lr=0.001, imgntMean=False): #I shouldnt be using prms here, but I am. prms = ku.get_prms(poseType='sigMotion', maxFrameDiff=7, imSz=None, isNewExpDir=True) cPrms = get_caffe_prms(concatLayer='fc6', sourceModelIter=None, fineMaxIter=40000, deviceId=deviceId, fineRunNum=runNum, addDrop=addDrop, extraFc=addFc, fine_base_lr=fine_base_lr, imgntMean=imgntMean) run_experiment(prms, cPrms, True)
def save_for_matconvnet(modelIter=60000, isSlowness=False, concatLayer='fc6', trnSeq=[], convConcat=False): modelIter = modelIter outDir = '/data1/pulkitag/others/joao/' if trnSeq != []: trnStr = 'trnSeq' + ''.join(['-%d' % t for t in trnSeq]) else: trnStr = '' print(trnStr) if not isSlowness: prms = ku.get_prms(poseType='sigMotion', maxFrameDiff=7, imSz=None, isNewExpDir=True, trnSeq=trnSeq) cPrms = get_caffe_prms(concatLayer=concatLayer, convConcat=convConcat) outName = 'kitti-' + trnStr + '-iter' + '%d.mat' % modelIter else: prms = ku.get_prms(poseType='slowness', maxFrameDiff=7, imSz=None, lossType='contrastive', nrmlzType='none', trnSeq=trnSeq) cPrms = get_caffe_prms(concatLayer=concatLayer, contrastiveMargin=1, convConcat=convConcat) outName = 'kitti_slowness_concat%s_ctMrgn%d-%d.mat' % (concatLayer, 1, modelIter) exp = setup_experiment(prms, cPrms) snapFile = exp.get_snapshot_name(modelIter) defFile = '/work4/pulkitag-code/pkgs/caffe-v2-2/modelFiles/kitti/base_files/kitti_finetune_fc6_deploy_input.prototxt' print snapFile net = mp.MyNet(defFile, snapFile) outName = os.path.join(outDir, outName) matlabRefFile = '/home/carreira/imagenet-caffe-alex.mat' mpio.save_weights_for_matconvnet(net, outName, matlabRefFile=matlabRefFile)
def run_sun_layerwise(deviceId=1, runNum=2, addFc=True, addDrop=True, fine_base_lr=0.001, imgntMean=False, stepsize=20000, resumeIter=None): #maxLayers = ['fc6', 'pool5', 'relu4', 'relu3', 'pool2', 'pool1'] #lrAbove = ['fc6', 'conv5', 'conv4', 'conv3', 'conv2', 'conv2'] maxLayers = ['fc6'] lrAbove = ['conv1'] prms = ku.get_prms(poseType='sigMotion', maxFrameDiff=7, imSz=None, isNewExpDir=True) for mxl, abv in zip(reversed(maxLayers), reversed(lrAbove)): cPrms = get_caffe_prms(concatLayer='fc6', fineMaxLayer=mxl, lrAbove=abv, fineMaxIter=40000, deviceId=deviceId, fineRunNum=runNum, fine_base_lr = fine_base_lr, extraFc = addFc, addDrop = addDrop, imgntMean = imgntMean) #exp = make_experiment(prms, cPrms, True, resumeIter=resumeIter) run_experiment(prms, cPrms, True, resumeIter=resumeIter)
def finetune_odometry(netType='alex', addFc=False, addDrop=False, imgntMean=True, concatLayer='conv5', convConcat=True, fine_base_lr=0.001, contextPad=16, deviceId=0, kittiTrnSeq=[]): prms = get_prms() cPrms = get_caffe_prms(concatLayer=concatLayer, convConcat=convConcat, contextPad=contextPad, extraFc=addFc, addDrop=addDrop, imgntMean=imgntMean, fine_base_lr=0.001, deviceId=deviceId) if kittiTrnSeq==[]: trnStr = '' else: trnStr = '_trnSeq' + ''.join('-%d' % t for t in kittiTrnSeq) prms['expName'] = prms['expName'] + 'fine_from_' + netType + trnStr if netType=='alex': srcModelFile = '/data1/pulkitag/caffe_models/caffe_imagenet_train_iter_310000' elif netType == 'kitti': srcPrms = ku.get_prms(poseType='sigMotion', maxFrameDiff=7, lossType='classify', imSz=None, trnSeq=kittiTrnSeq) srcCPrms = kn.get_caffe_prms(concatLayer='conv5', convConcat=True) srcExp = kn.setup_experiment(srcPrms, srcCPrms) srcModelFile = srcExp.get_snapshot_name(60000) print (srcModelFile)
def run_sun_layerwise_small(deviceId=0, runNum=1, fineNumData=10, addFc=True, addDrop=True, sourceModelIter=150000, imgntMean=True, concatLayer='fc6', resumeIter=None, fine_base_lr=0.001, runType='run', convConcat=False, prms=None, srcDefFile=None, srcModelFile=None, isMySimple=False, contrastiveMargin=None, maxLayers=None, trnSeq=[]): #Set the prms if prms is None: print('PRMS IS NONE - creating it', trnSeq) prms = ku.get_prms(poseType='sigMotion', maxFrameDiff=7, imSz=None, isNewExpDir=True, trnSeq=trnSeq) print(prms['trnSeq']) imSz = prms['imSz'] if imSz is None: imSz, testImSz, testCrpSz = 227, 256, 227 else: imSz, testImSz, testCrpSz = 128, 128, 112 acc = {} if maxLayers is None: if isMySimple: maxLayers = ['relu1', 'relu2', 'relu3', 'relu4'] else: #maxLayers = ['pool1', 'pool2','relu3','relu4','pool5', 'fc6'] maxLayers = ['pool2', 'relu3', 'relu4', 'pool5'] #maxLayers = ['pool1'] else: assert type(maxLayers) == list if addFc: lrAbove = ['fc-extra'] * len(maxLayers) else: lrAbove = ['class_fc'] * len(maxLayers) for mxl, abv in zip(maxLayers, lrAbove): #Get CaffePrms cPrms = get_caffe_prms(concatLayer=concatLayer, sourceModelIter=sourceModelIter, fineMaxIter=None, stepsize=None, fine_base_lr=fine_base_lr, extraFc=addFc, addDrop=addDrop, fineMaxLayer=mxl, lrAbove=abv, fineRunNum=runNum, fineNumData=fineNumData, deviceId=deviceId, imgntMean=imgntMean, convConcat=convConcat, imSz=imSz, isMySimple=isMySimple, contrastiveMargin=contrastiveMargin) if runType == 'run': isExist = find_experiment(prms, cPrms, srcDefFile=srcDefFile) #pdb.set_trace() if isExist: print 'EXPERIMENT FOUND, SKIPPING' continue else: run_experiment(prms, cPrms, True, resumeIter, srcDefFile=srcDefFile, srcModelFile=srcModelFile) elif runType == 'test': run_test(prms, cPrms, imH=testImSz, imW=testImSz, cropH=testCrpSz, cropW=testCrpSz, srcDefFile=srcDefFile) elif runType == 'accuracy': acc[mxl] = read_accuracy(prms, cPrms) if runType == 'accuracy': return acc, maxLayers
def run_sun_layerwise_small(deviceId=0, runNum=1, fineNumData=10, addFc=True, addDrop=True, sourceModelIter=150000, imgntMean=True, concatLayer='fc6', resumeIter=None, fine_base_lr=0.001, runType='run', convConcat=False, prms=None, srcDefFile=None, srcModelFile=None, isMySimple=False, contrastiveMargin=None, maxLayers=None, trnSeq=[]): #Set the prms if prms is None: print ('PRMS IS NONE - creating it', trnSeq) prms = ku.get_prms(poseType='sigMotion', maxFrameDiff=7, imSz=None, isNewExpDir=True, trnSeq=trnSeq) print (prms['trnSeq']) imSz = prms['imSz'] if imSz is None: imSz, testImSz, testCrpSz = 227, 256, 227 else: imSz, testImSz, testCrpSz = 128, 128, 112 acc = {} if maxLayers is None: if isMySimple: maxLayers = ['relu1', 'relu2','relu3','relu4'] else: #maxLayers = ['pool1', 'pool2','relu3','relu4','pool5', 'fc6'] maxLayers = ['pool2','relu3','relu4', 'pool5'] #maxLayers = ['pool1'] else: assert type(maxLayers) == list if addFc: lrAbove = ['fc-extra'] * len(maxLayers) else: lrAbove = ['class_fc'] * len(maxLayers) for mxl, abv in zip(maxLayers, lrAbove): #Get CaffePrms cPrms = get_caffe_prms(concatLayer=concatLayer, sourceModelIter=sourceModelIter, fineMaxIter=None, stepsize=None, fine_base_lr=fine_base_lr, extraFc=addFc, addDrop=addDrop, fineMaxLayer=mxl, lrAbove=abv, fineRunNum=runNum, fineNumData=fineNumData, deviceId=deviceId, imgntMean=imgntMean, convConcat=convConcat, imSz=imSz, isMySimple=isMySimple, contrastiveMargin=contrastiveMargin) if runType =='run': isExist = find_experiment(prms, cPrms, srcDefFile=srcDefFile) #pdb.set_trace() if isExist: print 'EXPERIMENT FOUND, SKIPPING' continue else: run_experiment(prms, cPrms, True, resumeIter, srcDefFile=srcDefFile, srcModelFile=srcModelFile) elif runType == 'test': run_test(prms, cPrms, imH=testImSz, imW=testImSz, cropH=testCrpSz, cropW=testCrpSz, srcDefFile=srcDefFile) elif runType == 'accuracy': acc[mxl] = read_accuracy(prms,cPrms) if runType=='accuracy': return acc, maxLayers