Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] lavfi/dnn: Fix OpenVINO missing model file corrupt issue.
@ 2022-08-04  9:31 Ting Fu
  2022-08-04 10:39 ` Anton Khirnov
  0 siblings, 1 reply; 4+ messages in thread
From: Ting Fu @ 2022-08-04  9:31 UTC (permalink / raw)
  To: ffmpeg-devel

DNN OpenVINO backend would not report missing model file if it does not
exist. It would corrupt directly with out any error infomation. This commit
would check both .xml and .bin file existance before loading model.

Signed-off-by: Ting Fu <ting.fu@intel.com>
---
 libavfilter/dnn/dnn_backend_openvino.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c
index b494f26f55..47e3fc8280 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -34,6 +34,7 @@
 #include "../internal.h"
 #include "safe_queue.h"
 #include <c_api/ie_c_api.h>
+#include <unistd.h>
 #include "dnn_backend_common.h"
 
 typedef struct OVOptions{
@@ -728,7 +729,7 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, DNNFunctionType func_
     OVContext *ctx = NULL;
     IEStatusCode status;
     size_t node_count = 0;
-    char *node_name = NULL;
+    char *node_name, *model_binary_file, *extension_chr = NULL;
 
     model = av_mallocz(sizeof(DNNModel));
     if (!model){
@@ -758,6 +759,22 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, DNNFunctionType func_
     if (status != OK)
         goto err;
 
+    //file existance check
+    model_binary_file = (char *)malloc(sizeof(model_filename));
+    strcpy(model_binary_file, model_filename);
+    extension_chr = strstr(model_binary_file, ".xml");
+    if (!extension_chr) {
+        av_log(ctx, AV_LOG_ERROR, "Model file name \"%s\" with incorrect extension.",
+               model_filename);
+        goto err;
+    }
+    strcpy(extension_chr, ".bin");
+    if (access(model_filename, F_OK) || access(model_binary_file, F_OK)) {
+        av_log(ctx, AV_LOG_ERROR, "Model file \"%s\" or \"%s\" does not exist.",
+               model_filename, model_binary_file);
+        goto err;
+    }
+
     status = ie_core_read_network(ov_model->core, model_filename, NULL, &ov_model->network);
     if (status != OK) {
         ie_version_t ver;
@@ -806,6 +823,7 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, DNNFunctionType func_
     return model;
 
 err:
+    free(model_binary_file);
     ff_dnn_free_model_ov(&model);
     return NULL;
 }
-- 
2.17.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-08-06 12:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-04  9:31 [FFmpeg-devel] [PATCH] lavfi/dnn: Fix OpenVINO missing model file corrupt issue Ting Fu
2022-08-04 10:39 ` Anton Khirnov
2022-08-05  3:34   ` Fu, Ting
2022-08-06 12:57   ` Anton Khirnov

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git