我想得到进程名称,因为它是python中的pid.python中有没有直接的方法?
我在 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) 我正在尝试在 C++ 中运行 TensorRT 推理。有时,当尝试构建新引擎或从文件加载引擎时,代码会崩溃。它偶尔会发生(有时运行没有任何问题)。我按照以下步骤准备网络:
initLibNvInferPlugins(&gLogger.getTRTLogger(), "");
if (mParams.loadEngine.size() > 0)
{
std::vector<char> trtModelStream;
size_t size{0};
std::ifstream file(mParams.loadEngine, std::ios::binary);
if (file.good())
{
file.seekg(0, file.end);
size = file.tellg();
file.seekg(0, file.beg);
trtModelStream.resize(size);
file.read(trtModelStream.data(), size);
file.close();
}
IRuntime* infer_Runtime = nvinfer1::createInferRuntime(gLogger);
if (mParams.dlaCore >= 0)
{
infer_Runtime->setDLACore(mParams.dlaCore);
}
mEngine = std::shared_ptr<nvinfer1::ICudaEngine>(
infer_Runtime->deserializeCudaEngine(trtModelStream.data(), size, nullptr), samplesCommon::InferDeleter());
gLogInfo << "TRT Engine loaded from: " << mParams.loadEngine << endl;
infer_Runtime->destroy();
if (!mEngine)
{
return false;
}
else
{
return true;
}
}
auto builder = SampleUniquePtr<nvinfer1::IBuilder>(nvinfer1::createInferBuilder(gLogger.getTRTLogger())); …Run Code Online (Sandbox Code Playgroud)