如何从内存加载opencv DNN模型?

发布于 2025-01-20 15:18:07 字数 348 浏览 1 评论 0原文

我有一个 caffemodel 和deploy.txt,我想从内存而不是硬盘加载。 我的想法是:

1 - 加密这些文件

2 - 附加在library.so(或可执行文件)的末尾

这些步骤已准备就绪。

现在,

3 - 我将解密这些文件(在内存中)

4 - 我想从内存中打开这些 dnn 模型(而不是文件)

我知道如何执行步骤 3,但不知道如何执行步骤 4。

所以基本上 如何使用 cv::dnn::readNetFromCaffe,而不是从内存中使用文件?

如果答案是 C++,我会更加感激。

I have a caffemodel and deploy.txt that I would like to load from memory, instead of hard disk.
My thoughts are :

1 - to encrypt these files

2 - attached at the end of a library.so (or an executable)

These steps are ready.

Now,

3 - I would decrypt these files (in memory)

4 - I would like to open these dnn model from memory (instead of files)

I know how to do step 3, but no idea about step 4.

So basically how do I use cv::dnn::readNetFromCaffe, but instead of files, from memory?

Would appreciate even more if the answer is in C++.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自演自醉 2025-01-27 15:18:07

这不是解决方案,而是解决方法。

您可以将解密的内存存储到一个文件中,加载它,然后立即删除它。
在 Windows 中,您可以将 FILE_ATTRIBUTE_TEMPORARY 与 CreateFile() 函数一起使用,这样如果缓存大小允许,文件就可以避免写入磁盘。
在 Linux 中,您可以在 open 函数上使用 O_TMPFILE 标志,这将确保文件描述符关闭(或程序崩溃)后文件被删除。但在最后一种情况下,无论大小如何,文件都会写入磁盘。

This is not a solution but a workaround.

You could store the decrypted memory to a file, loaded it and the then delete it immediately after.
In windows you could use FILE_ATTRIBUTE_TEMPORARY with CreateFile() function so the file can avoid writing to disk if the size of cache allows.
In Linux you could use O_TMPFILE flag on the open function which will make sure the file is deleted once the file descriptor is closed (or program crash). But in this last case the file does write to disk no matter the size.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文