NFT盲盒数字藏品系统开发(详细规则)丨NFT数字藏品盲盒系统开发(功能源码)
数字藏品是指使用是指使用区域链技术,对应特定的作品、艺术品生成的唯一数字凭证,在保护其数字版权的基础上,实现真实可信的数字化发行,购买收藏和使用。
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
关于区块链项目技术开发唯:MrsFu123,代币发行、dapp智能合约开发、链游开发、多链钱包开发
交易所开发、量化合约开发、互助游戏开发、Nft数字藏品开发、众筹互助开发、元宇宙开发、swap开发、
链上合约开发、ido开发、商城开发等,开发过各种各样的系统模式,更有多种模式、制度、案例、后台等,成熟技术团队,欢迎实体参考。
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")
区块链数字藏品的特性
基于区块链的数字藏品具备唯一性、不可分割、不可篡改、可验证、稀缺性等技术特性:
(1)唯一性:每个数字藏品在特定链上都具备唯一标识,可以代表数字或现实世界中的某个资产对象。
(2)不可分割:每个数字藏品自身都不可分割,可代表特定的数字藏品。
(3)不可篡改:基于区块链不可篡改的特性,使得数字藏品本身属性及所有权信息、历史交易记录等信息在抗篡改的链式数据结构中存储记录。
(4)可验证:区块链上信息公开透明,所有用户均可查询、验证数字藏品的所有权信息。
(5)稀缺性:互联网时代,信息复制门槛低,价值难受到认可。而区块链数字藏品独一无二、权属明确,可永久保存,具备稀缺性,让基于区块链的数字藏品有更强的溢价能力。
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开发逻辑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')