Exemple #1
0
def initializePruning():
    global blockList  #ip.getBlockList('vgg16')
    global featureList
    global convIdx
    global module
    global prune_count

    blockList = ip.createBlockList(newModel)  #ip.getBlockList('vgg16')
    featureList = ip.createFeatureList(newModel)
    convIdx = ip.findConvIndex(newModel)
    module = ip.getPruneModule(newModel)
    prune_count = ip.getPruneCount(module=module, blocks=blockList, maxpr=.1)

    global newList
    global layer_number
    global st
    global en
    global candidateConvLayer

    newList = []
    layer_number = 0
    st = 0
    en = 0
    candidateConvLayer = []

    print(f"Block List   = {blockList}\n"
          f"Feature List = {featureList}\n"
          f"Conv Index   = {convIdx}\n"
          f"Prune Count  = {prune_count}\n"
          f"Start Index  = {st}\n"
          f"End Index    = {en}\n"
          f"Initial Layer Number = {layer_number}\n"
          f"Empy candidate layer list = {candidateConvLayer}")
Exemple #2
0
def initializePruning():
    global blockList  #ip.getBlockList('vgg16')
    global featureList
    global convIdx
    global module
    global prune_count
    with open(outLogFile, "a") as f:

        blockList = ip.createBlockList(newModel)  #ip.getBlockList('vgg16')
        featureList = ip.createFeatureList(newModel)
        convIdx = ip.findConvIndex(newModel)
        module = ip.getPruneModule(newModel)
        prune_count = ip.getPruneCount(module=module,
                                       blocks=blockList,
                                       maxpr=.1)

        global newList
        global layer_number
        global st
        global en
        global candidateConvLayer

        newList = []
        layer_number = 0
        st = 0
        en = 0
        candidateConvLayer = []

        f.write(f"\nBlock List   = {blockList}"
                f"\nFeature List = {featureList}"
                f"\nConv Index   = {convIdx}"
                f"\nPrune Count  = {prune_count}"
                f"\nStart Index  = {st}"
                f"\nEnd Index    = {en}"
                f"\nInitial Layer Number = {layer_number}"
                f"\nEmpy candidate layer list = {candidateConvLayer}")
        f.close()
#Save the  trained model 
SavePath = '/home/pragnesh/Model/vgg16-v2'
torch.save(newModel, SavePath)


# ## Pruning

# #### Pruning Initialization

# In[4]:


blockList   = ip.createBlockList(newModel)              #ip.getBlockList('vgg16')
featureList = ip.createFeatureList(newModel)
convIdx     = ip.findConvIndex(newModel)
module      = ip.getPruneModule(newModel)
prune_count = ip.getPruneCount(module=module,blocks=blockList,maxpr=.1)
print(f"Block List   = {blockList}\n"
      f"Feature List = {featureList}\n" 
      f"Conv Index   = {convIdx}\n"
      f"Prune Count  = {prune_count}"
      
     )
# for i in range(len(module)):
#     print(f"{i+1} :{module[i]}")


# #### Implementing custom pruning process

# In[5]:
#         5.  Commit Pruning
#         6.  Update feature list
#         7.  Create new temp model with updated feature list
#         8.  Perform deep copy
#         9.  Train pruned model
#         10. Evalute the pruned model
#         11. Continue another iteration if required and accepted

# In[4]: Pruning Initialization
blockList = ip.createBlockList(newModel)  # ip.getBlockList('vgg16')
featureList = ip.createFeatureList(
    newModel)  # Number of feature map in each convolution layer
convIdx = ip.findConvIndex(
    newModel
)  # get the index of convolution parameter in newModel.features list
module = ip.getPruneModule(
    newModel)  # extract all the conv layer and store them in the module list
prune_count = ip.getPruneCount(
    module=module, blocks=blockList,
    maxpr=.1)  # set amount to be pruned from each layer
print(f"Block List   = {blockList}\n"
      f"Feature List = {featureList}\n"
      f"Conv Index   = {convIdx}\n"
      f"Prune Count  = {prune_count}")

# In[11]:Implementing custom pruning process
newList = []
layer_number = 0
st = 0
en = 0
candidateConvLayer = []