33 py::class_<NNFW_SESSION>(
m,
"nnfw_session", py::module_local())
35 py::init<const char *, const char *>(), py::arg(
"package_file_path"), py::arg(
"backends"),
36 "Create a new session instance, load model from nnpackage file or directory, "
37 "set available backends and prepare session to be ready for inference\n"
39 "\tpackage_file_path (str): Path to the nnpackage file or unzipped directory to be loaded\n"
40 "\tbackends (str): Available backends on which nnfw uses\n"
41 "\t\tMultiple backends can be set and they must be separated by a semicolon "
42 "(ex: \"acl_cl;cpu\")\n"
43 "\t\tAmong the multiple backends, the 1st element is used as the default backend.")
45 py::arg(
"tensor_info"),
46 "Set input model's tensor info for resizing.\n"
48 "\tindex (int): Index of input to be set (0-indexed)\n"
49 "\ttensor_info (tensorinfo): Tensor info to be set")
56 [](
NNFW_SESSION &session, uint32_t index, py::array_t<float> &buffer) {
57 session.set_input<
float>(index, buffer);
59 py::arg(
"index"), py::arg(
"buffer"),
62 "\tindex (int): Index of input to be set (0-indexed)\n"
63 "\tbuffer (numpy): Raw buffer for input")
66 [](
NNFW_SESSION &session, uint32_t index, py::array_t<int> &buffer) {
67 session.set_input<
int>(index, buffer);
69 py::arg(
"index"), py::arg(
"buffer"),
72 "\tindex (int): Index of input to be set (0-indexed)\n"
73 "\tbuffer (numpy): Raw buffer for input")
76 [](
NNFW_SESSION &session, uint32_t index, py::array_t<uint8_t> &buffer) {
77 session.set_input<uint8_t>(index, buffer);
79 py::arg(
"index"), py::arg(
"buffer"),
82 "\tindex (int): Index of input to be set (0-indexed)\n"
83 "\tbuffer (numpy): Raw buffer for input")
86 [](
NNFW_SESSION &session, uint32_t index, py::array_t<bool> &buffer) {
87 session.set_input<
bool>(index, buffer);
89 py::arg(
"index"), py::arg(
"buffer"),
92 "\tindex (int): Index of input to be set (0-indexed)\n"
93 "\tbuffer (numpy): Raw buffer for input")
96 [](
NNFW_SESSION &session, uint32_t index, py::array_t<int64_t> &buffer) {
97 session.set_input<int64_t>(index, buffer);
99 py::arg(
"index"), py::arg(
"buffer"),
102 "\tindex (int): Index of input to be set (0-indexed)\n"
103 "\tbuffer (numpy): Raw buffer for input")
106 [](
NNFW_SESSION &session, uint32_t index, py::array_t<int8_t> &buffer) {
107 session.set_input<int8_t>(index, buffer);
109 py::arg(
"index"), py::arg(
"buffer"),
112 "\tindex (int): Index of input to be set (0-indexed)\n"
113 "\tbuffer (numpy): Raw buffer for input")
116 [](
NNFW_SESSION &session, uint32_t index, py::array_t<int16_t> &buffer) {
117 session.set_input<int16_t>(index, buffer);
119 py::arg(
"index"), py::arg(
"buffer"),
122 "\tindex (int): Index of input to be set (0-indexed)\n"
123 "\tbuffer (numpy): Raw buffer for input")
126 [](
NNFW_SESSION &session, uint32_t index, py::array_t<float> &buffer) {
127 session.set_output<
float>(index, buffer);
129 py::arg(
"index"), py::arg(
"buffer"),
130 "Set output buffer\n"
132 "\tindex (int): Index of output to be set (0-indexed)\n"
133 "\tbuffer (numpy): Raw buffer for output")
136 [](
NNFW_SESSION &session, uint32_t index, py::array_t<int> &buffer) {
137 session.set_output<
int>(index, buffer);
139 py::arg(
"index"), py::arg(
"buffer"),
140 "Set output buffer\n"
142 "\tindex (int): Index of output to be set (0-indexed)\n"
143 "\tbuffer (numpy): Raw buffer for output")
146 [](
NNFW_SESSION &session, uint32_t index, py::array_t<uint8_t> &buffer) {
147 session.set_output<uint8_t>(index, buffer);
149 py::arg(
"index"), py::arg(
"buffer"),
150 "Set output buffer\n"
152 "\tindex (int): Index of output to be set (0-indexed)\n"
153 "\tbuffer (numpy): Raw buffer for output")
156 [](
NNFW_SESSION &session, uint32_t index, py::array_t<bool> &buffer) {
157 session.set_output<
bool>(index, buffer);
159 py::arg(
"index"), py::arg(
"buffer"),
160 "Set output buffer\n"
162 "\tindex (int): Index of output to be set (0-indexed)\n"
163 "\tbuffer (numpy): Raw buffer for output")
166 [](
NNFW_SESSION &session, uint32_t index, py::array_t<int64_t> &buffer) {
167 session.set_output<int64_t>(index, buffer);
169 py::arg(
"index"), py::arg(
"buffer"),
170 "Set output buffer\n"
172 "\tindex (int): Index of output to be set (0-indexed)\n"
173 "\tbuffer (numpy): Raw buffer for output")
176 [](
NNFW_SESSION &session, uint32_t index, py::array_t<int8_t> &buffer) {
177 session.set_output<int8_t>(index, buffer);
179 py::arg(
"index"), py::arg(
"buffer"),
180 "Set output buffer\n"
182 "\tindex (int): Index of output to be set (0-indexed)\n"
183 "\tbuffer (numpy): Raw buffer for output")
186 [](
NNFW_SESSION &session, uint32_t index, py::array_t<int16_t> &buffer) {
187 session.set_output<int16_t>(index, buffer);
189 py::arg(
"index"), py::arg(
"buffer"),
190 "Set output buffer\n"
192 "\tindex (int): Index of output to be set (0-indexed)\n"
193 "\tbuffer (numpy): Raw buffer for output")
195 "Get the number of inputs defined in loaded model\n"
197 "\tint: The number of inputs")
199 "Get the number of outputs defined in loaded model\n"
201 "\tint: The number of outputs")
203 py::arg(
"layout") =
"NONE",
204 "Set the layout of an input\n"
206 "\tindex (int): Index of input to be set (0-indexed)\n"
207 "\tlayout (str): Layout to set to target input")
209 py::arg(
"layout") =
"NONE",
210 "Set the layout of an output\n"
212 "\tindex (int): Index of output to be set (0-indexed)\n"
213 "\tlayout (str): Layout to set to target output")
215 "Get i-th input tensor info\n"
217 "\tindex (int): Index of input\n"
219 "\ttensorinfo: Tensor info (shape, type, etc)")
221 "Get i-th output tensor info\n"
223 "\tindex (int): Index of output\n"
225 "\ttensorinfo: Tensor info (shape, type, etc)");
232 m.attr(
"nnfw_session")
233 .cast<py::class_<NNFW_SESSION>>()
235 "Retrieve training information for the model.")
237 "Set training information for the model.")
240 "Run a training step, optionally updating weights.")
242 "Retrieve the training loss for a specific index.")
243 .def(
"train_set_input", &NNFW_SESSION::train_set_input<float>, py::arg(
"index"),
244 py::arg(
"buffer"),
"Set training input tensor for the given index (float).")
245 .def(
"train_set_input", &NNFW_SESSION::train_set_input<int>, py::arg(
"index"),
246 py::arg(
"buffer"),
"Set training input tensor for the given index (int).")
247 .def(
"train_set_input", &NNFW_SESSION::train_set_input<uint8_t>, py::arg(
"index"),
248 py::arg(
"buffer"),
"Set training input tensor for the given index (uint8).")
249 .def(
"train_set_expected", &NNFW_SESSION::train_set_expected<float>, py::arg(
"index"),
250 py::arg(
"buffer"),
"Set expected output tensor for the given index (float).")
251 .def(
"train_set_expected", &NNFW_SESSION::train_set_expected<int>, py::arg(
"index"),
252 py::arg(
"buffer"),
"Set expected output tensor for the given index (int).")
253 .def(
"train_set_expected", &NNFW_SESSION::train_set_expected<uint8_t>, py::arg(
"index"),
254 py::arg(
"buffer"),
"Set expected output tensor for the given index (uint8).")
255 .def(
"train_set_output", &NNFW_SESSION::train_set_output<float>, py::arg(
"index"),
256 py::arg(
"buffer"),
"Set output tensor for the given index (float).")
257 .def(
"train_set_output", &NNFW_SESSION::train_set_output<int>, py::arg(
"index"),
258 py::arg(
"buffer"),
"Set output tensor for the given index (int).")
259 .def(
"train_set_output", &NNFW_SESSION::train_set_output<uint8_t>, py::arg(
"index"),
260 py::arg(
"buffer"),
"Set output tensor for the given index (uint8).")
262 "Export the trained model to a circle file.")
264 "Import a training checkpoint from a file.")
266 "Export the training checkpoint to a file.");