TensorRT上首次运行demo(sampleSSD)笔记

其实官方已经有了非常详细的教程,https://github.com/NVIDIA/TensorRT;https://github.com/NVIDIA/TensorRT/tree/master/samples/opensource/sampleSSD。但是由于我对神经网络很是不熟悉,所以导致理解有误。

  1. 设置CUDA_INSTALL_DIR 和 CUDNN_INSTALL_DIR(我设置的是/usr/lib/aarch64-linux-gnu/,官网提供的镜像里并没有和cuda类似的目录,只有lib,没有头文件,不太清楚)。

  2. 只是想运行一下Demo的话,可以在设置好CUDA_INSTALL_DIR 和CUDNN_INSTALL_DIR之后直接看Prerequisites。

  3. 需要下载的资源 models_VGGNet_VOC0712_SSD_300x300。上述网站上提供的链接国内不能直接下载,我在网上没有找到免费的,于是找别人帮忙下载的。应该也会保留一段时间,有需要的可以私信我。

  4. Edit the deploy.prototxt file and change all the Flatten layers to Reshape operations with the following parameters:
    所有type是Flatten ,修改为Reshape,参数也按如下修改。

layer {
  name: "conv6_2_mbox_conf_flat"
  type: "Reshape"
  bottom: "conv6_2_mbox_conf_perm"
  top: "conv6_2_mbox_conf_flat"
  reshape_param {
    shape {
        dim: 0
        dim: -1
        dim: 1
        dim: 1
    }
}
}
  1. Update the detection_out layer to add the keep_count output as expected by the TensorRT DetectionOutput Plugin. top: “keep_count”
    意思是新增加一句。我开始理解错了。报错:Plugin layer output count is not equal to caffe output count.

  2. Some tactics do not have sufficient workspace memory to run.
    运行出现这一句,不要担心,我也出现了,好像并不影响。等待稍长一会,就会有结果。

  3. 运行成功截图。
    在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的TensorRT C++ demo,该demo使用TensorRT推理引擎对MNIST数字进行分类: ```c++ #include <iostream> #include <cmath> #include <fstream> #include <sstream> #include "NvInfer.h" #include "NvInferPlugin.h" #include "NvOnnxParser.h" using namespace nvinfer1; using namespace plugin; int main(int argc, char** argv) { // Load the ONNX model std::string onnx_model_file = "mnist.onnx"; IBuilder* builder = createInferBuilder(gLogger); INetworkDefinition* network = builder->createNetwork(); auto parser = nvonnxparser::createParser(*network, gLogger); parser->parseFromFile(onnx_model_file.c_str(), -1); builder->setMaxBatchSize(1); builder->setMaxWorkspaceSize(1 << 30); // Set the input and output dimensions Dims input_dims = network->getInput(0)->getDimensions(); input_dims.d[0] = 1; // Set batch size to 1 network->getInput(0)->setDimensions(input_dims); network->getOutput(0)->setDimensions(Dims4(1, 10, 1, 1)); // Build the engine ICudaEngine* engine = builder->buildCudaEngine(*network); // Create execution context IExecutionContext* context = engine->createExecutionContext(); // Create input and output buffers void* input_buffer; void* output_buffer; cudaMalloc(&input_buffer, input_dims.numel() * sizeof(float)); cudaMalloc(&output_buffer, 10 * sizeof(float)); // Load the input data float input_data[28 * 28]; std::ifstream input_file("test_input.txt"); std::string line; int i = 0; while (getline(input_file, line)) { std::stringstream ss(line); ss >> input_data[i++]; } // Copy the input data to GPU cudaMemcpy(input_buffer, input_data, input_dims.numel() * sizeof(float), cudaMemcpyHostToDevice); // Run inference context->execute(1, &input_buffer, &output_buffer); // Copy the output back to CPU float output_data[10]; cudaMemcpy(output_data, output_buffer, 10 * sizeof(float), cudaMemcpyDeviceToHost); // Print the output std::cout << "Output: "; for (int i = 0; i < 10; i++) { std::cout << output_data[i] << " "; } std::cout << std::endl; // Clean up cudaFree(input_buffer); cudaFree(output_buffer); context->destroy(); engine->destroy(); network->destroy(); builder->destroy(); parser->destroy(); return 0; } ``` 这个demo将一个MNIST手写数字的28x28像素图像作为输入,输出一个包含10个元素的向量,其中每个元素代表一个数字的概率。在执行这个demo之前,需要先将ONNX模型转换为TensorRT格式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值