Web3.0通过将信息交互从屏幕转移到物理空间,改变了终端用户体验,因而也有称Web3.0为“空间网络(Spatial Web)”。该“空间网络”包括空间交互层(利用智能眼镜或语音等实现实时信息交互)、数字信息层(借助传感和数字映射为每一个对象创建数字孪生)和物理层(通过感观了解和体验的世界)。
DAPP是去中心化应用程序/分布式的应用程序,是底层区块链平台生态上衍生的各种分布式应用,也是区块链世界中的基础服务提供方。将应用程序分布在不同节点上,通过共识机制和区块链平台来完成任务的应用程序,它本身就是去中心化,不依赖于任何中心化服务器,促使用户交易更加安全。
数据作为新型生产要素,能为实体经济带来放大、叠加和倍增作用,是做强做优做大数字经济的关键。建立数据可信流通体系,增强数据的可用、可信、可流通、可追溯水平,是激活数据要素潜能、赋能实体经济的重要途径。区块链技术具有去中心化、共识机制、不可篡改、可以追溯、规则透明等特点。
int backendType[2];
net->getSessionInfo(session,MNN::Interpreter::BACKENDS,backendType);
MNN_PRINT("Session Info:memory use%f MB,flops is%f M,backendType is%d,batch size=%dn",memoryUsage,flops,backendType[0],argc-2);
//获取输出tensor的信息
auto output=net->getSessionOutput(session,NULL);
if(nullptr==output||output->elementSize()==0){
MNN_ERROR("Resize error,the model can't run batch:%dn",shape[0]);
return 0;
}
//定义真正输入数据inputUser
std::shared_ptr<Tensor>inputUser(new Tensor(input,Tensor::TENSORFLOW));
auto bpp=inputUser->channel();
auto size_h=inputUser->height();
auto size_w=inputUser->width();
MNN_PRINT("input:w:%d,h:%d,bpp:%dn",size_w,size_h,bpp);
//依次填充batch张图片数据到inputUser
for(int batch=0;batch<shape[0];++batch){
auto inputPatch=argv[batch+2];
int width,height,channel;
auto inputImage=stbi_load(inputPatch,&width,&height,&channel,4);
if(nullptr==inputImage){
MNN_ERROR("Can't open%sn",inputPatch);
return 0;
}
MNN_PRINT("origin size:%d,%dn",width,height);
//trans是图像变换矩阵,可以用来做缩放、旋转等图像变换,避免引入opencv
Matrix trans;
//Set transform,from dst scale to src,the ways below are both ok
#ifdef USE_MAP_POINT
float srcPoints[]={
0.0f,0.0f,
0.0f,(float)(height-1),
(float)(width-1),0.0f,
(float)(width-1),(float)(height-1),
};
float dstPoints[]={
0.0f,0.0f,
0.0f,(float)(size_h-1),
(float)(size_w-1),0.0f,
(float)(size_w-1),(float)(size_h-1),
};
trans.setPolyToPoly((Point)dstPoints,(Point)srcPoints,4);
#else
trans.setScale((float)(width-1)/(size_w-1),(float)(height-1)/(size_h-1));
#endif
//MNN中使用CV::ImageProcess进行图像处理
ImageProcess::Config config;
config.filterType=BILINEAR;
float mean[3]={103.94f,116.78f,123.68f};
float normals[3]={0.017f,0.017f,0.017f};
//float mean[3]={127.5f,127.5f,127.5f};
//float normals[3]={0.00785f,0.00785f,0.00785f};
::memcpy(config.mean,mean,sizeof(mean));
::memcpy(config.normal,normals,sizeof(normals));
//图像格式转换:RGBA(.png)->BGR(模型输入要求)
config.sourceFormat=RGBA;
config.destFormat=BGR;
std::shared_ptr<ImageProcess>pretreat(ImageProcess::create(config));
pretreat->setMatrix(trans);
//执行图像处理
pretreat->convert((uint8_t)inputImage,width,height,0,inputUser->host<uint8_t>()+inputUser->stride(0)batch*inputUser->getType().bytes(),size_w,size_h,bpp,0,inputUser->getType());
stbi_image_free(inputImage);
}
//拷贝真实输入数据到会话中
input->copyFromHostTensor(inputUser.get());
//执行会话
net->runSession(session);
auto dimType=output->getDimensionType();
if(output->getType().code!=halide_type_float){
dimType=Tensor::TENSORFLOW;
}
//定义输出数据承接outputUser
std::shared_ptr<Tensor>outputUser(new Tensor(output,dimType));
//拷贝到outputUser
output->copyToHostTensor(outputUser.get());
//获取输出类型:可能是数据类型?
auto type=outputUser->getType();
//对每一张图
for(int batch=0;batch<shape[0];++batch){
MNN_PRINT("For Image:%sn",argv[batch+2]);
auto size=outputUser->stride(0);
//用std::pair承接序号,置信度
std::vector<std::pair<int,float>>tempValues(size);
//对每种输出类型,分别解析
if(type.code==halide_type_float){
auto values=outputUser->host<float>()+batch*outputUser->stride(0);
for(int i=0;i<size;++i){
tempValues<i>=std::make_pair(i,values<i>);
}
}
if(type.code==halide_type_uint&&type.bytes()==1){
auto values=outputUser->host<uint8_t>()+batch*outputUser->stride(0);
for(int i=0;i<size;++i){
tempValues<i>=std::make_pair(i,values<i>);
}
}
if(type.code==halide_type_int&&type.bytes()==1){
auto values=outputUser->host<int8_t>()+batch*outputUser->stride(0);
for(int i=0;i<size;++i){
tempValues<i>=std::make_pair(i,values<i>);
}
}
//Find Max按置信度排序
std::sort(tempValues.begin(),tempValues.end(),
{return a.second>b.second;});
//打印top10信息
int length=size>10?10:size;
for(int i=0;i<length;++i){
MNN_PRINT("%d,%fn",tempValues<i>.first,tempValues<i>.second);
}
}
return 0;
}