Add Execution Provider OpenVINO
This commit is contained in:
parent
62731c958c
commit
6377ebf568
4
.devcontainer/devcontainer.json
Normal file
4
.devcontainer/devcontainer.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "FT-Driverless Dev",
|
||||
"image": "git.fasttube.de/ft-driverless/ft_as:gstreamer-plugin-bad"
|
||||
}
|
@ -21,7 +21,9 @@
|
||||
*/
|
||||
|
||||
#include "gstonnxclient.h"
|
||||
#include <cpu_provider_factory.h>
|
||||
#include <onnxruntime_cxx_api.h>
|
||||
#include <onnxruntime/core/providers/cpu/cpu_provider_factory.h>
|
||||
#include <onnxruntime/core/providers/openvino/openvino_provider_factory.h>
|
||||
#include <sstream>
|
||||
|
||||
#define GST_CAT_DEFAULT onnx_inference_debug
|
||||
@ -63,8 +65,9 @@ GstOnnxClient::GstOnnxClient (GstElement *debug_parent):debug_parent(debug_paren
|
||||
inputDatatypeSize (sizeof (uint8_t)),
|
||||
fixedInputImageSize (false),
|
||||
inputTensorOffset (0.0),
|
||||
inputTensorScale (1.0)
|
||||
{
|
||||
inputTensorScale (1.0),
|
||||
provider_config(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
GstOnnxClient::~GstOnnxClient () {
|
||||
@ -72,6 +75,10 @@ GstOnnxClient::GstOnnxClient (GstElement *debug_parent):debug_parent(debug_paren
|
||||
delete[]dest;
|
||||
}
|
||||
|
||||
void GstOnnxClient::setProviderConfig (const char *config)
|
||||
{
|
||||
provider_config = config;
|
||||
}
|
||||
int32_t GstOnnxClient::getWidth (void)
|
||||
{
|
||||
return width;
|
||||
@ -222,6 +229,20 @@ GstOnnxClient::GstOnnxClient (GstElement *debug_parent):debug_parent(debug_paren
|
||||
(sessionOptions, 1));
|
||||
}
|
||||
break;
|
||||
case GST_ONNX_EXECUTION_PROVIDER_OPENVINO: {
|
||||
std::unordered_map<std::string, std::string> ovOptions;
|
||||
if (this->provider_config) {
|
||||
std::istringstream ss(this->provider_config);
|
||||
std::string kv;
|
||||
while (std::getline(ss, kv, ',')) {
|
||||
auto pos = kv.find('=');
|
||||
if (pos == std::string::npos) continue;
|
||||
ovOptions[kv.substr(0, pos)] = kv.substr(pos + 1);
|
||||
}
|
||||
}
|
||||
sessionOptions.AppendExecutionProvider("OpenVINO", ovOptions);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Ort::ThrowOnError (OrtSessionOptionsAppendExecutionProvider_CPU
|
||||
(sessionOptions, 1));
|
||||
|
@ -54,6 +54,7 @@ typedef enum
|
||||
{
|
||||
GST_ONNX_EXECUTION_PROVIDER_CPU,
|
||||
GST_ONNX_EXECUTION_PROVIDER_CUDA,
|
||||
GST_ONNX_EXECUTION_PROVIDER_OPENVINO,
|
||||
} GstOnnxExecutionProvider;
|
||||
|
||||
|
||||
@ -82,6 +83,7 @@ namespace GstOnnxNamespace {
|
||||
GstTensorMeta *copy_tensors_to_meta (std::vector<Ort::Value> &outputs,
|
||||
GstBuffer *buffer);
|
||||
void parseDimensions(GstVideoInfo vinfo);
|
||||
void setProviderConfig(const char *config);
|
||||
private:
|
||||
|
||||
GstElement *debug_parent;
|
||||
@ -108,6 +110,7 @@ namespace GstOnnxNamespace {
|
||||
bool fixedInputImageSize;
|
||||
float inputTensorOffset;
|
||||
float inputTensorScale;
|
||||
const char *provider_config;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -84,6 +84,7 @@ struct _GstOnnxInference
|
||||
gpointer onnx_client;
|
||||
gboolean onnx_disabled;
|
||||
GstVideoInfo video_info;
|
||||
gchar *provider_config;
|
||||
};
|
||||
|
||||
GST_DEBUG_CATEGORY (onnx_inference_debug);
|
||||
@ -101,6 +102,7 @@ enum
|
||||
PROP_INPUT_IMAGE_FORMAT,
|
||||
PROP_OPTIMIZATION_LEVEL,
|
||||
PROP_EXECUTION_PROVIDER,
|
||||
PROP_PROVIDER_CONFIG,
|
||||
PROP_INPUT_OFFSET,
|
||||
PROP_INPUT_SCALE
|
||||
};
|
||||
@ -190,6 +192,9 @@ gst_onnx_execution_provider_get_type (void)
|
||||
{GST_ONNX_EXECUTION_PROVIDER_CUDA,
|
||||
"CUDA execution provider",
|
||||
"cuda"},
|
||||
{GST_ONNX_EXECUTION_PROVIDER_OPENVINO,
|
||||
"OPENVINO execution provider",
|
||||
"openvino"},
|
||||
{0, NULL, NULL},
|
||||
};
|
||||
|
||||
@ -316,6 +321,14 @@ gst_onnx_inference_class_init (GstOnnxInferenceClass * klass)
|
||||
G_MINFLOAT, G_MAXFLOAT, 1.0,
|
||||
(GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
||||
|
||||
g_object_class_install_property (G_OBJECT_CLASS (klass),
|
||||
PROP_PROVIDER_CONFIG,
|
||||
g_param_spec_string ("provider-config",
|
||||
"Provider config",
|
||||
"Comma-separierte Key=Value-Optionen",
|
||||
nullptr,
|
||||
(GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
||||
|
||||
|
||||
gst_element_class_set_static_metadata (element_class, "onnxinference",
|
||||
"Filter/Effect/Video",
|
||||
@ -351,7 +364,8 @@ static void
|
||||
gst_onnx_inference_finalize (GObject * object)
|
||||
{
|
||||
GstOnnxInference *self = GST_ONNX_INFERENCE (object);
|
||||
|
||||
g_free (self->provider_config);
|
||||
self->provider_config = NULL;
|
||||
g_free (self->model_file);
|
||||
delete GST_ONNX_CLIENT_MEMBER (self);
|
||||
G_OBJECT_CLASS (gst_onnx_inference_parent_class)->finalize (object);
|
||||
@ -397,6 +411,11 @@ gst_onnx_inference_set_property (GObject * object, guint prop_id,
|
||||
case PROP_INPUT_SCALE:
|
||||
onnxClient->setInputImageScale (g_value_get_float (value));
|
||||
break;
|
||||
case PROP_PROVIDER_CONFIG:
|
||||
g_free (self->provider_config);
|
||||
self->provider_config = g_value_dup_string (value);
|
||||
onnxClient->setProviderConfig(self->provider_config);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user