ONE - On-device Neural Engine
|
#include <string>
#include <memory>
#include <thread>
#include <vector>
#include <iostream>
#include <fstream>
#include "OMTrainingInterpreter.h"
#include "onert-micro.h"
#include <circle-generated/circle/schema_generated.h>
#include <circle-generated/circle/traininfo_generated.h>
Go to the source code of this file.
Data Structures | |
struct | nnfw_session |
Macros | |
#define | NNFW_RETURN_ERROR_IF_NULL(p) |
Typedefs | |
using | DataBuffer = std::vector< char > |
Functions | |
DataBuffer | readFile (const char *path) |
NNFW_STATUS | nnfw_create_session (nnfw_session **session) |
Create a new session instance. | |
NNFW_STATUS | nnfw_load_model_from_file (nnfw_session *session, const char *package_file_path) |
Load model from nnpackage file or directory. | |
NNFW_STATUS | nnfw_train_prepare (nnfw_session *session) |
Prepare session to be ready for training. | |
NNFW_STATUS | nnfw_train (nnfw_session *session, bool update_weights) |
Train the model. | |
NNFW_STATUS | nnfw_train_export_circle (nnfw_session *session, const char *path) |
Export current training model into circle model. | |
NNFW_STATUS | nnfw_train_export_checkpoint (nnfw_session *session, const char *path) |
Export circle checkpoint. | |
NNFW_STATUS | nnfw_train_import_checkpoint (nnfw_session *session, const char *path) |
Import circle checkpoint. | |
NNFW_STATUS | nnfw_train_set_input (nnfw_session *session, uint32_t index, void *input, const nnfw_tensorinfo *input_info) |
Set training input. | |
NNFW_STATUS | nnfw_train_set_expected (nnfw_session *session, uint32_t index, void *expected, const nnfw_tensorinfo *expected_info) |
Set training expected output. | |
NNFW_STATUS | nnfw_train_get_loss (nnfw_session *session, uint32_t index, float *loss) |
Get loss value for expected output. | |
NNFW_STATUS | nnfw_train_set_traininfo (nnfw_session *session, const nnfw_train_info *info) |
Set training information. | |
NNFW_STATUS | nnfw_train_set_output (nnfw_session *session, uint32_t index, NNFW_TYPE type, void *buffer, size_t length) |
Set training output buffer. | |
#define NNFW_RETURN_ERROR_IF_NULL | ( | p | ) |
Definition at line 29 of file onert-micro.cpp.
using DataBuffer = std::vector<char> |
Definition at line 37 of file onert-micro.cpp.
NNFW_STATUS nnfw_create_session | ( | nnfw_session ** | session | ) |
Create a new session instance.
This only creates a session. Model is loaded after nnfw_load_model_from_file
is invoked. And inference is performed after nnfw_run
is invoked.
nnfw_close_session
should be called once if session is no longer needed
[out] | session | The session to be created |
Definition at line 390 of file onert-micro.cpp.
NNFW_STATUS nnfw_load_model_from_file | ( | nnfw_session * | session, |
const char * | package_file_path | ||
) |
Load model from nnpackage file or directory.
Load model from path to model or nnpackage.
The length of package_file_path
must not exceed 1024 bytes including zero at the end.
[in] | session | nnfw_session loading the given nnpackage file/dir |
[in] | package_file_path | Path to the nnpackage file or unzipped directory to be loaded |
NNFW_STATUS_NO_ERROR
if successful Definition at line 392 of file onert-micro.cpp.
NNFW_STATUS nnfw_train | ( | nnfw_session * | session, |
bool | update_weights | ||
) |
Train the model.
nnfw_train_set_input
and nnfw_train_set_expected
for each input and expected outputIn order to use update_weights
as false, it should be called after nnfw_train_set_output
.
[in] | session | The session to be trained |
[in] | update_weights | If true, update weights of the model If false, do not update weights of the model (for validation) |
NNFW_STATUS_NO_ERROR
if successful Definition at line 399 of file onert-micro.cpp.
NNFW_STATUS nnfw_train_export_checkpoint | ( | nnfw_session * | session, |
const char * | path | ||
) |
Export circle checkpoint.
nnfw_train
[in] | session | The session to export a checkpoint |
[in] | path | The path to export a checkpoint |
NNFW_STATUS_NO_ERROR
if successful Definition at line 409 of file onert-micro.cpp.
NNFW_STATUS nnfw_train_export_circle | ( | nnfw_session * | session, |
const char * | path | ||
) |
Export current training model into circle model.
Export circle model.
nnfw_train
[in] | session | The session to export inference model |
[in] | path | The path to export inference model |
NNFW_STATUS_NO_ERROR
if successful Definition at line 404 of file onert-micro.cpp.
NNFW_STATUS nnfw_train_get_loss | ( | nnfw_session * | session, |
uint32_t | index, | ||
float * | loss | ||
) |
Get loss value for expected output.
nnfw_train
[in] | session | The session to get loss value |
[in] | index | The index of loss value [0, number of expected outputs) |
[out] | loss | The loss value |
NNFW_STATUS_NO_ERROR
if successful Definition at line 433 of file onert-micro.cpp.
NNFW_STATUS nnfw_train_import_checkpoint | ( | nnfw_session * | session, |
const char * | path | ||
) |
Import circle checkpoint.
nnfw_train
[in] | session | The session to export a checkpoint |
[in] | path | The path to export a checkpoint |
NNFW_STATUS_NO_ERROR
if successful Definition at line 414 of file onert-micro.cpp.
NNFW_STATUS nnfw_train_prepare | ( | nnfw_session * | session | ) |
Prepare session to be ready for training.
If training info is NOT set in session, this function returns @c NNFW_STATUS_ERROR . You should set training info using {@link nnfw_train_set_traininfo}.
[in] | session | The session to be prepared for training |
NNFW_STATUS_NO_ERROR
if successful Definition at line 397 of file onert-micro.cpp.
NNFW_STATUS nnfw_train_set_expected | ( | nnfw_session * | session, |
uint32_t | index, | ||
void * | expected, | ||
const nnfw_tensorinfo * | expected_info | ||
) |
Set training expected output.
nnfw_train_prepare
session | The session to be set training inputs and expected model outputs |
index | The index of training expected output |
expected | The expected buffers for training |
expected_info | The shape and type of expected buffer If it is nullptr, it will not change shape and batch size |
NNFW_STATUS_NO_ERROR
if successful Definition at line 426 of file onert-micro.cpp.
References NNFW_RETURN_ERROR_IF_NULL.
NNFW_STATUS nnfw_train_set_input | ( | nnfw_session * | session, |
uint32_t | index, | ||
void * | input, | ||
const nnfw_tensorinfo * | input_info | ||
) |
Set training input.
nnfw_train_prepare
[in] | session | The session to be set training inputs and expected model outputs |
[in] | index | The index of training input |
[in] | input | The input buffers for training |
[in] | input_info | The shape and type of input buffer If it is nullptr, it will not change shape and batch size |
NNFW_STATUS_NO_ERROR
if successful Definition at line 419 of file onert-micro.cpp.
References NNFW_RETURN_ERROR_IF_NULL.
NNFW_STATUS nnfw_train_set_output | ( | nnfw_session * | session, |
uint32_t | index, | ||
NNFW_TYPE | type, | ||
void * | buffer, | ||
size_t | length | ||
) |
Set training output buffer.
This function must be called after nnfw_train_prepare
, buffer
given to this function can be reused for training. length
must be greater or equal than the operand requires. An output operand can have unspecified shape and deduced dynamically during the execution. You must provide buffer
large enough.
[in] | session | Session from inference output is to be extracted |
[in] | index | Index of output to be set (0-indexed) |
[in] | type | Type of the output |
[out] | buffer | Raw buffer for output |
[in] | length | Size of bytes of output buffer |
NNFW_STATUS_NO_ERROR
if successful Definition at line 445 of file onert-micro.cpp.
NNFW_STATUS nnfw_train_set_traininfo | ( | nnfw_session * | session, |
const nnfw_train_info * | info | ||
) |
Set training information.
nnfw_load_model_from_file
and before calling nnfw_train_prepare
[in] | session | The session to be set training information |
[in] | info | The training information |
NNFW_STATUS_NO_ERROR
if successful Definition at line 439 of file onert-micro.cpp.
DataBuffer readFile | ( | const char * | path | ) |
Definition at line 39 of file onert-micro.cpp.
Referenced by entry(), and nnfw_session::load_model_from_file().