什么是PIL派链NFT铸造系统开发丨PIL派链NFT铸造系统开发(开发详细)及源码案例

简介:  cv::imread() 默认读取为三通道BGR,需要进行B/R通道交换,这里采用 cv::cvtColor()实现。

  cv::imread() 默认读取为三通道BGR,需要进行B/R通道交换,这里采用 cv::cvtColor()实现。

图像尺寸需要调整到 224 × 224 224\times 224224×224,通过 cv::resize() 实现。

opencv读取的图像矩阵存储形式:H x W x C, 但是pytorch中 Tensor的存储为:N x C x H x W, 因此需要进行变换,就是np.transpose()操作,这里使用tensor.permut()实现,效果是一样的。

数据归一化,采用 tensor.div(255) 实现。
// test_model.cpp

include

include <torch/torch.h>

include <torch/script.h>

include <opencv2/core.hpp>

include <opencv2/imgproc/imgproc.hpp>

include <opencv2/highgui/highgui.hpp>

int main(int argc, char* argv[]) {
// 加载JIT模型
auto module = torch::jit::load(argv[1]);

// 加载图像
auto image = cv::imread(argv[2], cv::ImreadModes::IMREAD_COLOR);
cv::Mat image_transfomed;
cv::resize(image, image_transfomed, cv::Size(224, 224));
cv::cvtColor(image_transfomed, image_transfomed, cv::COLOR_BGR2RGB);

// 图像转换为Tensor
torch::Tensor tensor_image = torch::from_blob(image_transfomed.data, {image_transfomed.rows, image_transfomed.cols, 3},torch::kByte);
tensor_image = tensor_image.permute({2, 0, 1});
// tensor_image = tensor_image.toType(torch::kFloat);
tensor_image = tensor_image.div(255.);
// tensor_image = tensor_image.sub(0.5);
// tensor_image = tensor_image.div(0.5);

tensor_image = tensor_image.unsqueeze(0);

// 运行模型
torch::Tensor output = module.forward({tensor_image}).toTensor();

// 结果处理
int result = output.argmax().item();
std::cout << "The classifiction index is: " << result << std::endl;
return 0;
}

相关文章
|
8月前
|
安全 区块链 数据安全/隐私保护
NFT铸造合成项目系统开发|DAPP开发
智能合约的特点包括可编程性、自治性、不可篡改性和安全性
|
10月前
|
新零售 人工智能 JSON
NFT/DAPP盲盒游戏系统开发(开发方案),DAPP/NFT盲盒游戏系统开发(项目案例)及源码部署
新零售是线上与线下结合,组合的价值主要是线下为线上引流,降低引流投入,线下成为线上的体验店,提高转化和复购,线上和线下双渠道一起提高周转,提高效率,线上和线下虽然各自核算收入和投入,但相互之间能产生互促效应。
|
11月前
|
区块链 开发者
NFT盲盒系统开发实现构建技术分析(源码示例)
NFT盲盒系统的开发需要涉及到区块链技术、数字资产编码技术以及盲盒销售系统等多个方面。开发者需要考虑如何保证数字资产的安全性和惟一 性,同时还需要保证盲盒销售的顺畅和公正。 NFT盲盒系统的开发是一个复杂而创新的过程,需要技术、创意和资金的支持。
|
11月前
|
Web App开发 JavaScript 前端开发
openseaNFT艺术品交易平台开发部署 | openseaNFT艺术品交易平台开发源码示例
OpenSea的主要特点是统一的平台和标准化的流程。用户可以在平台上创建和管理自己的NFT,如艺术品、虚拟房地产、数字收藏品等。同时,OpenSea还提供了一个拍卖市场,让用户可以出售自己的NFT并获得收益。此外,该平台还支持用户在线浏览和购买其他用户铸造的NFT。
|
存储 JSON JavaScript
NFT链游系统开发(详细 及案例)丨NFT链游系统开发(区块链游戏)详情案例
NFT链游系统开发(详细 及案例)丨NFT链游系统开发(区块链游戏)详情案例
|
Python 异构计算 并行计算
PIL派链NFT铸造开发运营版丨PIL派链NFT铸造系统开发(开发案例)及源码
model:网络模型 input_size:网络输入图片的shape,这里不用加batch_size进去 batch_size:batch_size参数,默认是-1 device:在GPU还是CPU上运行,默认是cuda在GPU上运行,如果想在CPU上执行将参数改为CPU即可
PIL派链NFT铸造系统开发详细技术分析丨代码部署
// remove bsv and token from liquidity pool public function removeLiquidity(PubKey sender, int lpAmount, Sig senderSig, int oldTokenBalance, int senderKeyIndex, int senderBalance,
NFT铸造系统开发(成熟及技术)丨功能源码
// add bsv and token to liquidity pool public function addLiquidity(PubKey sender, Sig senderSig, int tokenAmount, int senderBalance, int senderKeyIndex, int oldTokenBalance
|
人工智能 5G vr&ar
DAPP/NFT铸造开发稳定版,DAPP/NFT铸造系统开发技术详细及源码
Web 3.0 has changed the end-user experience by shifting information interaction from the screen to physical space, which is also known as &quot;Spatial Web&quot;. The &quot;spatial network&quot; includes a spatial interaction layer (using intelligent glasses or voice to achieve real-time information interaction), a dig