ONE - On-device Neural Engine
Loading...
Searching...
No Matches
package.infer.session.session Class Reference
Collaboration diagram for package.infer.session.session:

Public Member Functions

 __init__ (self, str path=None, str backends="cpu")
 
 compile (self, str path, str backends="cpu")
 
 inference (self)
 
- Public Member Functions inherited from package.common.basesession.BaseSession
 __getattr__ (self, name)
 
 set_inputs (self, size, inputs_array=[])
 
 set_outputs (self, size)
 

Additional Inherited Members

- Data Fields inherited from package.common.basesession.BaseSession
 session
 
 inputs
 
 outputs
 
- Protected Member Functions inherited from package.common.basesession.BaseSession
 _recreate_session (self, backend_session)
 

Detailed Description

Class for inference using nnfw_session.

Definition at line 5 of file session.py.

Constructor & Destructor Documentation

◆ __init__()

package.infer.session.session.__init__ (   self,
str   path = None,
str   backends = "cpu" 
)
Initialize the inference session.
Args:
    path (str): Path to the model file or nnpackage directory.
    backends (str): Backends to use, default is "cpu".

Reimplemented from package.common.basesession.BaseSession.

Definition at line 9 of file session.py.

9 def __init__(self, path: str = None, backends: str = "cpu"):
10 """
11 Initialize the inference session.
12 Args:
13 path (str): Path to the model file or nnpackage directory.
14 backends (str): Backends to use, default is "cpu".
15 """
16 if path is not None:
17 super().__init__(libnnfw_api_pybind.infer.nnfw_session(path, backends))
18 self.session.prepare()
19 self.set_outputs(self.session.output_size())
20 else:
21 super().__init__()
22

References package.infer.session.session.__init__(), validate_onnx2circle.OnnxRunner.session, onert::api::python::NNFW_SESSION.session, package.common.basesession.BaseSession.session, and package.common.basesession.BaseSession.set_outputs().

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

Member Function Documentation

◆ compile()

package.infer.session.session.compile (   self,
str  path,
str   backends = "cpu" 
)
Prepare the session by recreating it with new parameters.
Args:
    path (str): Path to the model file or nnpackage directory. Defaults to the existing path.
    backends (str): Backends to use. Defaults to the existing backends.

Definition at line 23 of file session.py.

23 def compile(self, path: str, backends: str = "cpu"):
24 """
25 Prepare the session by recreating it with new parameters.
26 Args:
27 path (str): Path to the model file or nnpackage directory. Defaults to the existing path.
28 backends (str): Backends to use. Defaults to the existing backends.
29 """
30 # Update parameters if provided
31 if path is None:
32 raise ValueError("path must not be None.")
33 # Recreate the session with updated parameters
34 self._recreate_session(libnnfw_api_pybind.infer.nnfw_session(path, backends))
35 # Prepare the new session
36 self.session.prepare()
37 self.set_outputs(self.session.output_size())
38

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

◆ inference()


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