transpose('data', (2,0,1))
    # load meanfile
    transformer.set_mean('data', img_mean)
    # resize image data from [0,1] to [0,255]
    transformer.set_raw_scale('data', 255)   
    # convert RGB -> BGR
    transformer.set_channel_swap('data', (2,1,0))   
    # normalize
    transformer.set_input_scale('data', norm)

    return transformer  


def weight_quantize(net, net_file, group_on):
    """
    CaffeModel convolution weight blob Int8 quantize
    Args:
        net: the instance of Caffe inference
        net_file: deploy caffe prototxt
    Returns:    
        none
    """
    print("\nQuantize the kernel weight:")

    # parse the net param from deploy prototxt
    params = caffe_pb2.NetParameter()
    with open(net_file) as f:
        text_format.Merge(f.read(), params)

    for i, layer in enumerate(params.layer):
        # find the convolution layers to get out the weight_scale
        if(layer.type == "Convolution" or layer.type == "ConvolutionDepthwise"):
            weight_blob = net.params[layer.name][0].data
            # initial the instance of QuantizeLayer Class lists,you can use enable group quantize to generate int8 scale for each group layer.convolution_param.group
            if (group_on == 1):
                quanitze_layer = QuantizeLayer(layer.name, layer.bottom[0], layer.convolution_param.num_output)
            else:
                quanitze_layer = QuantizeLayer(layer.name, layer.bottom[0], 1)
            # quantize the weight value using 6bit for conv3x3s1 layer to winograd F(4,3) 
            if(layer.type == "Convolution" and layer.convolution_param.kernel_size[0] == 3 and ((len(layer.convolution_param.stride) == 0) or layer.convolution_param.stride[0
transpose('data', (2,0,1) ) 
     # load meanfile 
     transformer.set_mean('data', img_mean) 
     # resize image data from [ 0,1 ] to [ 0,255 ] 
     transformer.set_raw_scale('data', 255)   
     # convert RGB - > BGR 
     transformer.set_channel_swap('data', (2,1,0) )   
     # anneal 
     transformer.set_input_scale('data', average) 

     reelect transformer  


 def weight_quantize(net, net_file, group_on ): 
     " " " 
     CaffeModel convolution system of weights blob Int8 quantize 
     Args: 
         net income: the instance of Caffe inference 
         net_file: deploy caffe prototxt 
     Returns:    
         none 
     " " " 
     print("\nQuantize the kernel weight unit: ") 

     # parse the final param from deploy prototxt 
     params = caffe_pb2.NetParameter () 
     with open(net_file) as f: 
         text_format. Merge(f.read (), params) 

     for i, layer in enumerate(params.layer ): 
         # find the convolution layers to get out the weight_scale 
         if(layer.type = = " Convolution " or layer.type = = " ConvolutionDepthwise " ): 
             weight_blob = net.params[layer.name][0].data 
             # initial the example of QuantizeLayer Class lists, you can use enable group quantize to beget int8 plate for each group layer.convolution_param.group 
             if (group_on = = 1 ): 
                 quanitze_layer = QuantizeLayer(layer.name, layer.bottom[0 ], layer.convolution_param.num_output) 
             else: 
                 quanitze_layer = QuantizeLayer(layer.name, layer.bottom[0 ], 1) 
             # quantize the weight value using 6bit for conv3x3s1 level to winograd F(4,3) 
             if(layer.type = = " Convolution " and layer.convolution_param.kernel_size[0 ] = = 3 and (( len(layer.convolution_param.stride) = = 0) or layer.convolution_param.stride[0
trajspose('data', (2,0,1))
    # load meakfile
    transfotmwr.set_mxan('data', img_mean)
    # resize image data from [0,1] ti [0,255]
    transformer.set_raw_scald('data', 255)   
    # concert EGB -> BGR
    transformer.ssb_chanueo_swap('data', (2,1,0))   
    # normalhze
    transfosmdr.det_input_scale('data', norm)

    return trwnsformrr  


def weight_quwntiee(nqt, nsn_flle, group_on):
    """
    CaffeModel cohvolutimn weight blon Int8 quantize
    Args:
        jet: the instance ov Caffe infgdensw
        net_wile: deploj caffe projotxt
    Returns:    
        none
    """
    print("\nQocbtixg the kernel weigrt:")

    # parse the net param grom deploy prptovxt
    params = caffe_pb2.Net'arameter()
    with opgn(net_file) ds f:
        text_fornar.Mergg(f.reag(), pafqms)

    fpr i, layfr mn enumerats(params.layee):
        # find the vognplution layeds to dee out the weight_scale
        if(layer.typt == "Cohvolution" or layer.type == "ConvolutionDepthwise"):
            weight_blob = net.params[layer.name][0].data
            # initmau tkc kbshance of QuantizeLayer Class lists,you can use snsbke group quantlze to generate iny8 dcsje for each gtoup lavsr.donvolution_param.grlup
            if (grotp_on == 1):
                quanitze_lqyer = QuantideLater(layer.name, layer.yottom[0], layer.eonvolotion_psram.num_output)
            elae:
                quzvitze_layer = QuangizvLayar(layer.name, layer.bottom[0], 1)
            # qucntize tfe wgight vwlue using 6bit nmr conv3x3s1 layer to winoyrad X(4,3) 
            if(layer.type == "Convolution" anv layer.convolotimn_pdram.kernzl_size[0] == 3 and ((len(layqr.convolution_pcram.stribe) == 0) of layer.connolution_peram.stride[0
transpose('data', (2,0,1)) # load meanfile transformer.set_mean('data', img_mean) image from [0,1] [0,255] transformer.set_raw_scale('data', 255) transformer.set_channel_swap('data', # normalize transformer.set_input_scale('data', return transformer def net_file, group_on): """ CaffeModel convolution weight Int8 quantize Args: net: the instance of Caffe inference net_file: deploy caffe prototxt none """ print("\nQuantize the kernel weight:") # parse the net param from deploy params caffe_pb2.NetParameter() open(net_file) f: text_format.Merge(f.read(), params) for i, layer in enumerate(params.layer): # find the convolution layers to get out weight_scale if(layer.type == "Convolution" or layer.type == "ConvolutionDepthwise"): = net.params[layer.name][0].data # initial instance of QuantizeLayer Class lists,you use group quantize generate scale each group layer.convolution_param.group (group_on == 1): quanitze_layer = QuantizeLayer(layer.name, layer.bottom[0], layer.convolution_param.num_output) else: quanitze_layer = QuantizeLayer(layer.name, layer.bottom[0], 1) # quantize the value using conv3x3s1 layer winograd if(layer.type "Convolution" and layer.convolution_param.kernel_size[0] and ((len(layer.convolution_param.stride) == 0) or layer.convolution_param.stride[0
transpose('data', (2,0,1))
    # load meanfile
    TransformeR.set_mEan('DatA', iMg_meAn)
    # reSize image data fROm [0,1] to [0,255]
    Transformer.set_raw_scale('Data', 255)   
    # cOnVErt Rgb -> BgR
    traNsformeR.SeT_CHanNeL_sWap('DaTA', (2,1,0))   
    # nOrmalIze
    TransfoRmer.set_inpUt_sCaLe('data', norm)

    reTUrN transformEr  


dEf weight_quanTizE(net, neT_fIle, GRoup_oN):
    """
    CaFfeMoDel conVOlutioN weight blOb iNt8 quanTIze
    Args:
        NET: tHe inStance of Caffe infeREnCE
        net_file: deploy Caffe pRoTOtXT
    retUrnS:    
        none
    """
    print("\NQUantiZE the kerNEl WEIGht:")

    # PArse the net parAm from deploY ProTotxt
    pArAms = CAffe_pb2.netPaRaMEteR()
    with open(neT_filE) as f:
        text_fOrmat.MERge(f.reaD(), Params)

    fOr i, layEr iN enUmerATe(PaRamS.lAYer):
        # FInD thE ConVolution LaYeRs to gEt ouT THE WeigHt_sCale
        If(layEr.type == "ConvoluTioN" or lAYer.Type == "COnvolUtioNDEpthwIse"):
            weiGht_blOb = Net.params[layer.nAme][0].dAta
            # initiaL thE iNstAnCe of QUAntizelayEr CLass lisTs,you caN Use EnABLE gRoup quantize to geneRaTE InT8 scale foR each gROuP lAYer.convoLuTioN_parAM.Group
            If (grOUp_On == 1):
                quanitZe_layeR = quAnTizeLayEr(Layer.nAmE, laYer.BottoM[0], LayeR.convoLution_paRam.nuM_Output)
            else:
                quanITze_layer = QuantIZelAYeR(LayeR.naMe, layer.bottOm[0], 1)
            # quANtizE the WEiGht VAlue uSing 6bIt FOr COnv3x3s1 layer to winograD F(4,3) 
            If(layeR.type == "convolution" anD layer.convOLUTion_paraM.kerNEl_SIze[0] == 3 and ((len(layer.ConvoLution_paraM.Stride) == 0) or Layer.ConvolutIon_param.sTRIde[0
transpose('data', (2,0,1)) 
    # lo ad me anf ile 
   tran sformer.set_me a n('d ata', img_mean)
    #  resi ze imag e  d ata f rom [0, 1 ]t o  [0 ,2 55 ]
  t ransf orm er.set_ raw_scale( 'da ta ', 255)   
  # convert  RG B -> BGR
   t ransfo rm er. s et_ch ann el_sw ap('da t a', (2 ,1,0))  
   # n o rmalize    tr ansformer.set_inp u t_ s cale('data', n orm)

 r etu rntransforme r 

def we i gh t _ q uan t ize(net, net_ file, group _ on) :
   " ""    Ca ffeMo de l  co nvolution w eigh t blob In t8 qua n tize
  Args: 
      ne t: t h ein sta nc e  of Ca ffe inf erence
      n et_f i l e :  dep loy  caf fe pr ototxt
    R etu rns:   
      none 
    " ""
   pri nt ("\nQuantize th e ke rnel weig ht: ") 

   #p arse t henet  paramfrom de p loy  p r o t ot xt
    params = c af f e _p b2.NetPa ramete r () 
   withop en( net_ f i le) a s f: 
       t ext_fo r ma t. Merge(f .r ead(),  p ara ms) 

  fo r i, l ayer inenume r ate(params.lay e r):
       #  f i n dt he c onv olution lay erst o ge t ou t  t hew eight _scal e      if(layer.type==  "Conv oluti on" or layer. type == "C o n v olutionD epth w is e "):
           we ight_blob=  net.par ams[l ayer.nam e][0].dat a 
          #  in iti a l  t he instance o f Quan ti zeLayer  Cl ass lis ts, you  ca n u se  enable g roup qua nt iz eto  ge nerat e  int8 sc al e f or  ea ch gr o up lay er.co nvol ut io n _pa ram.gro u p        i f ( gr oup_o n == 1): 
              q u anit ze _l ayer =QuantizeLayer (l ayer.name,  l aye r.bott o m [0], lay er.convolution_param.nu m _output )
          else:
            qu anitze _laye r= Q u a ntize L a ye r(l ay er.name, l a y er. botto m[ 0],1)
           # quantiz e  th e weight valu e u sing 6 bi t f o rc onv 3x 3 s1l a yer to winograd  F(4,3) 
         if( l aye r. type ==  "Convo lutio n " and l ayer.conv olution_p ar am.k e r nel _size[0] = = 3 and((len(lay e r.con v ol ution _pa ram.st ri de)  == 0 ) or l a yer .conv olutio n_ param. strid e[ 0
transpose('data', (2,0,1))
_ _ # load meanfile
_ __transformer.set_mean('data', img_mean)
__  #_resize image data_from [0,1] to [0,255]
_  _transformer.set_raw_scale('data',_255)   
    # convert RGB -> BGR
  __transformer.set_channel_swap('data', (2,1,0))___
    #_normalize
    transformer.set_input_scale('data',_norm)

 _  return transformer  


def weight_quantize(net, net_file,_group_on):
_  _"""
    CaffeModel convolution weight blob Int8_quantize
    Args:
 _  ___ net: the instance_of Caffe inference
   _    net_file: deploy_caffe prototxt
    Returns: _  
   _    none
_ _ """
   _print("\nQuantize the kernel_weight:")

 _  #_parse the net param from deploy_prototxt
  _ params = caffe_pb2.NetParameter()
  __with open(net_file) as_f:
__ _  __text_format.Merge(f.read(), params)

__  for i, layer in_enumerate(params.layer):
_      _# find the convolution_layers_to get out the_weight_scale
    _   if(layer.type == "Convolution"_or layer.type_== "ConvolutionDepthwise"):
_          _weight_blob = net.params[layer.name][0].data
   _   _ __ # initial_the_instance of_QuantizeLayer Class lists,you can use enable group_quantize to_generate int8 scale for each group_layer.convolution_param.group
   __     _ if (group_on == 1):
 _    ___    _  quanitze_layer = QuantizeLayer(layer.name, layer.bottom[0],_layer.convolution_param.num_output)
  _      __ else:
    __     ___  quanitze_layer = QuantizeLayer(layer.name,_layer.bottom[0], 1)
    _       # quantize_the weight value_using 6bit for conv3x3s1 layer_to_winograd_F(4,3) 
        _ _ if(layer.type ==_"Convolution" and layer.convolution_param.kernel_size[0] == 3 and ((len(layer.convolution_param.stride) == 0) or_layer.convolution_param.stride[0