Public Member Functions
ngraph::onnx_import::ONNXModelEditor Class Referencefinal

A class representing a set of utilities allowing modification of an ONNX model. More...

#include <editor.hpp>

Public Member Functions

 ONNXModelEditor (const std::string &model_path)
 Creates an editor from a model file located on a storage device. The file is parsed and loaded into the m_model_proto member variable. More...
 
void set_input_types (const std::map< std::string, element::Type_t > &input_types)
 Modifies the in-memory representation of the model (m_model_proto) by setting custom input types for all inputs specified in the provided map. More...
 
void set_input_shapes (const std::map< std::string, ngraph::PartialShape > &input_shapes)
 Modifies the in-memory representation of the model (m_model_proto) by setting custom input shapes for all inputs specified in the provided map. More...
 
void set_input_values (const std::map< std::string, std::shared_ptr< ngraph::op::Constant >> &input_values)
 Modifies the in-memory representation of the model by setting custom input values for inputs specified in the provided map. More...
 
ONNX_NAMESPACE::ModelProto & model () const
 Returns a non-const reference to the underlying ModelProto object, possibly modified by the editor's API calls. More...
 
const std::string & model_path () const
 Returns the path to the original model file.
 
void serialize (const std::string &out_file_path) const
 Saves the possibly model held by this class to a file. Serializes in binary mode. More...
 

Detailed Description

A class representing a set of utilities allowing modification of an ONNX model.

Note
This class can be used to modify an ONNX model before it gets translated to an ngraph::Function by the import_onnx_model function. It lets you modify the model's input types and shapes, extract a subgraph and more. An instance of this class can be passed directly to the onnx_importer API.

Constructor & Destructor Documentation

◆ ONNXModelEditor()

ngraph::onnx_import::ONNXModelEditor::ONNXModelEditor ( const std::string &  model_path)

Creates an editor from a model file located on a storage device. The file is parsed and loaded into the m_model_proto member variable.

Parameters
model_pathPath to the file containing the model.

Member Function Documentation

◆ model()

ONNX_NAMESPACE::ModelProto& ngraph::onnx_import::ONNXModelEditor::model ( ) const

Returns a non-const reference to the underlying ModelProto object, possibly modified by the editor's API calls.

Returns
A reference to ONNX ModelProto object containing the in-memory model

◆ serialize()

void ngraph::onnx_import::ONNXModelEditor::serialize ( const std::string &  out_file_path) const

Saves the possibly model held by this class to a file. Serializes in binary mode.

Parameters
out_file_pathA path to the file where the modified model should be dumped.

◆ set_input_shapes()

void ngraph::onnx_import::ONNXModelEditor::set_input_shapes ( const std::map< std::string, ngraph::PartialShape > &  input_shapes)

Modifies the in-memory representation of the model (m_model_proto) by setting custom input shapes for all inputs specified in the provided map.

Parameters
input_shapesA collection of pairs {input_name: new_input_shape} that should be used to modified the ONNX model loaded from a file. This method throws an exception if the model doesn't contain any of the inputs specified in its parameter.

◆ set_input_types()

void ngraph::onnx_import::ONNXModelEditor::set_input_types ( const std::map< std::string, element::Type_t > &  input_types)

Modifies the in-memory representation of the model (m_model_proto) by setting custom input types for all inputs specified in the provided map.

Parameters
input_typesA collection of pairs {input_name: new_input_type} that should be used to modified the ONNX model loaded from a file. This method throws an exception if the model doesn't contain any of the inputs specified in its parameter.

◆ set_input_values()

void ngraph::onnx_import::ONNXModelEditor::set_input_values ( const std::map< std::string, std::shared_ptr< ngraph::op::Constant >> &  input_values)

Modifies the in-memory representation of the model by setting custom input values for inputs specified in the provided map.

Note
This method modifies existing initializer tensor if its name matches one of input_name. Otherwise it adds initializer tensor into the model. If input tensor of matching name is present in the model, its type and shape are modified accordingly.
Parameters
input_valuesA collection of pairs {input_name: new_input_values} used to update the ONNX model. Initializers already existing are overwritten.

The documentation for this class was generated from the following file: