【tensorrt】——PluginV2Layer must be V2Ext or V2IOExt or V2DynamicExt when there is no implicit batch d

本文主要是介绍【tensorrt】——PluginV2Layer must be V2Ext or V2IOExt or V2DynamicExt when there is no implicit batch d,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

tensorrt

1. tensorrt插件

  1. 用c++为tensorrt写了插件,继承自IPluginV2
  2. pybind11进行python注册
namespace torch2trt {PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {py::class_<InterpolatePlugin>(m, "InterpolatePlugin")               // 用 pybind11 封装一个 python 能调用的 c++.def(py::init<std::vector<int64_t>, std::string, bool>(), py::arg("size"), py::arg("mode"), py::arg("align_corners")).def(py::init<const std::string &>(), py::arg("data")).def("getSerializationSize", &InterpolatePlugin::getSerializationSize).def("deserializeFromString", &InterpolatePlugin::deserializeFromString).def("serializeToString", [](const InterpolatePlugin& plugin) {std::string data = plugin.serializeToString();return py::bytes(data);});py::class_<GroupNormPlugin>(m, "GroupNormPlugin").def(py::init<int64_t, at::Tensor, at::Tensor, double>(), py::arg("num_groups"), py::arg("weight"), py::arg("bias"), py::arg("eps")).def(py::init<const std::string &>(), py::arg("data")).def("getSerializationSize", &GroupNormPlugin::getSerializationSize).def("deserializeFromString", &GroupNormPlugin::deserializeFromString).def("serializeToString", [](const GroupNormPlugin& plugin) {std::string data = plugin.serializeToString();return py::bytes(data);});}
} // namespace torch2trt
  1. 在python中进行使用
from torch2trt.plugins import InterpolatePlugin
PLUGIN_NAME = 'interpolate'
registry = trt.get_plugin_registry()
for c in registry.plugin_creator_list:print("plugin name:", c.name, "plugin namespace:", c.plugin_namespace)if c.name == PLUGIN_NAME and c.plugin_namespace == 'torch2trt':creator = cbreak
torch2trt_plugin = InterpolatePlugin(size=size, mode=mode, align_corners=align_corners)             # python 封装的 c++ 类
intert = creator.deserialize_plugin(PLUGIN_NAME, torch2trt_plugin.serializeToString())                   # 这两应该是一样的,为啥要用后面的这个。。。

报错:
[TensorRT] ERROR: interprate: PluginV2Layer must be V2Ext or V2IOExt or V2DynamicExt when there is no implicit batch dimension.
[TensorRT] ERROR: interprate: PluginV2Layer must be V2Ext or V2IOExt or V2DynamicExt when there is no implicit batch dimension.
[TensorRT] ERROR: Layer interprate failed validation
[TensorRT] ERROR: Network validation failed.

解决方案
参考:https://forums.developer.nvidia.com/t/add-plugins-to-network-in-c-api-with-explicit-batch-dimension-in-tensorrt-7/110076/3

Hi,You would need to update the plugin.
The plugin that we ship is derived from IPluginV2, however, the OSS plugin is IPluginV2Ext, so you use TRT OSS plugin code instead.Thanks

应该是我的插件类继承自IPluginV2类的问题。后面再看怎么解决。

2. 验证

reference

  1. https://www.fatalerrors.org/a/0dpw0Do.html
  2. https://oldpan.me/archives/tensorrt-plugin-one-post-get-it

这篇关于【tensorrt】——PluginV2Layer must be V2Ext or V2IOExt or V2DynamicExt when there is no implicit batch d的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1056756

相关文章

tensorRT C++使用pt转engine模型进行推理

目录 1. 前言2. 模型转换3. 修改Binding4. 修改后处理 1. 前言 本文不讲tensorRT的推理流程,因为这种文章很多,这里着重讲从标准yolov5的tensort推理代码(模型转pt->wts->engine)改造成TPH-yolov5(pt->onnx->engine)的过程。 2. 模型转换 请查看上一篇文章https://blog.csdn.net/

关于Mybatis的Batch模式性能测试及结论

近日在公司项目中,使用到spring+mybatis的架构,特对mybatis的batch模式做了相关研究,得出以下结论:       1.Mybatis内置的ExecutorType有3种,默认的是simple,该模式下它为每个语句的执行创建一个新的预处理语句,单条提交sql;而batch模式重复使用已经预处理的语句,  并且批量执行所有更新语句,显然batch性能将更优;  2.但batch模

Document root element sqlMap, must match DOCTYPE root sqlMapConfig.

解决两个问题(主要是刚开始学习ibatis的错误) Error parsing XML. org.xml.sax.SAXParseException: Document root element "sqlMap", must match DOCTYPE root "sqlMapConfig".  Error parsing XML. org.xml.sax.SAXParseException

tf.train.batch和tf.train.shuffle_batch的理解

capacity是队列的长度 min_after_dequeue是出队后,队列至少剩下min_after_dequeue个数据 假设现在有个test.tfrecord文件,里面按从小到大顺序存放整数0~100 1. tf.train.batch是按顺序读取数据,队列中的数据始终是一个有序的队列, 比如队列的capacity=20,开始队列内容为0,1,..,19=>读取10条记录后,队列剩下10,

目标跟踪算法(bytetrack)-tensorrt部署教程

一、本机安装python环境 conda create -n bytetrace_env python=3.8activate bytetrace_envconda install pytorch torchvision cudatoolkit=10.1 -c 检测GPU是否可用,不可用不行 import torchprint(torch.cuda.is_available())

如何快速高效的训练ResNet,各种奇技淫巧(二):Mini-batch

点击上方“AI公园”,关注公众号,选择加“星标“或“置顶” 作者:Ayoosh Kathuria 编译:ronghuaiyang 导读 这个系列介绍了如何在CIFAR10上高效的训练ResNet,到第4篇文章为止,我们使用单个V100的GPU,可以在79s内训练得到94%的准确率。里面有各种各样的trick和相关的解释,非常好。 我们研究了mini-batch对训练的影响,并使用更大

Scaling SGD Batch Size to 32K for ImageNet Training

为了充分利用GPU计算,加快训练速度,通常采取的方法是增大batch size.然而增大batch size的同时,又要保证精度不下降,目前的state of the art 方法是等比例与batch size增加学习率,并采Sqrt Scaling Rule,Linear Scaling Rule,Warmup Schem等策略来更新学来率. 在训练过程中,通过控制学习率,便可以在训练的时候采

ValueError: Shape must be rank 0 but is rank 1 for 'train_data/ReadFile' (op: 'ReadFile') with input

使用函数tf.train.slice_input_producer读取文件时, input_queue = tf.train.slice_input_producer([flist], shuffle=self.shuffle,seed=0123, num_epochs=self.num_epochs)input_file = tf.read_file(input_queue) 出现错误:

Laravel 报错: Dotenv values containing spaces must be surrounded by quotes.

报错信息如下: 原因: .env文件配置中包含空格的配置信息,用双引号""引起来即可。 我是在配置项后面添加注释前面有空格,换行后显示正常。

【深度学习】TensorRT模型转换环境

Ubuntu 22.04 LTS、Cuda 12.3、Tensorrt 8.6.1、Python 3.10、A10G GPU 要在 Ubuntu 22.04 LTS 上使用 TensorRT 将模型转换为 TensorRT 格式,您需要安装一些必要的环境和依赖项。以下是详细的步骤: 更新系统: sudo apt updatesudo apt upgrade 安装 CUDA 12.3: