ONE - On-device Neural Engine
Loading...
Searching...
No Matches
circle_resizer::CircleModel Class Reference

#include <CircleModel.h>

Public Member Functions

 CircleModel (const std::vector< uint8_t > &buffer)
 Initialize the model with buffer representation.
 
 CircleModel (const std::string &model_path)
 Initialize the model with buffer representation.
 
 ~CircleModel ()
 Dtor of CircleModel. Note that explicit declaration is needed to satisfy forward declaration + unique_ptr.
 
luci::Modulemodule ()
 Get the loaded model in luci::Module representation.
 
std::vector< Shapeinput_shapes () const
 Get input shapes of the loaded model.
 
std::vector< Shapeoutput_shapes () const
 Get output shapes of the loaded model.
 
void save (std::ostream &stream)
 Save the model to the output stream.
 
void save (const std::string &output_path)
 Save the model to the location indicated by output_path.
 

Detailed Description

The representation of Circle Model.

Definition at line 37 of file CircleModel.h.

Constructor & Destructor Documentation

◆ CircleModel() [1/2]

CircleModel::CircleModel ( const std::vector< uint8_t > &  buffer)
explicit

Initialize the model with buffer representation.

Exceptions:

  • std::runtime_error if interpretation of provided buffer as a circle model failed.

Definition at line 117 of file CircleModel.cpp.

117: _module{load_module(buffer)} {}

◆ CircleModel() [2/2]

CircleModel::CircleModel ( const std::string &  model_path)
explicit

Initialize the model with buffer representation.

Exceptions:

  • std::runtime_error if reading a model from provided path failed.

Definition at line 119 of file CircleModel.cpp.

119: CircleModel(read_model(model_path)) {}

◆ ~CircleModel()

CircleModel::~CircleModel ( )
default

Dtor of CircleModel. Note that explicit declaration is needed to satisfy forward declaration + unique_ptr.

Member Function Documentation

◆ input_shapes()

std::vector< Shape > CircleModel::input_shapes ( ) const

Get input shapes of the loaded model.

Definition at line 146 of file CircleModel.cpp.

147{
148 return extract_shapes<luci::CircleInput>(loco::input_nodes(_module->graph()));
149}
std::vector< Node * > input_nodes(const Graph *)
Definition Graph.cpp:71

References loco::input_nodes().

◆ module()

luci::Module * CircleModel::module ( )

Get the loaded model in luci::Module representation.

Definition at line 121 of file CircleModel.cpp.

121{ return _module.get(); }

Referenced by save().

◆ output_shapes()

std::vector< Shape > CircleModel::output_shapes ( ) const

Get output shapes of the loaded model.

Definition at line 151 of file CircleModel.cpp.

152{
153 return extract_shapes<luci::CircleOutput>(loco::output_nodes(_module->graph()));
154}
std::vector< Node * > output_nodes(Graph *)
Definition Graph.cpp:101

References loco::output_nodes().

◆ save() [1/2]

void CircleModel::save ( const std::string &  output_path)

Save the model to the location indicated by output_path.

Exceptions:

  • std::runtime_error if saving the model the given path failed.

Definition at line 140 of file CircleModel.cpp.

141{
142 std::ofstream out_stream(output_path, std::ios::out | std::ios::binary);
143 save(out_stream);
144}
void save(std::ostream &stream)
Save the model to the output stream.

References save().

◆ save() [2/2]

void CircleModel::save ( std::ostream &  stream)

Save the model to the output stream.

Exceptions:

  • std::runtime_error if saving the model the given stream failed.

Definition at line 123 of file CircleModel.cpp.

124{
125 BufferModelContract contract(module());
126 luci::CircleExporter exporter;
127 if (!exporter.invoke(&contract))
128 {
129 throw std::runtime_error("Exporting buffer from the model failed");
130 }
131
132 auto model_buffer = contract.get_buffer();
133 stream.write(reinterpret_cast<const char *>(model_buffer.data()), model_buffer.size());
134 if (!stream.good())
135 {
136 throw std::runtime_error("Failed to write to output stream");
137 }
138}
luci::Module * module()
Get the loaded model in luci::Module representation.
bool invoke(Contract *) const

References luci::CircleExporter::invoke(), and module().

Referenced by save().


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