pytorch导出模型并使用onnxruntime C++部署加载模型推理

2023-05-16

机器学习的框架众多,为了方便复用和统一后端模型部署推理,业界主流都在采用onnx格式的模型,支持pytorch,tensorflow,mxnet多种AI框架。为了提高部署推理的性能,考虑采用onnxruntime机器学习后端推理框架进行部署加速,通过简单的C++ api的调用就可以满足基本使用场景。

下载依赖

参考微软开源项目主页https://github.com/microsoft/onnxruntime

  • onnxruntime python包,通过pip安装
  • onnxruntime C++ sdk,下载源码编译

pytorch训练和导出

这里的例子使用了标准的fashion_mnist数据集,训练了简单的线性模型来进行结果分类,输入服装的图片(1 x 28 x 28)输出所属的类型(1 x 10)。

import numpy as np
import torch
from torch import nn
from torch.utils.data import DataLoader
from torchvision import datasets
from torchvision.transforms import ToTensor
import onnxruntime

# data file
data_dir = "../data"
model_file = "model.pt"
onnx_model_file = "model.onnx"

# download training data from open datasets.
training_data = datasets.FashionMNIST(
    root=data_dir,
    train=True,
    download=True,
    transform=ToTensor(),
)

# data loader
batch_size = 64

train_dataloader = DataLoader(training_data, batch_size=batch_size)
test_dataloader = DataLoader(test_data, batch_size=batch_size)

# peek sample
for X, y in test_dataloader:
    print("Shape of X [N, C, H, W]: ", X.shape)
    print("Shape of y: ", y.shape)
    break

classes = [
    "T-shirt/top",
    "Trouser",
    "Pullover",
    "Dress",
    "Coat",
    "Sandal",
    "Shirt",
    "Sneaker",
    "Bag",
    "Ankle boot",
]

# define model
device = "cpu"
print("Using device: ", device)

class NeuralNetwork(nn.Module):
    def __init__(self):
        super().__init__()
        self.flatten = nn.Flatten()
        self.linear_relu_stack = nn.Sequential(
            nn.Linear(28 * 28, 512),
            nn.ReLU(),
            nn.Linear(512, 512),
            nn.ReLU(),
            nn.Linear(512, 10)
        )

    def forward(self, x):
        x = self.flatten(x)
        logits = self.linear_relu_stack(x)
        return logits
    
model = NeuralNetwork().to(device)
print(model)

# define train
loss_fn = nn.CrossEntropyLoss()
optimizer = torch.optim.SGD(model.parameters(), lr=1e-3)

def train(dataloader, model, loss_fn, optimizer):
    size = len(dataloader.dataset)
    model.train()
    for batch, (X, y) in enumerate(dataloader):
        X, y = X.to(device), y.to(device)

        # Compute prediction error
        pred = model(X)
        loss = loss_fn(pred, y)

        # Backpropagation
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()

        if batch % 100 == 0:
            loss, current = loss.item(), (batch + 1) * len(X)
            print("loss: %7f, current: %5d / size: %5d" % (loss, current, size))

# define test
def test(dataloader, model, loss_fn):
    size = len(dataloader.dataset)
    num_batches = len(dataloader)
    model.eval()
    test_loss, correct = 0, 0
    with torch.no_grad():
        for X, y in dataloader:
            X, y = X.to(device), y.to(device)
            pred = model(X)
            test_loss += loss_fn(pred, y).item()
            correct += (pred.argmax(1) == y).type(torch.float).sum().item()
    test_loss /= num_batches
    correct /= size
    print(f"Test Error: \n Accuracy: %0.1f, Avg loss: %8f \n" % (correct * 100, test_loss))

# training
epochs = 5
for t in range(epochs):
    print("Epoch %d\n-------------------------------" % (t + 1))
    train(train_dataloader, model, loss_fn, optimizer)
    test(test_dataloader, model, loss_fn)
print("Done!")

# pytorch save and load model
torch.save(model, model_file)

# choose sample
x, y = test_data[6][0], test_data[6][1]

