欢迎光临散文网 会员登陆 & 注册

DAPP/FDF智能合约众筹循环互助系统开发(详细方案)丨源码部署

2023-03-21 15:58 作者:bili_33032327742  | 我要投稿

  作为一种可能的Web3.0底层技术,区块链以去中心化、不可篡改、可溯源等特点,构建起数字经济时代的全新信任体系。


  从技术角度分析,区块链让数字资产价值流转的每一个节点都公开透明、有迹可循且不可篡改,这将会让Web3.0时代的一切交易变得更加真实可信。


  同时,数据通过区块链技术可以确定权属,实现数据的资产化,这也将使得区块链成为Web3.0时代的基础设施。


  一、pytorch模型保存/加载


  有两种方式可用于保存/加载pytorch模型1)文件中保存模型结构和权重参数2)文件只保留模型权重.


  1、文件中保存模型结构和权重参数


  1)pytorch模型保存


  import torch


  torch.save(selfmodel,"save.pt")


  2)pytorch模型加载


  import torch


  torch.load("save.pt")


  2、文件只保留模型权重


  1)pytorch模型保存


  import torch


  torch.save(selfmodel.state_dict(),"save.pt")


  2)pytorch模型加载


  关于区块链技术项目开发威:yy625019


  selfmodel.load_state_dict(torch.load("save.pt"))


  二、pytorch模型转ONNX模型


  1、文件中保存模型结构和权重参数


  import torch


  torch_model=torch.load("save.pt")#pytorch模型加载


  batch_size=1#批处理大小


  input_shape=(3,244,244)#输入数据


  #set the model to inference mode


  torch_model.eval()


  x=torch.randn(batch_size,*input_shape)#生成张量


  export_onnx_file="test.onnx"#目的ONNX文件名


  torch.onnx.export(torch_model,


  x,


  export_onnx_file,


  opset_version=10,


  do_constant_folding=True,#是否执行常量折叠优化


  input_names=["input"],#输入名


  output_names=["output"],#输出名


  dynamic_axes={"input":{0:"batch_size"},#批处理变量


  "output":{0:"batch_size"}})


  注:dynamic_axes字段用于批处理.若不想支持批处理或固定批处理大小,移除dynamic_axes字段即可.


  2、文件中只保留模型权重


  import torch


  torch_model=selfmodel()#由研究员提供python.py文件


  batch_size=1#批处理大小


  input_shape=(3,244,244)#输入数据


  #set the model to inference mode


  torch_model.eval()


  x=torch.randn(batch_size,*input_shape)#生成张量


  export_onnx_file="test.onnx"#目的ONNX文件名


  torch.onnx.export(torch_model,


  x,


  export_onnx_file,


  opset_version=10,


  do_constant_folding=True,#是否执行常量折叠优化


  input_names=["input"],#输入名


  output_names=["output"],#输出名


  dynamic_axes={"input":{0:"batch_size"},#批处理变量


  "output":{0:"batch_size"}})


DAPP/FDF智能合约众筹循环互助系统开发(详细方案)丨源码部署的评论 (共 条)

分享到微博请遵守国家法律