什么是DAPP(分布式应用)?
DAPP是DecentralizeDAPPlication的缩写,中文叫分布式应用/去中心化应用)。通常来说,不同的DAPP会采用不同的底层区快开发平台和共识机制,或者自行发布代币(也可以使用基于相同区快平台的通用代币)。
removing_ops=[]
for op in self.graph.operations.values():
if op.type=='Constant':
assert len(op.outputs)==1,(
f'Constant Operation{op.name}has more than 1 output,is there a network parsing error?')
removing_ops.append(op)
然后遍历removing_ops列表。之前说初始化参数的时候说过,通过设置每一个Operation的_is_parameter=Ture可以实现参数化。然后设置value,最后才做真正的移除算子。设置value后记得把value转换成tensor,调用convert_to_tensor()方法即可。
for const_op in removing_ops:
assert isinstance(const_op,Operation)
constant_value=const_op.attributes['value']
output_var=const_op.outputs[0]
output_var._is_parameter=True
output_var.value=constant_value
self.graph.remove_operation(removing_op=const_op)
def remove_constant_input(self)->None:
"""部分部署平台不支持Constant Op作为算子的输入
在这种情况下我们使用这个pass把它们切换成Parameter Variable
Some backend platform doesn't support Constant
Op,we use this pass to replace it by forcing its value to be a
parameter variable."""
removing_ops=[]
for op in self.graph.operations.values():
if op.type=='Constant':
assert len(op.outputs)==1,(
f'Constant Operation{op.name}has more than 1 output,is there a network parsing error?')
removing_ops.append(op)
for const_op in removing_ops:
assert isinstance(const_op,Operation)
constant_value=const_op.attributes['value']
output_var=const_op.outputs[0]
output_var._is_parameter=True
output_var.value=constant_value
self.graph.remove_operation(removing_op=const_op)