# onnx save and load model
torch.onnx.export(
        model,
        x,
        onnx_model_file,
        input_names=['input'],
        output_names=['output'],
        dynamic_axes = {'input':
                            {0: 'batch_size'},
                       'output':
                            {0: 'batch_size'}
                       })

onnxruntime python加载模型推理

onnx_model = onnxruntime.InferenceSession(onnx_model_file, providers=["CPUExecutionProvider"])
print(onnx_model)

# onnx predict
onnx_input_name = onnx_model.get_inputs()[0].name
onnx_output_name = onnx_model.get_outputs()[0].name

onnx_x = x.numpy()
onnx_pred_y = onnx_model.run([onnx_output_name], {onnx_input_name: onnx_x})
print(onnx_pred_y)
print(int(np.argmax(onnx_pred_y)))

推理结果

[array([[ 0.78701156, -0.3907491 ,  0.8121021 ,  0.14819556,  1.0213459 ,
         -0.7819631 ,  0.95659614, -1.4445262 ,  0.06370842, -1.2055752 ]],
       dtype=float32)]
4

onnxruntime C++加载模型推理

需要构建C++工程,引入onnxruntime依赖,支持windows和linux

工程结构

onnxruntime_demo
├── build
│   ├── onnxruntime_demo
│   └── model.onnx
├── CMakeLists.txt
├── onnxruntime
├── README.md
└── src
    └── main.cpp

main.cpp

#include <iostream>
#include <array>
#include <algorithm>
#include "onnxruntime_cxx_api.h"

