parameters: ()
docstring: 组织模型OP结构信息
docstring_summary: 组织模型OP结构信息
docstring_tokens: 组织模型OP结构信息
function: def organizeModelOpInfo():
      """ 组织模型OP结构信息 """
      print("Organizing model operators info...")
      ops = program.current_block().ops
      feedOutputName = None
      index = 0
      for op in ops:
          opInfo = {}
  
          # 获取OP type，需要映射到PaddleJS的名字
          opInfo["type"] = mapToPaddleJSTypeName(op.type)
  
          opInputs = op.input_names
          opOutputs = op.output_names
  
          # 获取OP input
          inputs = {}
          for name in opInputs:
              value = op.input(name)
              if len(value) <= 0:
                  continue
              if value[0] == feedOutputName:
                  # FIXME:workaround,PaddleJSfeed 输入必须是image，且为单输入，这里修改feed后面的OP的input为image，建立前后关联
                  inputs[name] = ["image"]
              else:
                  inputs[name] = value
          opInfo["inputs"] = inputs
  
          # 获取OP output
          outputs = {}
          # 将outputs转换为数组
          if op.type == 'density_prior_box' or op.type == 'prior_box' or op.type == 'box_coder':
              outputs['Out'] = []
              for name in opOutputs:
                  value = op.output(name)
                  if len(value) <= 0:
                      continue
                  outputs['Out'].append(value[0])
          else:
              for name in opOutputs:
                  value = op.output(name)
                  if len(value) <= 0:
                      continue
                  if op.type == "feed":
                      # FIXME:workaround,PaddleJSfeed 输入必须是image，且为单输入，这里保存原始的输出名，以便映射
                      feedOutputName = value[0]
                      outputs[name] = ["image"]
                  else:
                      outputs[name] = value
  
          opInfo["outputs"] = outputs
  
  
          # 有的模型如人脸关键点，会出现两个算子合并的情况，如lmk_demo，elementwise_add后接了relu算子，relu的输入输出相等，兼容一下
          # inputs与outputs只有一个，名称相等，则，输入加后缀，改上一层算子。
          if 'X' in inputs and 'Out' in outputs:
              curInputs = inputs['X']
              curOutputs = outputs['Out']
              if len(curInputs) == 1 and len(curOutputs) == 1 and curInputs[0] == curOutputs[0] and index > 1:
                  originName = curInputs[0]
                  changedName = inputs['X'][0] = curInputs[0] = originName + '_changed'
                  opInfo["inputs"]['X'] = curInputs
                  # 获取上一层算子
                  prevOpOutputs = modelInfo["ops"][index - 1]['outputs']
                  for name in prevOpOutputs:
                      values = prevOpOutputs[name]
                      for i, curName in enumerate(values):
                          if (curName == originName):
                              modelInfo["ops"][index - 1]['outputs'][name][i] = changedName
                  appendedVarList.append({'name': originName, 'new': changedName})
  
          # 获取OP attribute
          attrs = {}
          for name in op.attr_names:
              # 过滤不需要的参数
              if name in needFilterAttributes:
                  continue
              value = op.attr(name)
              attrs[name] = value
          opInfo["attrs"] = attrs
  
          if (op.type == 'rnn'):
              global rnnList
              rnnList.append(index)
  
          # multiclass_nms 单独处理
          if (op.type == 'multiclass_nms'):
              postOps.append(opInfo)
          else:
              # 存入modelInfo
              modelInfo["ops"].append(opInfo)
          logModel("[OP index:" + str(index) + " type:" + op.type + "]")
          jsonDumpsIndentStr = json.dumps(opInfo, indent=2)
          logModel(jsonDumpsIndentStr)
          logModel("")
          index += 1
      print("Organizing model operators info successfully.")
function_tokens: def organizeModelOpInfo ( ) : print ( "Organizing model operators info..." ) ops = program . current_block ( ) . ops feedOutputName = None index = 0 for op in ops : opInfo = { } # 获取OP type，需要映射到PaddleJS的名字 opInfo [ "type" ] = mapToPaddleJSTypeName ( op . type ) opInputs = op . input_names opOutputs = op . output_names # 获取OP input inputs = { } for name in opInputs : value = op . input ( name ) if len ( value ) <= 0 : continue if value [ 0 ] == feedOutputName : # FIXME:workaround,PaddleJSfeed 输入必须是image，且为单输入，这里修改feed后面的OP的input为image，建立前后关联 inputs [ name ] = [ "image" ] else : inputs [ name ] = value opInfo [ "inputs" ] = inputs # 获取OP output outputs = { } # 将outputs转换为数组 if op . type == 'density_prior_box' or op . type == 'prior_box' or op . type == 'box_coder' : outputs [ 'Out' ] = [ ] for name in opOutputs : value = op . output ( name ) if len ( value ) <= 0 : continue outputs [ 'Out' ] . append ( value [ 0 ] ) else : for name in opOutputs : value = op . output ( name ) if len ( value ) <= 0 : continue if op . type == "feed" : # FIXME:workaround,PaddleJSfeed 输入必须是image，且为单输入，这里保存原始的输出名，以便映射 feedOutputName = value [ 0 ] outputs [ name ] = [ "image" ] else : outputs [ name ] = value opInfo [ "outputs" ] = outputs # 有的模型如人脸关键点，会出现两个算子合并的情况，如lmk_demo，elementwise_add后接了relu算子，relu的输入输出相等，兼容一下 # inputs与outputs只有一个，名称相等，则，输入加后缀，改上一层算子。 if 'X' in inputs and 'Out' in outputs : curInputs = inputs [ 'X' ] curOutputs = outputs [ 'Out' ] if len ( curInputs ) == 1 and len ( curOutputs ) == 1 and curInputs [ 0 ] == curOutputs [ 0 ] and index > 1 : originName = curInputs [ 0 ] changedName = inputs [ 'X' ] [ 0 ] = curInputs [ 0 ] = originName + '_changed' opInfo [ "inputs" ] [ 'X' ] = curInputs # 获取上一层算子 prevOpOutputs = modelInfo [ "ops" ] [ index - 1 ] [ 'outputs' ] for name in prevOpOutputs : values = prevOpOutputs [ name ] for i , curName in enumerate ( values ) : if ( curName == originName ) : modelInfo [ "ops" ] [ index - 1 ] [ 'outputs' ] [ name ] [ i ] = changedName appendedVarList . append ( { 'name' : originName , 'new' : changedName } ) # 获取OP attribute attrs = { } for name in op . attr_names : # 过滤不需要的参数 if name in needFilterAttributes : continue value = op . attr ( name ) attrs [ name ] = value opInfo [ "attrs" ] = attrs if ( op . type == 'rnn' ) : global rnnList rnnList . append ( index ) # multiclass_nms 单独处理 if ( op . type == 'multiclass_nms' ) : postOps . append ( opInfo ) else : # 存入modelInfo modelInfo [ "ops" ] . append ( opInfo ) logModel ( "[OP index:" + str ( index ) + " type:" + op . type + "]" ) jsonDumpsIndentStr = json . dumps ( opInfo , indent = 2 ) logModel ( jsonDumpsIndentStr ) logModel ( "" ) index += 1 print ( "Organizing model operators info successfully." )