声明一个全局类,在类的析构函数中会释放显存。
yolodet::yoloNet net;
int main(int argc, char* argv[]){
std::string engine = "model/yolov4.engine";
net.loadmodel(engine);
return 0;
}
报错:
CUDA error driver shutting down at /home/data/CM/3_image_classification/pytorch_image_classification/device/tensorrt2/src/trt.cpp:195runDet: /home/data/CM/3_image_classification/pytorch_image_classification/device/tensorrt2/src/trt.cpp:195: yolodet::yoloNet::~yoloNet(): Assertion `0’ failed.
Aborted (core dumped)
相似的问题:
http://bbs.gpuworld.cn/index.php?topic=59560.0
解决方案
直接初始化类,不要先声明,再初始化。
// 先声明再初始化
// yolodet::yoloNet net;
std::string engine = "output/mobilenetv2.engine";
yolodet::yoloNet net(engine);
问题二
这样声明全局类还是会报错,只能在用new了。
std::string engine = "output/mobilenetv2.engine";
static yolodet::yoloNet net(engine);
解决方案
std::string engine = "output/mobilenetv2.engine";
yolodet::yoloNet* net = new yolodet::yoloNet(engine);