int main(int argc, char* argv[])
{
    // --- define model path
#if _WIN32
    const wchar_t* model_path = L"./model.onnx"; // you can use string to wchar_t* function to convert
#else
    const char* model_path = "./model.onnx";
#endif

    // --- init onnxruntime env
    Ort::Env env(ORT_LOGGING_LEVEL_WARNING, "Default");

    auto memory_info = Ort::MemoryInfo::CreateCpu(OrtDeviceAllocator, OrtMemTypeCPU);

    // set options
    Ort::SessionOptions session_option;
    session_option.SetIntraOpNumThreads(5); // extend the number to do parallel
    session_option.SetGraphOptimizationLevel(ORT_ENABLE_ALL);

    // --- prepare data
    const char* input_names[] = { "input" }; // must keep the same as model export
    const char* output_names[] = { "output" };

    // use statc array to preallocate data buffer
    std::array<float, 1 * 28 * 28> input_matrix;
    std::array<float, 1 * 10> output_matrix;

    // must use int64_t type to match args
    std::array<int64_t, 3> input_shape{ 1, 28, 28 };
    std::array<int64_t, 2> output_shape{ 1, 10 };

    std::vector<std::vector<std::vector<float>>> sample_x = {
        {
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0039, 0.0000, 0.0000, 0.0667, 0.0000, 0.1373, 0.2157, 0.2039, 0.1765, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0118, 0.0000, 0.0039, 0.9804, 1.0000, 0.9608, 0.9961, 0.9333, 0.9569,0.9373, 0.5412, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.3451, 0.4863, 0.6667, 0.9961, 0.5412, 0.7333, 1.0000, 0.7333, 0.1255, 0.0157, 0.0000, 0.0039, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.3294, 0.3843, 0.0000, 0.7137, 0.8235, 0.9529, 1.0000, 0.1451, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0039, 0.0000, 0.0235, 0.2196, 0.2824, 0.3569, 0.5216, 0.1686, 0.0000, 0.9412, 0.8549, 0.0000, 0.0000, 0.1529, 0.1804, 0.0784, 0.0980, 0.0078, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.1882, 0.4275, 0.2745, 0.2118, 0.1725, 0.2784, 0.2196, 0.2510, 0.0588, 0.0784, 0.1137, 0.1098, 0.2275, 0.2235, 0.2000, 0.0784, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.2549, 0.2863, 0.3216, 0.1922, 0.2275, 0.2039, 0.1255, 0.3294, 0.2706, 0.0980, 0.1961, 0.2471, 0.1804, 0.1059, 0.0980, 0.1137, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0471, 0.3059, 0.2078, 0.5137, 0.1451, 0.2235, 0.2039, 0.0784, 0.3529, 0.3059, 0.0784, 0.2078, 0.2431, 0.1412, 0.0667, 0.1059, 0.1529, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.1098, 0.3333, 0.1137, 0.6039, 0.2275, 0.1843, 0.1686, 0.0471, 0.2980, 0.2784, 0.0824, 0.1333, 0.0745, 0.0824, 0.0745, 0.1294, 0.1686, 0.0275, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.1686, 0.3098, 0.0510, 0.5373, 0.2549, 0.1608, 0.1647, 0.0392, 0.3294, 0.2627, 0.0510, 0.1137, 0.1098, 0.0706, 0.1608, 0.1765, 0.1137, 0.0824, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.2078, 0.2863, 0.0392, 0.5725, 0.3333, 0.1686, 0.1647, 0.0353, 0.3294, 0.2471, 0.0627, 0.1216, 0.0941, 0.0549, 0.1294, 0.1137, 0.1137, 0.0510, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.2392, 0.2745, 0.0078, 0.6627, 0.4000, 0.1098, 0.1843, 0.0588, 0.3137, 0.2353, 0.0392, 0.1137, 0.1020, 0.0000, 0.3020, 0.1098, 0.1059, 0.0549, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.2627, 0.2353, 0.0118, 0.7176, 0.3059, 0.1725, 0.1804, 0.0510, 0.2941, 0.2431, 0.0353, 0.0941, 0.1098, 0.0000, 0.6314, 0.1529, 0.0510, 0.0824, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.2902, 0.1961, 0.0157, 0.8706, 0.2745, 0.1451, 0.1804, 0.0627, 0.2941, 0.2549, 0.0275, 0.1020, 0.0627, 0.0000, 0.9490, 0.1804, 0.0275, 0.0980, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.2863, 0.1412, 0.0431, 1.0000, 0.2235, 0.1725, 0.2118, 0.0431, 0.2902, 0.2471, 0.0157, 0.1020, 0.0235, 0.0039, 0.8549, 0.2863, 0.0000, 0.1059, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0314, 0.2941, 0.1137, 0.0980, 1.0000, 0.2627, 0.1804, 0.1961, 0.0235, 0.3098, 0.2471, 0.0314, 0.0980, 0.0000, 0.1059, 0.9569, 0.3961, 0.0000, 0.1137, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0431, 0.2941, 0.0588, 0.2078, 1.0000, 0.2275, 0.1529, 0.1922, 0.0706, 0.2980, 0.2549, 0.0235, 0.1059, 0.0157, 0.0000, 0.8627, 0.5412, 0.0000, 0.1098, 0.0118, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0431, 0.2902, 0.0196, 0.4039, 0.9961, 0.1922, 0.1882, 0.1804, 0.0510, 0.2863, 0.2549, 0.0078, 0.0980, 0.0196, 0.0000, 0.8196, 0.6941, 0.0000, 0.1176, 0.0275, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0627, 0.2941, 0.0157, 0.4745, 1.0000, 0.1412, 0.1843, 0.2039, 0.0627, 0.2627, 0.2706, 0.0078, 0.0863, 0.0549, 0.0000, 0.7451, 0.7098, 0.0000, 0.1098, 0.0314, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0863, 0.3059, 0.0000, 0.5098, 0.9961, 0.0824, 0.2314, 0.2275, 0.1098, 0.2902, 0.2824, 0.0039, 0.1059, 0.0941, 0.0000, 0.6863, 0.8000, 0.0000, 0.0941, 0.0392, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0902, 0.3020, 0.0000, 0.6078, 0.8549, 0.0784, 0.2235, 0.2078, 0.0941, 0.2745, 0.2863, 0.0078, 0.1059, 0.0863, 0.0000, 0.5255, 0.8392, 0.0000, 0.0784, 0.0471, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0941, 0.2941, 0.0000, 0.7255, 0.7451, 0.0824, 0.2510, 0.2314, 0.1294, 0.2824, 0.2824, 0.0157, 0.1020, 0.1216, 0.0000, 0.4784, 0.8549, 0.0118, 0.0667, 0.0627, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.0941, 0.3176, 0.0000, 0.7608, 0.6157, 0.0706, 0.2235, 0.2196, 0.1176, 0.2784, 0.3020, 0.0157, 0.0902, 0.1020, 0.0000, 0.4353, 0.8902, 0.0510, 0.0510, 0.0745, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.1255, 0.3059, 0.0000, 0.8863, 0.5333, 0.2000, 0.3216, 0.2863, 0.1529, 0.2941, 0.3137, 0.0314, 0.1098, 0.1294, 0.0000, 0.4000, 0.9490, 0.0627, 0.0471, 0.0745, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.1412, 0.2745, 0.0118, 0.9176, 0.3294, 0.2039, 0.2941, 0.2941, 0.2235, 0.2510, 0.2588, 0.0745, 0.1608, 0.1529, 0.0314, 0.2039, 0.8549, 0.1765, 0.0235, 0.0667, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.1373, 0.2706, 0.1137, 0.9412, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.8980, 0.4353, 0.0000, 0.0667, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.2588, 0.3294, 0.1765, 0.4510, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.4667, 0.3059, 0.0941, 0.1020, 0.0000, 0.0000, 0.0000, 0.0000},
        {0.0000, 0.0000, 0.0000, 0.0000, 0.2118, 0.2784, 0.1216, 0.2000, 0.0000, 0.0000, 0.0039, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.1412, 0.1176, 0.1059, 0.1059, 0.0000, 0.0000, 0.0000, 0.0000}
        }
    };
    int sample_y = 4;

    // expand input as one dimention array
    for (int i = 0; i < 1; i++)
        for (int j = 0; j < 28; j++)
            for (int k = 0; k < 28; k++)
                input_matrix[i * 1 * 28 + j * 28 + k] = sample_x[i][j][k];

    Ort::Value input_tensor = Ort::Value::CreateTensor<float>(memory_info, input_matrix.data(), input_matrix.size(), input_shape.data(), input_shape.size());
    Ort::Value output_tensor = Ort::Value::CreateTensor<float>(memory_info, output_matrix.data(), output_matrix.size(), output_shape.data(), output_shape.size());

    // --- predict
    Ort::Session session(env, model_path, session_option); // FIXME: must check if model file exist or valid, otherwise this will cause crash
    session.Run(Ort::RunOptions{ nullptr }, input_names, &input_tensor, 1, output_names, &output_tensor, 1); // here only use one input output channel

    // --- result
    // just use output_matrix as output, all you can use bellow code to get
    //float* output_buffer = output_tensor.GetTensorMutableData<float>();

    std::cout << "--- predict result ---" << std::endl;
    // matrix output
    std::cout << "ouput matrix: ";
    for (int i = 0; i < 10; i++)
        std::cout << output_matrix[i] << " ";
    std::cout << std::endl;
    // argmax value
    int argmax_value = std::distance(output_matrix.begin(), std::max_element(output_matrix.begin(), output_matrix.end()));
    std::cout << "output argmax value: " << argmax_value << std::endl;

    getchar();

    return 0;
}

