Skip to content

Commit

Permalink
example code use nnfw_xxx
Browse files Browse the repository at this point in the history
  • Loading branch information
chunseoklee authored Jun 4, 2024
1 parent 4c4e0c7 commit f5fb6a7
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions onert-micro/onert-micro/include/onert-micro.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ extern "C" {
// sample example
// 0. create context
om_context *ctx;
om_create_context(&ctx);
nnfw_session *session;
nnfw_create_session(&session);
// 1. load model
om_load_model_from_file(ctx, MODEL_PATH);
// 1. load model (and checkpoint if continue training)
nnfw_load_model_from_file(session, MODEL_PATH);
// 1-1. (optional, TBD) configure training options
nnfw_load_ckpt_from_file(session, CKPT_PATH);
om_train_compile(ctx);
nnfw_train_prepare(session);
float training_input[BATCH_SIZE*INPUT_SIZE];
float training_label[BATCH_SIZE*OUTPUT_SIZE];
Expand All @@ -58,21 +59,21 @@ for(int epoch=0; epoch < NUM_EPOCHS; epoch++) {
memcpy(training_input, train_input_data + THIS_BATCH_OFFSET, BATCH_SIZE*INPUT_SIZE);
memcpy(training_output, train_output_data + THIS_BATCH_OFFSET, BATCH_SIZE*OUTPUT_SIZE);
// 2. feed training input / output
om_train_set_input(ctx, 0 , training_input, BATCH_SIZE*INPUT_SIZE);
om_train_set_expected(ctx, 0 , training_input,BATCH_SIZE*INPUT_SIZE);
// 2. feed training input / expected output
nnfw_train_set_input(session, 0 , training_input, NULL);
nnfw_train_set_expected(session, 0 , training_input, NULL);
// 3. train a step
om_train_single_step(ctx);
nnfw_train(session);
}
// 4. check loss
float loss;
om_train_get_loss(ctx, 0, &loss);
nnfw_train_get_loss(ctx, 0, &loss);
if(loss > TARGET_LOSS) {
om_train_save_as_checkpoint(ctx, PATH);
nnfw_train_save_as_checkpoint(ctx, CKPT_PATH);
}
else {
om_train_save_as_inferencemodel(ctx, PATH);
nnfw_train_export_circle(ctx, CIRCLE_PATH);
}
}
*/
Expand Down

0 comments on commit f5fb6a7

Please sign in to comment.