onnxobjectdetector: gracefully handle Ort exceptions rather than dumping core

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4765>
This commit is contained in:
Aaron Boxer 2023-06-02 13:21:06 -04:00 committed by GStreamer Marge Bot
parent a1c2df830b
commit e624e7c695
2 changed files with 63 additions and 48 deletions

View file

@ -203,6 +203,7 @@ bool GstOnnxClient::createSession (std::string modelFile,
break;
};
try {
Ort::SessionOptions sessionOptions;
// for debugging
//sessionOptions.SetIntraOpNumThreads (1);
@ -214,6 +215,7 @@ bool GstOnnxClient::createSession (std::string modelFile,
Ort::ThrowOnError (OrtSessionOptionsAppendExecutionProvider_CUDA
(sessionOptions, 0));
#else
GST_ERROR ("ONNX CUDA execution provider not supported");
return false;
#endif
break;
@ -221,7 +223,8 @@ bool GstOnnxClient::createSession (std::string modelFile,
break;
};
session = new Ort::Session (getEnv (), modelFile.c_str (), sessionOptions);
session =
new Ort::Session (getEnv (), modelFile.c_str (), sessionOptions);
auto inputTypeInfo = session->GetInputTypeInfo (0);
std::vector < int64_t > inputDims =
inputTypeInfo.GetTensorTypeAndShapeInfo ().GetShape ();
@ -236,7 +239,8 @@ bool GstOnnxClient::createSession (std::string modelFile,
}
fixedInputImageSize = width > 0 && height > 0;
GST_DEBUG ("Number of Output Nodes: %d", (gint) session->GetOutputCount ());
GST_DEBUG ("Number of Output Nodes: %d",
(gint) session->GetOutputCount ());
Ort::AllocatorWithDefaultOptions allocator;
auto input_name = session->GetInputNameAllocated (0, allocator);
@ -254,6 +258,11 @@ bool GstOnnxClient::createSession (std::string modelFile,
outputNodeInfo[function].type = tensor_info.GetElementType ();
}
}
}
catch (Ort::Exception & ortex) {
GST_ERROR ("%s", ortex.what ());
return false;
}
return true;
}

View file

@ -643,9 +643,15 @@ gst_onnx_object_detector_process (GstBaseTransform * trans, GstBuffer * buf)
}
if (gst_buffer_map (buf, &info, GST_MAP_READ)) {
GstOnnxObjectDetector *self = GST_ONNX_OBJECT_DETECTOR (trans);
auto boxes = GST_ONNX_MEMBER (self)->run (info.data, vmeta,
self->label_file ? self->label_file : "",
self->score_threshold);
std::vector < GstOnnxNamespace::GstMlBoundingBox > boxes;
try {
boxes = GST_ONNX_MEMBER (self)->run (info.data, vmeta,
self->label_file ? self->label_file : "", self->score_threshold);
}
catch (Ort::Exception & ortex) {
GST_ERROR_OBJECT (self, "%s", ortex.what ());
return FALSE;
}
for (auto & b:boxes) {
auto vroi_meta = gst_buffer_add_video_region_of_interest_meta (buf,
GST_ONNX_OBJECT_DETECTOR_META_NAME,