-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ONE-DCO-1.0-Signed-off-by: ragmani <ragmani0216@gmail.com>
- Loading branch information
Showing
35 changed files
with
1,751 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef __ONERT_API_PYTHON_NNFW_SESSION_BINDINGS_H__ | ||
#define __ONERT_API_PYTHON_NNFW_SESSION_BINDINGS_H__ | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
// Declare binding common functions | ||
void bind_nnfw_session(pybind11::module_ &m); | ||
|
||
// Declare binding experimental functinos | ||
void bind_experimental_nnfw_session(pybind11::module_ &m); | ||
|
||
#endif // __ONERT_API_PYTHON_NNFW_SESSION_BINDINGS_H__ |
25 changes: 25 additions & 0 deletions
25
runtime/onert/api/python/include/nnfw_tensorinfo_bindings.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef __ONERT_API_PYTHON_NNFW_TENSORINFO_BINDINGS_H__ | ||
#define __ONERT_API_PYTHON_NNFW_TENSORINFO_BINDINGS_H__ | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
// Declare binding tensorinfo | ||
void bind_tensorinfo(pybind11::module_ &m); | ||
|
||
#endif // __ONERT_API_PYTHON_NNFW_TENSORINFO_BINDINGS_H__ |
34 changes: 34 additions & 0 deletions
34
runtime/onert/api/python/include/nnfw_traininfo_bindings.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef __ONERT_API_PYTHON_NNFW_TRAININFO_BINDINGS_H__ | ||
#define __ONERT_API_PYTHON_NNFW_TRAININFO_BINDINGS_H__ | ||
|
||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
|
||
namespace py = pybind11; | ||
|
||
// Declare binding train enums | ||
void bind_nnfw_train_enums(py::module_ &m); | ||
|
||
// Declare binding loss info | ||
void bind_nnfw_loss_info(py::module_ &m); | ||
|
||
// Declare binding train info | ||
void bind_nnfw_train_info(py::module_ &m); | ||
|
||
#endif // __ONERT_API_PYTHON_NNFW_TRAININFO_BINDINGS_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,15 @@ | ||
__all__ = ['infer'] | ||
from . import infer | ||
# Define the public API of the onert package | ||
# __all__ = ["infer", "train"] | ||
__all__ = ["infer", "tensorinfo", "train"] | ||
# __all__ = ["tensorinfo", "train"] | ||
|
||
# Import and expose the infer module's functionalities | ||
from . import infer as infer | ||
# from . import session as infer, tensorinfo | ||
|
||
# Import and expose tensorinfo | ||
from .infer import tensorinfo as tensorinfo | ||
|
||
# Import and expose the train module's functionalities | ||
# from . import train | ||
from . import train |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .basesession import BaseSession | ||
|
||
__all__ = ["BaseSession"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import numpy as np | ||
|
||
|
||
def num_elems(tensor_info): | ||
"""Get the total number of elements in nnfw_tensorinfo.dims.""" | ||
n = 1 | ||
for x in range(tensor_info.rank): | ||
n *= tensor_info.dims[x] | ||
return n | ||
|
||
|
||
class BaseSession: | ||
""" | ||
Base class providing common functionality for inference and training sessions. | ||
""" | ||
def __init__(self, backend_session): | ||
""" | ||
Initialize the BaseSession with a backend session. | ||
Args: | ||
backend_session: A backend-specific session object (e.g., nnfw_session). | ||
""" | ||
self.session = backend_session | ||
self.inputs = [] | ||
self.outputs = [] | ||
|
||
def __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. | ||
""" | ||
return getattr(self.session, name) | ||
|
||
# def num_elems(self, tensor_info): | ||
# """ | ||
# Get the total number of elements in a tensor. | ||
|
||
# Args: | ||
# tensor_info: Tensor information object. | ||
|
||
# Returns: | ||
# int: Total number of elements in the tensor. | ||
# """ | ||
# n = 1 | ||
# for x in range(tensor_info.rank): | ||
# n *= tensor_info.dims[x] | ||
# return n | ||
|
||
def 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. | ||
""" | ||
for i in range(size): | ||
input_tensorinfo = self.session.input_tensorinfo(i) | ||
|
||
if len(inputs_array) > i: | ||
input_array = np.array(inputs_array[i], dtype=input_tensorinfo.dtype) | ||
else: | ||
print( | ||
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." | ||
) | ||
input_array = np.zeros((num_elems(input_tensorinfo)), | ||
dtype=input_tensorinfo.dtype) | ||
|
||
self.session.set_input(i, input_array) | ||
self.inputs.append(input_array) | ||
|
||
def set_outputs(self, size): | ||
""" | ||
Set the output tensors for the session. | ||
Args: | ||
size (int): Number of output tensors. | ||
""" | ||
for i in range(size): | ||
output_tensorinfo = self.session.output_tensorinfo(i) | ||
output_array = np.zeros((num_elems(output_tensorinfo)), | ||
dtype=output_tensorinfo.dtype) | ||
self.session.set_output(i, output_array) | ||
self.outputs.append(output_array) |
Oops, something went wrong.