DAPP/FDF智能合約眾籌循環(huán)互助系統(tǒng)開發(fā)(詳細(xì)方案)丨源碼部署
作為一種可能的Web3.0底層技術(shù),區(qū)塊鏈以去中心化、不可篡改、可溯源等特點,構(gòu)建起數(shù)字經(jīng)濟時代的全新信任體系。
從技術(shù)角度分析,區(qū)塊鏈讓數(shù)字資產(chǎn)價值流轉(zhuǎn)的每一個節(jié)點都公開透明、有跡可循且不可篡改,這將會讓W(xué)eb3.0時代的一切交易變得更加真實可信。
同時,數(shù)據(jù)通過區(qū)塊鏈技術(shù)可以確定權(quán)屬,實現(xiàn)數(shù)據(jù)的資產(chǎn)化,這也將使得區(qū)塊鏈成為Web3.0時代的基礎(chǔ)設(shè)施。
一、pytorch模型保存/加載
有兩種方式可用于保存/加載pytorch模型1)文件中保存模型結(jié)構(gòu)和權(quán)重參數(shù)2)文件只保留模型權(quán)重.
1、文件中保存模型結(jié)構(gòu)和權(quán)重參數(shù)
1)pytorch模型保存
import torch
torch.save(selfmodel,"save.pt")
2)pytorch模型加載
import torch
torch.load("save.pt")
2、文件只保留模型權(quán)重
1)pytorch模型保存
import torch
torch.save(selfmodel.state_dict(),"save.pt")
2)pytorch模型加載
關(guān)于區(qū)塊鏈技術(shù)項目開發(fā)威:yy625019
selfmodel.load_state_dict(torch.load("save.pt"))
二、pytorch模型轉(zhuǎn)ONNX模型
1、文件中保存模型結(jié)構(gòu)和權(quán)重參數(shù)
import torch
torch_model=torch.load("save.pt")#pytorch模型加載
batch_size=1#批處理大小
input_shape=(3,244,244)#輸入數(shù)據(jù)
#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,#是否執(zhí)行常量折疊優(yōu)化
input_names=["input"],#輸入名
output_names=["output"],#輸出名
dynamic_axes={"input":{0:"batch_size"},#批處理變量
"output":{0:"batch_size"}})
注:dynamic_axes字段用于批處理.若不想支持批處理或固定批處理大小,移除dynamic_axes字段即可.
2、文件中只保留模型權(quán)重
import torch
torch_model=selfmodel()#由研究員提供python.py文件
batch_size=1#批處理大小
input_shape=(3,244,244)#輸入數(shù)據(jù)
#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,#是否執(zhí)行常量折疊優(yōu)化
input_names=["input"],#輸入名
output_names=["output"],#輸出名
dynamic_axes={"input":{0:"batch_size"},#批處理變量
"output":{0:"batch_size"}})