推理结果

--- predict result ---
ouput matrix: 0.787004 -0.390761 0.8121 0.148179 1.02133 -0.781948 0.956589 -1.44451 0.0637145 -1.20555
output argmax value: 4

可以看到,在同样的输入情况下,C++和python版本可以得到同样的输出
其实还可以支持多通道输入输出

代码

onnxruntime_demo

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

pytorch导出模型并使用onnxruntime C++部署加载模型推理 的相关文章

  • 双目立体视觉 I:标定和校正

    点击上方 AI公园 xff0c 关注公众号 xff0c 选择加 星标 或 置顶 作者 xff1a Ali Yasin Eser 编译 xff1a ronghuaiyang 导读 双目立体校正和标定 大家好 xff01 今天我们将讨论什么是立
  • 4_竞赛无人机基本自动飞行支持函数与导航控制函数解析——零基础学习竞赛无人机搭积木式编程

    竞赛无人机基本自动飞行支持函数与导航控制函数解析 基本自动飞行支持函数 void basic auto flight support void 根据前面几讲的介绍 xff0c 要想实现无人机的自动飞行 xff0c 单依靠姿态自稳 高度控制远
  • Ubuntu20.04/Ubuntu22.04 配置VScode+Opencv+cmake(C++)

    下面介绍Ubuntu20 04下安装opencv xff0c 当然Ubuntu22 04也适用 xff0c 然后将opencv链接到VsCode 先主体按照 gt 点我 xff1a 链接1 lt 的第一点进行安装 xff0c 但是特别注意
  • makefile和cmake

    目录 作用优点cmake 作用 makefile关系到了整个工程的编译规则 一个工程中的源文件不计其数 xff0c 其按类型 功能 模块分别放在若干个目录中 xff0c makefile定义了一系列的规则来指定 xff0c 哪些文件需要先编
  • Linux查看线程的堆栈信息

    1 使用top命令 xff0c 查找pid 2 显示线程 xff0c 查找线程tid ps mp pid o THREAD tid time sort rn 3 将线程id转化为16进制0xtid printf 34 x n 34 tid
  • MPU6050 简介

    目录 关于MPU6050芯片 关于小板 关于厂家和DATASHEET 关于漂移 关于角加速度还是角速度 关于精度和量程 xff08 可调 xff0c 可选 xff09 关于功耗 xff0c 陀螺仪 43 加速器工作电流 xff1a 3 8m
  • 银河麒麟V10操作系统安装putty和cutecom和网络调试助手(mNetAssist)

    银河麒麟V10操作系统安装putty和cutecom和网络调试助手 xff08 mNetAssist xff09 安装Putty 需要连接网络 sudo apt get install putty 安装Cutecom 需要连接网络 sudo
  • STM32串口中断接收和中断发送

    STM32串口USART1中断接收和中断发送 先贴出中断函数 void USART1 IRQHandler void if USART GetITStatus USART1 USART IT RXNE 61 RESET USART Clea
  • ICP(Iterative Closest Point迭代最近点)算法学习笔记

    背景 xff1a 博主从百度百科开始学习icp算法 xff0c 主要是后期加得学习笔记 xff08 红色部分 xff09 ICP算法 xff1a 以点集对点集 xff08 PSTPS xff09 配准方法为基础 xff0c 他们阐述了一种曲
  • linux设备上的Onvif 实现21:解决大华摄像头无法使用问题

    好长时间没有再写该系列文章了 xff0c 最近刚好摸索着解决了大华摄像头无法使用问题 xff0c 记录下来 xff0c 应该对其他博友有所帮助 之前虽然写了一大堆文章说明了如何使用gsoap连接摄像头 xff0c 但这是针对一台海康的摄像头
  • NRF24L01工作原理(发送接收通道地址)解读 图示

    NRF24L01工作原理 xff08 发送接收通道地址 xff09 解读 图示 NRF24l01工作原理 xff08 发送接收通道地址 xff09 网上说明不清晰 xff0c 特制作本说明 xff0c xff08 制作 xff1a 流浪的蛙
  • Realsense D435i 使用

    工作之后才发现问题不是单线程地来找你 xff0c 而是多线程并发地涌向你 D435i是一款良心传感器 xff0c 美中不足的是你拿不到广角图像 虽然现在不负责传感器测试了 xff08 老大布置什么 xff0c 打工的就去做什么就好了 xff
  • Kalibr标定d435i

    figure it out 最近准备使用realsense d435i xff0c 先对其进行标定 整体环境是基于ROS的 xff0c 因为Kalibr是在ROS环境下 大致过程如下 xff1a imu标定 gt 双目标定 gt 双目 43
  • cout函数未定义问题和函数隐形类型转换

    cout函数未定义的一些问题 xff1a 看上面的图片 xff0c 有个朋友说 xff0c 按照上面using和修改了iostream为什么还是显示未定呢 xff1f 到底怎么办呢 xff1f 解决 xff1a include lt ios
  • C++ primer plus

    https github com lilinxiong cppPrimerPlus six https github com lilinxiong cppPrimerPlus six 最近在看C 43 43 primer plus这本书 x
  • ROS编译过程中的错误

    一 catkin make编译错误 xff08 1 xff09 Could not find a package configuration file provided by 34 gazebo ros control 34 with an
  • 算法导论学习笔记-2

    第二章 xff1a 函数的增长 2 1渐近记号 记号 定义 xff1a g n 61 f n 存在正常数c1 c2和n0 xff0c 使对所有n n0 xff0c 有0 c1 g n f n c2 g n xff1b 满足该定义 xff0c
  • C++理论复习之运算符重载

    C 43 43 运算符重载 重载操作符的一般格式 xff1a Type operator 43 Type A Type B 可重载与不可重载的操作符列表 操作符重载的注意事项 重载操作符必须有一个类类型的操作数 xff0c 不能重载内置类型
  • 计算机网络概述

    OSI参考模型 国际标准化组织 I S O 开发了开放式系统互联 O S I 参考模型 xff0c 以促进计算机系统的开放互联 开放式互联就是可在多个厂家的环境中支持互联 很少有产品是完全的O S I 模式 xff1b 相反 xff0c 其
  • PCL:如何自定义一个点云PointT类型

    1 xff0c 使用基础点云类型 include 34 pcl point types h 34 include 34 pcl impl instantiate hpp 34 include 34 foo h 34 include 34 i

