def saveModel(new_pt, model, WPQ): """ This functions writes to the protobuf to generate the new .caffemodel """ if DEBUG_Mario: print("\n--- saveModel ---") print("in pt (new_pt): ", new_pt) print("in model: ", model) print("in WPQ: ", WPQ.keys()) net = Net(new_pt, model=model) net.WPQ = WPQ net.finalmodel(save=False) # model new_pt, new_model = net.save(prefix='pruned') if DEBUG_Mario: print("\nout pt (new_pt): ", new_pt) print("out model (new_model): ", new_model) print('\nFinal model ready. For testing you can use:') print('\t$CAFFE_ROOT/build/tools/caffe test -model', new_pt, '-weights', new_model) return new_pt, new_model
def stepend(new_pt, model, WPQ): net = Net(new_pt, model=model) net.WPQ = WPQ net.finalmodel(save=False) # load weights into the caffemodel -by Mario net.dis_memory() #final = net.finalmodel(WPQ, prefix='3r') new_pt, new_model = net.save(prefix='3c') print('caffe test -model',new_pt, '-weights',new_model) return {"final": None}
def step1(pt, model, WPQ, check_exist=False): print(pt) net = Net(pt, model, noTF=1) model = net.finalmodel(WPQ) # loads weights into the caffemodel - by Mario if 1:#TODO: Consider adding a configuration paramter to cfgs.py in order to control whether or not to prune the last conv layer -by Mario convs = net.convs redprint("including last conv layer!") else: convs = net.convs[:-1] redprint("ignoring last conv layer!") if dcfgs.dic.option == 1: if DEBUG: redprint("This line executed because dcfgs.dic.option is set to 1 [train.step1()]") sums = net.type2names('Eltwise')[:-1] newsums = [] for i in sums: if not i.endswith('block8_sum'): newsums.append(i) newconvs = [] for i in convs: if i.endswith('_proj'): newconvs.insert(0,i) else: newconvs.append(i) convs = newsums + newconvs else: convs += net.type2names('Eltwise')[:-1] # I guess Element-wise operations are included in ResNet or Xception -by Mario if dcfgs.dic.fitfc: convs += net.type2names('InnerProduct') if dcfgs.model in [cfgs.Models.xception,cfgs.Models.resnet]: for i in net.bns: if 'branch1' in i: convs += [i] net.freeze_images(check_exist=check_exist, convs=convs) return {"model":model}
def step1(pt, model, WPQ, check_exist=False): print(pt) net = Net(pt, model, noTF=1) model = net.finalmodel(WPQ) if 1: convs = net.convs else: convs = net.convs[:-1] redprint("ignoring last conv!") if dcfgs.dic.option == 1: sums = net.type2names('Eltwise')[:-1] newsums = [] for i in sums: if not i.endswith('block8_sum'): newsums.append(i) newconvs = [] for i in convs: if i.endswith('_proj'): newconvs.insert(0,i) else: newconvs.append(i) convs = newsums + newconvs else: convs += net.type2names('Eltwise')[:-1] if dcfgs.dic.fitfc: convs += net.type2names('InnerProduct') if dcfgs.model in [cfgs.Models.xception,cfgs.Models.resnet]: for i in net.bns: if 'branch1' in i: convs += [i] net.freeze_images(check_exist=check_exist, convs=convs) return {"model":model}