ONE - On-device Neural Engine
Loading...
Searching...
No Matches
package.common.basesession.BaseSession Class Reference

Public Member Functions

 __init__ (self, backend_session=None)
 
 __getattr__ (self, name)
 
 set_inputs (self, size, inputs_array=[])
 
 set_outputs (self, size)
 

Data Fields

 session
 
 inputs
 
 outputs
 

Protected Member Functions

 _recreate_session (self, backend_session)
 

Detailed Description

Base class providing common functionality for inference and training sessions.

Definition at line 14 of file basesession.py.

Constructor & Destructor Documentation

◆ __init__()

package.common.basesession.BaseSession.__init__ (   self,
  backend_session = None 
)
Initialize the BaseSession with a backend session.
Args:
    backend_session: A backend-specific session object (e.g., nnfw_session).

Reimplemented in package.infer.session.session.

Definition at line 18 of file basesession.py.

18 def __init__(self, backend_session=None):
19 """
20 Initialize the BaseSession with a backend session.
21 Args:
22 backend_session: A backend-specific session object (e.g., nnfw_session).
23 """
24 self.session = backend_session
25 self.inputs = []
26 self.outputs = []
27

Member Function Documentation

◆ __getattr__()

package.common.basesession.BaseSession.__getattr__ (   self,
  name 
)
Delegate attribute access to the bound NNFW_SESSION instance.
Args:
    name (str): The name of the attribute or method to access.
Returns:
    The attribute or method from the bound NNFW_SESSION instance.

Definition at line 28 of file basesession.py.

28 def __getattr__(self, name):
29 """
30 Delegate attribute access to the bound NNFW_SESSION instance.
31 Args:
32 name (str): The name of the attribute or method to access.
33 Returns:
34 The attribute or method from the bound NNFW_SESSION instance.
35 """
36 if name in self.__dict__:
37 # First, try to get the attribute from the instance's own dictionary
38 return self.__dict__[name]
39 elif hasattr(self.session, name):
40 # If not found, delegate to the session object
41 return getattr(self.session, name)
42 else:
43 raise AttributeError(
44 f"'{type(self).__name__}' object has no attribute '{name}'")
45

References validate_onnx2circle.OnnxRunner.session, onert::api::python::NNFW_SESSION.session, and package.common.basesession.BaseSession.session.

◆ _recreate_session()

package.common.basesession.BaseSession._recreate_session (   self,
  backend_session 
)
protected
Protected method to recreate the session.
Subclasses can override this method to provide custom session recreation logic.

Definition at line 46 of file basesession.py.

46 def _recreate_session(self, backend_session):
47 """
48 Protected method to recreate the session.
49 Subclasses can override this method to provide custom session recreation logic.
50 """
51 if self.session is not None:
52 del self.session # Clean up the existing session
53 self.session = backend_session
54

References validate_onnx2circle.OnnxRunner.session, onert::api::python::NNFW_SESSION.session, and package.common.basesession.BaseSession.session.

Referenced by package.infer.session.session.compile().

◆ set_inputs()

package.common.basesession.BaseSession.set_inputs (   self,
  size,
  inputs_array = [] 
)
Set the input tensors for the session.
Args:
    size (int): Number of input tensors.
    inputs_array (list): List of numpy arrays for the input data.

Definition at line 55 of file basesession.py.

55 def set_inputs(self, size, inputs_array=[]):
56 """
57 Set the input tensors for the session.
58 Args:
59 size (int): Number of input tensors.
60 inputs_array (list): List of numpy arrays for the input data.
61 """
62 if self.session is None:
63 raise ValueError(
64 "Session is not initialized with a model. Please compile with a model before setting inputs."
65 )
66 for i in range(size):
67 input_tensorinfo = self.session.input_tensorinfo(i)
68
69 if len(inputs_array) > i:
70 input_array = np.array(inputs_array[i], dtype=input_tensorinfo.dtype)
71 else:
72 print(
73 f"Model's input size is {size}, but given inputs_array size is {len(inputs_array)}.\n{i}-th index input is replaced by an array filled with 0."
74 )
75 input_array = np.zeros((num_elems(input_tensorinfo)),
76 dtype=input_tensorinfo.dtype)
77
78 self.session.set_input(i, input_array)
79 self.inputs.append(input_array)
80
uint64_t num_elems(const nnfw_tensorinfo *ti)
Definition minimal.cc:21

