我知道这个问题已经被问了很多次,但这些建议似乎都不起作用,可能是因为我的设置有些不同:
Ubuntu 22.04
python 3.10.8
tensorflow 2.11.0
cudatoolkit 11.2.2
cudnn 8.1.0.77
nvidia-tensorrt 8.4.3.1
nvidia-pyindex 1.0.9
Run Code Online (Sandbox Code Playgroud)
home/dan/anaconda3/envs/tf/lib/python3.10/site-packages/tensorrt在我的目录中创建了一个 conda 环境“tf”
libnvinfer_builder_resource.so.8.4.3
libnvinfer_plugin.so.8
libnvinfer.so.8
libnvonnxparser.so.8
libnvparsers.so.8
tensorrt.so
Run Code Online (Sandbox Code Playgroud)
跑步时python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"我得到
tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7';
dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory;
LD_LIBRARY_PATH: :/home/dan/anaconda3/envs/tf/lib
tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7';
dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory;
LD_LIBRARY_PATH: :/home/dan/anaconda3/envs/tf/lib
tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用TensorRT部署经过培训的U-Net。使用Keras(以Tensorflow作为后端)对模型进行了训练。代码与这一代码非常相似:https : //github.com/zhixuhao/unet/blob/master/model.py
当我将模型转换为UFF格式时,使用如下代码:
import uff
import os
uff_fname = os.path.join("./models/", "model_" + idx + ".uff")
uff_model = uff.from_tensorflow_frozen_model(
frozen_file = os.path.join('./models', trt_fname), output_nodes = output_names,
output_filename = uff_fname
)
Run Code Online (Sandbox Code Playgroud)
我将收到以下警告:
Warning: No conversion function registered for layer: ResizeNearestNeighbor yet.
Converting up_sampling2d_32_12/ResizeNearestNeighbor as custom op: ResizeNearestNeighbor
Warning: No conversion function registered for layer: DataFormatVecPermute yet.
Converting up_sampling2d_32_12/Shape-0-0-VecPermuteNCHWToNHWC-LayoutOptimizer as custom op: DataFormatVecPermute
Run Code Online (Sandbox Code Playgroud)
我试图通过用upsampling(双线性插值)替换upsampling层并转置卷积来避免这种情况。但是转换器会抛出类似的错误。我检查了https://docs.nvidia.com/deeplearning/sdk/tensorrt-support-matrix/index.html,似乎还不支持所有这些操作。
我想知道是否有解决此问题的方法?TensorRT还喜欢其他格式并支持上采样吗?还是可以用其他受支持的操作替换它?
我还看到某处可以添加自定义操作来替换那些不支持TensorRT的操作。虽然我不太确定工作流程如何。如果有人可以指出自定义图层的示例,那也将非常有帮助。
先感谢您!
我想使用NVIDIA TensorRT来运行我的Tensorflow模型.Currenly,TensorRT支持Caffe原型文本网络描述符文件.
我无法找到将Tensorflow模型转换为Caffe模型的源代码.有没有解决方法?
我正在尝试在 conda env 中安装tensorrt,并且通过 conda navigator 在我的环境中安装了 cudatoolkit 和 cudnn。\n我还更新了我的 pip 和 setuptool\n但是出现以下错误\n我应该做什么?
\n错误:
\nLooking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com\nCollecting nvidia-tensorrt\n Downloading nvidia-tensorrt-0.0.1.dev5.tar.gz (7.9 kB)\n Preparing metadata (setup.py) ... error\n error: subprocess-exited-with-error\n\n \xc3\x97 python setup.py egg_info did not run successfully.\n \xe2\x94\x82 exit code: 1\n \xe2\x95\xb0\xe2\x94\x80> [17 lines of output]\n Traceback (most recent call last):\n File "<string>", line 2, in <module>\n File "<pip-setuptools-caller>", line 34, in <module>\n File "C:\\Users\\Zaniar.J\\AppData\\Local\\Temp\\pip-install-j1d5secx\\nvidia-tensorrt_4052b513fcf14f1c9e44ac829f00ae55\\setup.py", line 150, in <module>\n raise RuntimeError(open("ERROR.txt", "r").read())\n RuntimeError:\n ###########################################################################################\n The package …Run Code Online (Sandbox Code Playgroud) 我在 TensorRT(使用 python)中有一个推理代码。我想在 ROS 中运行此代码,但在尝试分配缓冲区时出现以下错误:
LogicError: explicit_context_dependent failed: invalid device context - no currently active context?
该代码在 ROS 包之外运行良好。ROS 节点发布图像,给定的代码获取图像进行推理。推理代码如下所示:
#!/usr/bin/env python
# Revision $Id$
import rospy
from std_msgs.msg import String
from cv_bridge import CvBridge
import cv2
import os
import numpy as np
import argparse
import torch
from torch.autograd import Variable
from torchvision import transforms
import torch.nn.functional as F
import torch._utils
from PIL import Image
from sensor_msgs.msg import Image as ImageMsg
import tensorrt as trt
import pycuda.driver as cuda
import …Run Code Online (Sandbox Code Playgroud) 我试图在 ubuntu 18.4 (nv-tensorrt-repo-ubuntu1804-cuda10.2-trt7.0.0.11-ga-20191216_1-1_amd64.deb) debian 中安装 tensorRT 7.0。
遵循文档https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html#installing-debian。
我在使用 libnvinfer7 时遇到以下错误。在这个星球上寻找这个,无法找到,浪费了我的时间和睡眠。请帮我解决这个问题:
amarnath@amarnath-Precision-T3610:/opt/pixuate$ sudo apt install tensorrt
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following …Run Code Online (Sandbox Code Playgroud) 我们有一个Caffe模型,其中包含:
layer {
name: "foo"
type: "PriorBox"
prior_box_param { # ERROR HERE
# whatever
}
# etc
}
Run Code Online (Sandbox Code Playgroud)
现在,按照sampleMNIST我的代码尝试将我的模型导入TensorRT但得到一个错误:
Error parsing text-format ditcaffe.NetParameter: 1000:19 ("ERROR HERE" location):
Message type "ditcaffe.LayerParameter" has no field named "prior_box_param".
Run Code Online (Sandbox Code Playgroud)
搜索周围,这是一个已知问题,甚至有一个TensorRT类nvinfer1::plugin::PriorBoxParameters表明它应该能够处理这一层,但很少或有关于如何继续的文档.我读了一个关于拆分模型的建议,但是我的模型中有四个这个节点的实例,更重要的是,没有关于自定义节点中应该有什么代码的信息.
我应该如何处理这个问题,而对第三方设计和培训的现有模型的影响最小,因此我无法彻底改变模型或权重.
我发现我们可以通过多种方式优化 Tensorflow 模型。如果我弄错了,请告诉我。
1- 使用TF-TRT,这个 API 开发者由 tensorflow 和 integreted TensoRT 到 Tensorflow,这个 API 被称为:
从 tensorflow.python.compiler.tensorrt 导入 trt_convert 作为 trt
这个 API 可以应用于任何 tensorflow 模型(新旧版本模型),没有任何转换错误,因为如果这个 API 不支持任何新层,那么 TensorRT 引擎不要考虑这些层,而这些层保留给 Tensorflow 引擎和在 Tensorflow 上运行。对?
2- 使用TensorRT,此 API 由 NVIDA 开发,独立于 Tenorflow 库(未集成到 Tensorflow),此 API 称为:
将张量导入为 trt
如果我们要使用这个api,首先我们必须使用uff-convertor将tensorflow graph转换为UFF,然后将UFF graph解析为这个API。在这种情况下,如果 Tensorflow 图有不受支持的层,我们必须为这些层使用插件或自定义代码,对吗?
3- 我不知道,当我们使用 Tensorflow 模型时,为什么我们使用 UFF 转换器然后使用 TensorRT,我们可以直接使用 TF-TRT API,对吗?如果是这样,您是否通过这两种方法测试了 Tensorflow 优化模型以获得相同的性能?这种 UFF 转换器方法的优点是什么?
我对上述两种情况有一些疑问:
4- 我使用两种情况转换 ssd_mobilenet_v2,在情况 1 中,我的速度略有提高,但在情况 2 中,我取得了更大的进步,为什么?我的观点是,在情况 1 中,API 只考虑转换精度(FP32 …
我目前正在 Yolov4 上使用 Darknet,有 1 个班级。
我需要将这些权重导出为 onnx 格式,以进行 tensorRT 推理。我尝试了多种技术,使用ultralytics来转换或从 tensorflow 转换为 onnx。但似乎都不起作用。有直接的方法吗?
我正在尝试加速分段模型(unet-mobilenet-512x512)。我将我的tensorflow模型转换为具有FP16精度模式的tensorRT。而且速度比我预想的要低。在优化之前,我使用 .pb 冻结图进行推理时的速度为 7FPS。在tensorRT oprimization之后我有14FPS。
这是 Jetson NX 网站上的基准测试结果,
您可以看到,unet 256x256 分割速度为 146 FPS。我想,在最坏的情况下,我的unet512x512的速度应该慢4倍。
这是我使用 TensorRt 优化张量流保存模型的代码:
import numpy as np
from tensorflow.python.compiler.tensorrt import trt_convert as trt
import tensorflow as tf
params = trt.DEFAULT_TRT_CONVERSION_PARAMS
params = params._replace(
max_workspace_size_bytes=(1<<32))
params = params._replace(precision_mode="FP16")
converter = tf.experimental.tensorrt.Converter(input_saved_model_dir='./model1', conversion_params=params)
converter.convert()
def my_input_fn():
inp1 = np.random.normal(size=(1, 512, 512, 3)).astype(np.float32)
yield [inp1]
converter.build(input_fn=my_input_fn) # Generate corresponding TRT engines
output_saved_model_dir = "trt_graph2"
converter.save(output_saved_model_dir) # Generated engines will be saved.
print("------------------------freezing the graph---------------------")
from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2
saved_model_loaded …Run Code Online (Sandbox Code Playgroud)