namespace ngraph::onnx_import¶
Overview¶
ONNX importer features namespace. Functions in this namespace make it possible to use ONNX models. More…
namespace onnx_import {
// namespaces
namespace ngraph::onnx_import::detail;
namespace ngraph::onnx_import::error;
namespace ngraph::onnx_import::error::node;
// typedefs
typedef std::function<OutputVector(const Node&)> Operator;
typedef std::unordered_map<std::string, std::reference_wrapper<const Operator>> OperatorSet;
// classes
class Node;
// global functions
std::ostream& operator << (std::ostream& outs, const Node& node);
std::set<std::string> get_supported_operators (
std::int64_t version,
const std::string& domain
);
bool is_operator_supported (
const std::string& op_name,
std::int64_t version,
const std::string& domain = "ai.onnx"
);
std::shared_ptr<Function> import_onnx_model(
std::istream& stream,
const std::string& model_path = ""
);
std::shared_ptr<Function> import_onnx_model(const std::string& file_path);
void register_operator (
const std::string& name,
std::int64_t version,
const std::string& domain,
Operator fn
);
void unregister_operator (
const std::string& name,
std::int64_t version,
const std::string& domain
);
} // namespace onnx_import
Detailed Documentation¶
ONNX importer features namespace. Functions in this namespace make it possible to use ONNX models.
Typedefs¶
typedef std::function<OutputVector(const Node&)> Operator
Function which transforms single ONNX operator to nGraph sub-graph.
typedef std::unordered_map<std::string, std::reference_wrapper<const Operator>> OperatorSet
Map which contains ONNX operators accessible by std::string value as a key.
Global Functions¶
std::set<std::string> get_supported_operators (
std::int64_t version,
const std::string& domain
)
Returns a set of names of supported operators for the given opset version and domain.
Parameters:
version |
An opset version to get the supported operators for. |
domain |
A domain to get the supported operators for. |
Returns:
The set containing names of supported operators.
bool is_operator_supported (
const std::string& op_name,
std::int64_t version,
const std::string& domain = "ai.onnx"
)
Determines whether ONNX operator is supported.
Parameters:
op_name |
The ONNX operator name. |
version |
The ONNX operator set version. |
domain |
The domain the ONNX operator is registered to. If not set, the default domain “ai.onnx” is used. |
Returns:
true if operator is supported, false otherwise.
std::shared_ptr<Function> import_onnx_model(
std::istream& stream,
const std::string& model_path = ""
)
Imports and converts an serialized ONNX model from the input stream to an nGraph Function representation.
If stream parsing fails or the ONNX model contains unsupported ops, the function throws an ngraph_error exception.
Parameters:
stream |
The input stream (e.g. file stream, memory stream, etc). |
model_path |
The path to the imported onnx model. It is required if the imported model uses data saved in external files. |
Returns:
An nGraph function that represents a single output from the created graph.
std::shared_ptr<Function> import_onnx_model(const std::string& file_path)
Imports and converts an ONNX model from the input file to an nGraph Function representation.
If file parsing fails or the ONNX model contains unsupported ops, the function throws an ngraph_error exception.
Parameters:
file_path |
The path to a file containing the ONNX model (relative or absolute). |
Returns:
An nGraph function that represents a single output from the created graph.
void register_operator (
const std::string& name,
std::int64_t version,
const std::string& domain,
Operator fn
)
Registers ONNX custom operator. The function performs the registration of external ONNX operator which is not part of ONNX importer.
The operator must be registered before calling “import_onnx_model” functions.
Parameters:
name |
The ONNX operator name. |
version |
The ONNX operator set version. |
domain |
The domain the ONNX operator is registered to. |
fn |
The function providing the implementation of the operator which transforms the single ONNX operator to an nGraph sub-graph. |
void unregister_operator (
const std::string& name,
std::int64_t version,
const std::string& domain
)
Unregisters ONNX custom operator. The function unregisters previously registered operator.
Parameters:
name |
The ONNX operator name. |
version |
The ONNX operator set version. |
domain |
The domain the ONNX operator is registered to. |