References Operation.inputs, Request.inputs, circlechef::CircleImport.inputs(), crew::Part.inputs, luci::CircleReader.inputs(), luci::PGroup.inputs, luci::pass::Expression.inputs, mio::circle::Reader.inputs(), moco::ModelSignature.inputs(), tflinspect::Reader.inputs(), tflchef::TFliteImport.inputs(), tflread::Reader.inputs(), luci_interpreter::CircleReader.inputs(), onert_micro::core::reader::OMCircleReader.inputs(), moco::tf::test::TFNodeBuildTester.inputs(), moco::test::TFNodeBuildTester.inputs(), moco::test::TFNodeBuildTester.inputs(), luci::CircleFakeQuant.inputs(), moco::TFFakeQuantWithMinMaxVars.inputs(), luci::CircleAddN.inputs(), luci::CircleCustom.inputs(), luci::CircleAddN.inputs(), luci::CircleCustom.inputs(), loco::Graph.inputs(), nnc::sir::CallFunction.inputs, nnkit::support::onnx::Runner.inputs(), ann::Operation.inputs(), loco::Graph.inputs(), luci::CircleFakeQuant.inputs(), moco::TFFakeQuantWithMinMaxVars.inputs(), validate_onnx2circle.OnnxRunner.inputs, onert_micro::execute::OMRuntimeKernel.inputs, nnfw_custom_kernel_params.inputs, package.common.basesession.BaseSession.inputs, onert::exec::IODescription.inputs, package.common.basesession.num_elems(), validate_onnx2circle.OnnxRunner.session, onert::api::python::NNFW_SESSION.session, and package.common.basesession.BaseSession.session.

◆ set_outputs()

package.common.basesession.BaseSession.set_outputs (   self,
  size 
)
Set the output tensors for the session.
Args:
    size (int): Number of output tensors.

Definition at line 81 of file basesession.py.

81 def set_outputs(self, size):
82 """
83 Set the output tensors for the session.
84 Args:
85 size (int): Number of output tensors.
86 """
87 if self.session is None:
88 raise ValueError(
89 "Session is not initialized with a model. Please compile a model before setting outputs."
90 )
91 for i in range(size):
92 output_tensorinfo = self.session.output_tensorinfo(i)
93 output_array = np.zeros((num_elems(output_tensorinfo)),
94 dtype=output_tensorinfo.dtype)
95 self.session.set_output(i, output_array)
96 self.outputs.append(output_array)
97
98

References package.common.basesession.num_elems(), Operation.outputs, Request.outputs, circlechef::CircleImport.outputs(), crew::Part.outputs, luci::CircleReader.outputs(), luci::PGroup.outputs, mio::circle::Reader.outputs(), moco::ModelSignature.outputs(), nnc::sir::CallFunction.outputs, validate_onnx2circle.OnnxRunner.outputs, tflinspect::Reader.outputs(), tflchef::TFliteImport.outputs(), tflread::Reader.outputs(), luci_interpreter::CircleReader.outputs(), onert_micro::core::reader::OMCircleReader.outputs(), mio::circle::Reader.outputs(), loco::Graph.outputs(), nnkit::support::onnx::Runner.outputs(), ann::Operation.outputs(), loco::Graph.outputs(), onert_micro::execute::OMRuntimeKernel.outputs, nnfw_custom_kernel_params.outputs, package.common.basesession.BaseSession.outputs, onert::exec::IODescription.outputs, validate_onnx2circle.OnnxRunner.session, onert::api::python::NNFW_SESSION.session, and package.common.basesession.BaseSession.session.

Referenced by package.infer.session.session.__init__(), and package.infer.session.session.compile().

Field Documentation

◆ inputs

package.common.basesession.BaseSession.inputs

◆ outputs

◆ session


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