随机推荐

  • IP地址

    ip地址的分类 A类地址 设计IPv4 A类地址的目的是支持巨型网络 xff0c 因为对规模巨大网络的需求很小 xff0c 因此开发了这种结构使主机地址数很大 xff0c 而严格限制可被定义为A类网络的数量 一个A类I P地址仅使用第一个8
  • 数据存储大端小端模式的理解

    Big Endian和Little Endian的定义如下 xff1a 1 Little Endian就是低位字节排放在内存的低地址端 xff0c 高位字节排放在内存的高地址端 2 Big Endian 就是高位字节排放在内存的低地址端 x
  • cocos2dx实例开发之经典坦克

    小时候红白机上玩的的经典90坦克 xff0c 看起来简单 xff0c 做起来其实有点复杂 xff0c 这里用原版素材还原了一个简版 预览 工程结构 游戏架构 包括场景 xff1a 欢迎界面 xff0c 主菜单游戏场景 步骤 菜单场景 对于图
  • 数值分析C++:统计(均值/方差/偏度/峰度),积分,微分,蒙特卡罗

    用C 43 43 实现几个简单的数值分析计算 xff0c 以便深入理解计算机在求解代数问题的过程 原理 以下主要针对普通实数 xff0c 以及一元代数 统计 算数平均值 几何平均值 方差 偏度 峰度 积分 求解定积分的一般数学描述式 但是由
  • python脚本编程:监控指定进程的cpu和内存使用率

    为了测试某个服务的稳定性 xff0c 通常需要在服务长时间运行的情况下 xff0c 监控其资源消耗情况 xff0c 比如cpu和内存使用 这里借助python的psutil这个包可以很方便的监控指定进程号 xff08 PID xff09 的
  • python脚本编程:实时监控日志文件

    用python可以很小巧轻便的实时监控日志文件增量刷新 xff0c 根据某些关键字进行匹配 xff0c 方便做运维异常告警 代码 span class token keyword import span time span class to
  • C++获取机器启动至今的时长和机器启动的时间戳

    根据当前时间戳与机器启动至今的时间长度相减 xff0c 可以精确计算出机器启动时刻的时间戳epochtime 代码 span class token macro property span class token directive key
  • pytorch基于RNN实现文本情感分析并用C++加载模型预测

    文本情感分析是机器学习自然语言处理NLP中常见的应用场景 xff0c 给定一段文本 xff0c 识别其中的情绪或态度 xff0c 对其进行分类并标签化 这个手段可以应用于书籍电影评价 用户对产品满意度调查 人机对话感情色彩提取和金融研报分析
  • pytorch使用matplotlib和tensorboard实现模型和训练的可视化

    pytorch构建和训练深度学习模型的过程中 xff0c 往往需要能够直观的观测到可视化的过程 xff0c 比如画出训练曲线等 对于简单的曲线绘制可以使用matplotlib库做出基本的图 xff0c 如果需要更加高级的可视化过程 xff0
  • Eigen库:常见错误(最坑的库,没有之一)

    1 3rdparty eigen eigen3 eigen src core assignevaluator h 833 error C2338 YOU MIXED MATRICES OF DIFFERENT SIZES Eigen Mat
  • win10 资源管理器打开FTP站点跳到IE

    原文链接 xff1a https zhidao baidu com question 549827901 html 我也遇到一样的问题 xff0c 参考很多网页 xff0c 最好终于解决了 xff0c 我不能保证一定解决你的问题 xff0c
  • C++11写的一个简洁的单例类型模版包装器

    单例是经常用到的设计模式实践 xff0c 对于全局使用的唯一资源事例一般都把类型封装成单例 xff0c 但是有时候觉得对于每个class都要改造一遍单例会觉得比较繁琐 xff0c 尤其是在预先不知道哪些类型会使用为单例的时候 为了应对这种情
  • C++获取对应进程的cpu和内存使用情况(支持linux和windows)

    运维监控程序中经常需要根据一个进程号pid去监控实时的cpu和内存占用 xff0c 以下整理了一个C 43 43 实现的简单例子 xff0c 并封装为方便跨平台调用的函数 代码 span class token macro property
  • 基于C++ spdlog日志库的完善封装

    spdlog是一个C 43 43 编写的极速日志打印库 xff0c 支持异步写日志以及多种模式和格式化选项 以下基于spdlog库封装了一个简单易用的功能类 xff0c 采用的是header only方式 xff0c 便于项目集成 代码 p
  • C++11写的线程安全STL库

    用C 43 43 写的程序 xff0c 如果用到了自带的标准模板库STL xff0c 在多线程访问的时候如果不加锁很容易造成segment fault导致程序崩溃coredump xff0c 也就是说C 43 43 标准的STL不是线程安全
  • 使用cmake构建C++ imgui上手项目(支持Windows,Mac,Linux)

    优秀的即时渲染C 43 43 GUI开发框架imgui xff08 https github com ocornut imgui xff09 在很多场合能发挥非常棒的作用 但是由于官方源码仓库一直没有提供基于cmake构建和创建新项目的工具
  • 使用cmake构建C++ workflow上手项目(支持Windows,Linux)

    开源的C 43 43 后端开发框架workflow xff08 https github com sogou workflow xff09 已经在成熟的互联网公司得到非常稳定广泛的应用 xff0c 它结合了网络 异步 计算多个后端常用场景
  • 使用cmake构建C++ live555流媒体服务上手项目(支持Windows,Linux)

    开源的流媒体视频和音频RTSP开发框架live555 xff08 http www live555 com xff09 对于学习和构建音视频流媒体或者直播服务是很方便的 官方的源码包对各平台编译单独列出了对应的makefile xff0c
  • C++20新特性

    目录 新增关键字 keywords conceptrequiresconstinitconstevalco awaitco returnco yieldchar8 t 新增标识符 Identifies importmodule 模块 Mod
  • pytorch导出模型并使用onnxruntime C++部署加载模型推理

    机器学习的框架众多 xff0c 为了方便复用和统一后端模型部署推理 xff0c 业界主流都在采用onnx格式的模型 xff0c 支持pytorch xff0c tensorflow xff0c mxnet多种AI框架 为了提高部署推理的性能