NFT盲盒數(shù)字藏品系統(tǒng)開發(fā)(詳細規(guī)則)丨NFT數(shù)字藏品盲盒系統(tǒng)開發(fā)(功能源碼)
數(shù)字藏品是指使用是指使用區(qū)域鏈技術(shù),對應(yīng)特定的作品、藝術(shù)品生成的唯一數(shù)字憑證,在保護其數(shù)字版權(quán)的基礎(chǔ)上,實現(xiàn)真實可信的數(shù)字化發(fā)行,購買收藏和使用。
import os
import numpy as np
import torch
import torchvision
import onnx
import onnxruntime as ort
from model import CNN#need model structure
PATH=os.path.dirname(__file__)
NUM_TEST=1000
"""from pt to onnx"""
#get pt model
關(guān)于區(qū)塊鏈項目技術(shù)開發(fā)唯:MrsFu123,代幣發(fā)行、dapp智能合約開發(fā)、鏈游開發(fā)、多鏈錢包開發(fā)
交易所開發(fā)、量化合約開發(fā)、互助游戲開發(fā)、Nft數(shù)字藏品開發(fā)、眾籌互助開發(fā)、元宇宙開發(fā)、swap開發(fā)、
鏈上合約開發(fā)、ido開發(fā)、商城開發(fā)等,開發(fā)過各種各樣的系統(tǒng)模式,更有多種模式、制度、案例、后臺等,成熟技術(shù)團隊,歡迎實體參考。
path_pt=os.path.join(PATH,"cnn.pt")
model_pt=torch.load(f=path_pt)
#dummy input
dummy_input=torch.randn(size=(1,1,28,28))
#save onnx model
path_onnx=os.path.join(PATH,"cnn.onnx")
區(qū)塊鏈數(shù)字藏品的特性
基于區(qū)塊鏈的數(shù)字藏品具備唯一性、不可分割、不可篡改、可驗證、稀缺性等技術(shù)特性:
?。?)唯一性:每個數(shù)字藏品在特定鏈上都具備唯一標識,可以代表數(shù)字或現(xiàn)實世界中的某個資產(chǎn)對象。
?。?)不可分割:每個數(shù)字藏品自身都不可分割,可代表特定的數(shù)字藏品。
(3)不可篡改:基于區(qū)塊鏈不可篡改的特性,使得數(shù)字藏品本身屬性及所有權(quán)信息、歷史交易記錄等信息在抗篡改的鏈式數(shù)據(jù)結(jié)構(gòu)中存儲記錄。
?。?)可驗證:區(qū)塊鏈上信息公開透明,所有用戶均可查詢、驗證數(shù)字藏品的所有權(quán)信息。
?。?)稀缺性:互聯(lián)網(wǎng)時代,信息復制門檻低,價值難受到認可。而區(qū)塊鏈數(shù)字藏品獨一無二、權(quán)屬明確,可永久保存,具備稀缺性,讓基于區(qū)塊鏈的數(shù)字藏品有更強的溢價能力。
input_names=['actual_input']+['learned_%d'%i for i in range(6)]
torch.onnx.export(model=model_pt,args=dummy_input,f=path_onnx,
verbose=True,input_names=input_names)#arg verbose:True to print log
"""load onnx model"""
#load onnx model開發(fā)邏輯I35模式7O98源碼O7I8
model_onnx=onnx.load(path_onnx)
#check if model well formed
onnx.checker.check_model(model_onnx)
#print a human readable representation of the graph
print(onnx.helper.printable_graph(model_onnx.graph))
#data input
test_data=torchvision.datasets.MNIST(root='./data',train=False)
test_data_x=torch.unsqueeze(input=test_data.test_data,dim=1).type(torch.FloatTensor)[:NUM_TEST]/255.
test_data_y=test_data.test_labels[:NUM_TEST]
"""run onnx model"""
#ort session initialize
ort_session=ort.InferenceSession(path_onnx)
#dummy input
outputs=ort_session.run(output_names=None,
input_feed={'actual_input':np.random.randn(1,1,28,28).astype(np.float32)})
print("result of dummy input:{}".format(outputs[0]),'n')
#test data,loop
num_correct=0
for i in range(NUM_TEST):
test_data_x_,test_data_y_=test_data_x[i:i+1],test_data_y<i>
outputs=ort_session.run(output_names=None,input_feed={'actual_input':test_data_x_.numpy()})
predict_y=np.argmax(outputs[0])
if predict_y==test_data_y_:
num_correct+=1
else:
print("predict result{},correct answer{}".format(predict_y,test_data_y_),'n')
accuracy=round(num_correct/NUM_TEST,3)
print("model accuracy:{}".format(accuracy),'n')