Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
447116a9
Commit
447116a9
authored
May 18, 2019
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14524 from kohei-us:onnx-load-binary-blob
parents
d848594d
7b4aefed
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
0 deletions
+48
-0
dnn.hpp
modules/dnn/include/opencv2/dnn/dnn.hpp
+17
-0
onnx_importer.cpp
modules/dnn/src/onnx/onnx_importer.cpp
+31
-0
No files found.
modules/dnn/include/opencv2/dnn/dnn.hpp
View file @
447116a9
...
...
@@ -868,6 +868,23 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
*/
CV_EXPORTS_W
Net
readNetFromONNX
(
const
String
&
onnxFile
);
/** @brief Reads a network model from <a href="https://onnx.ai/">ONNX</a>
* in-memory buffer.
* @param buffer memory address of the first byte of the buffer.
* @param sizeBuffer size of the buffer.
* @returns Network object that ready to do forward, throw an exception
* in failure cases.
*/
CV_EXPORTS
Net
readNetFromONNX
(
const
char
*
buffer
,
size_t
sizeBuffer
);
/** @brief Reads a network model from <a href="https://onnx.ai/">ONNX</a>
* in-memory buffer.
* @param buffer in-memory buffer that stores the ONNX model bytes.
* @returns Network object that ready to do forward, throw an exception
* in failure cases.
*/
CV_EXPORTS_W
Net
readNetFromONNX
(
const
std
::
vector
<
uchar
>&
buffer
);
/** @brief Creates blob from .pb file.
* @param path to the .pb file with input tensor.
* @returns Mat.
...
...
modules/dnn/src/onnx/onnx_importer.cpp
View file @
447116a9
...
...
@@ -57,6 +57,24 @@ public:
CV_Error
(
Error
::
StsUnsupportedFormat
,
"Failed to parse onnx model"
);
}
ONNXImporter
(
const
char
*
buffer
,
size_t
sizeBuffer
)
{
struct
_Buf
:
public
std
::
streambuf
{
_Buf
(
const
char
*
buffer
,
size_t
sizeBuffer
)
{
char
*
p
=
const_cast
<
char
*>
(
buffer
);
setg
(
p
,
p
,
p
+
sizeBuffer
);
}
};
_Buf
buf
(
buffer
,
sizeBuffer
);
std
::
istream
input
(
&
buf
);
if
(
!
model_proto
.
ParseFromIstream
(
&
input
))
CV_Error
(
Error
::
StsUnsupportedFormat
,
"Failed to parse onnx model from in-memory byte array."
);
}
void
populateNet
(
Net
dstNet
);
};
...
...
@@ -808,6 +826,19 @@ Net readNetFromONNX(const String& onnxFile)
return
net
;
}
Net
readNetFromONNX
(
const
char
*
buffer
,
size_t
sizeBuffer
)
{
ONNXImporter
onnxImporter
(
buffer
,
sizeBuffer
);
Net
net
;
onnxImporter
.
populateNet
(
net
);
return
net
;
}
Net
readNetFromONNX
(
const
std
::
vector
<
uchar
>&
buffer
)
{
return
readNetFromONNX
(
reinterpret_cast
<
const
char
*>
(
buffer
.
data
()),
buffer
.
size
());
}
Mat
readTensorFromONNX
(
const
String
&
path
)
{
opencv_onnx
::
TensorProto
tensor_proto
=
opencv_onnx
::
TensorProto
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment