diff --git a/docs/api_evaluation.md b/docs/api_evaluation.md index cc6ecd8..a8bddb2 100644 --- a/docs/api_evaluation.md +++ b/docs/api_evaluation.md @@ -52,19 +52,21 @@ Total Memory cost (Network and NNoM): 32876 --- -## nnom_predic_one() +## nnom_predic() ~~~C -int32_t nnom_predic_one(nnom_model_t *m); +int32_t nnom_predic(nnom_model_t *m, uint32_t *label, float *prob); ~~~ -To predict one set of input data. This is the standalone API which does not require `printf()` to print results but only return the predicted label. +A standalone evaluation method, run single prodiction, return probability and top-1 label. This method is basicly `model_run()` + `index(top-1)` **Arguments** - **m:** the model to run prediction (evaluation). +- **label:** the variable to store top-1 label. +- **prob:** the variable to store probability. Range from 0~1. **Return** diff --git a/docs/example_mnist_simple_cn.md b/docs/example_mnist_simple_cn.md index 83df17a..0e818db 100644 --- a/docs/example_mnist_simple_cn.md +++ b/docs/example_mnist_simple_cn.md @@ -123,6 +123,8 @@ prediction start.. Time: 62 tick Truth label: 8 Predicted label: 8 +Probability: 100% + ~~~ 额,如果恶心到你了,那我道歉... @@ -134,6 +136,7 @@ Predicted label: 8 - 此次预测的时间,这里用了 `62 tick`,我这是相当于 62ms - 这张图片的真实数字是 `8` - 网络计算的这张照片的数字 `8` +- 可能性是100% 赶快去试试,其他的 9 张图片吧。 diff --git a/docs/index.md b/docs/index.md index 133276b..4182a02 100644 --- a/docs/index.md +++ b/docs/index.md @@ -38,9 +38,15 @@ Nowadays, neural networks are **wider**, **deeper**, and **denser**. >[3] Huang, G., Liu, Z., Van Der Maaten, L., & Weinberger, K. Q. (2017). Densely connected convolutional networks. In Proceedings of the IEEE conference on computer vision and pattern recognition (pp. 4700-4708). -**If you would like to try those more up-to-date, decent and complex structures on MCU** +After 2014, the development of Neural Networks are more focus on structure optimising to improve efficiency and performance, which is more important to the small footprint platforms such as MCUs. +However, the available NN libs for MCU are too low-level which make it sooooo difficult to use with these complex strucures. +Therefore, we build NNoM to help developers to manage the structures, memory and parameters, even with the automatic tools for faster and simpler deploying. -**NNoM can help you to build them with only a few lines of C codes**, same as you did with Python in [**Keras**](https://keras.io/) +Now with NNoM, you are free to play with these more up-to-date, decent and complex structures on MCU. + +With [**Keras**](https://keras.io/) and our tools, deploying a model only takes a few line of codes. + +Please do check the [examples](https://github.com/majianjia/nnom/tree/master/examples). --- diff --git a/examples/mnist-simple/mcu/main.c b/examples/mnist-simple/mcu/main.c index 714855c..24b55f9 100644 --- a/examples/mnist-simple/mcu/main.c +++ b/examples/mnist-simple/mcu/main.c @@ -53,7 +53,8 @@ void print_img(int8_t * buf) void mnist(int argc, char** argv) { uint32_t tick, time; - int32_t result; + uint32_t predic_label; + float prob; int32_t index = atoi(argv[1]); if(index >= TOTAL_IMAGE || argc != 2) @@ -67,7 +68,7 @@ void mnist(int argc, char** argv) // copy data and do prediction memcpy(nnom_input_data, (int8_t*)&img[index][0], 784); - result = nnom_predic_one(model); + nnom_predic(model, &predic_label, &prob); time = rt_tick_get() - tick; //print original image to console @@ -75,7 +76,8 @@ void mnist(int argc, char** argv) printf("Time: %d tick\n", time); printf("Truth label: %d\n", label[index]); - printf("Predicted label: %d\n", result); + printf("Predicted label: %d\n", predic_label); + printf("Probability: %d%%\n", (int)(prob*100)); } FINSH_FUNCTION_EXPORT(mnist, mnist(4) ); diff --git a/inc/nnom_utils.h b/inc/nnom_utils.h index 433a806..61a443d 100644 --- a/inc/nnom_utils.h +++ b/inc/nnom_utils.h @@ -73,7 +73,7 @@ void prediction_summary(nnom_predic_t *pre); // this api test one set of data, return the prediction // return the predicted label // return NN_ARGUMENT_ERROR if parameter error -int32_t nnom_predic_one(nnom_model_t *m); +nnom_status_t nnom_predic(nnom_model_t *m, uint32_t *label, float *prob); void model_stat(nnom_model_t *m); diff --git a/mkdocs.yml b/mkdocs.yml index e864979..cb61439 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -13,8 +13,8 @@ nav: - Merges: 'api_merge.md' - Evaluation: 'api_evaluation.md' - Legacy Guide: - - A Temporary Guide: 'A Temporary Guide to NNoM.md' - - Porting and Optimisation Guide: 'Porting and Optimisation Guide.md' + - A Temporary Guide: 'A_Temporary_Guide_to_NNoM.md' + - Porting and Optimisation Guide: 'Porting_and_Optimisation_Guide.md' - Old Readme: 'legacy_README.md' - 中文: - RT-Thread: 'rt-thread_guide.md' diff --git a/src/nnom_utils.c b/src/nnom_utils.c index 8ebe112..c5d8157 100644 --- a/src/nnom_utils.c +++ b/src/nnom_utils.c @@ -223,9 +223,9 @@ void prediction_summary(nnom_predic_t *pre) // stand alone prediction API // this api test one set of data, return the prediction -int32_t nnom_predic_one(nnom_model_t *m) +nnom_status_t nnom_predic(nnom_model_t *m, uint32_t *label, float *prob) { - int32_t max_val, max_index; + int32_t max_val, max_index, sum; int8_t *output; if (!m) @@ -239,6 +239,7 @@ int32_t nnom_predic_one(nnom_model_t *m) // Top 1 max_val = output[0]; max_index = 0; + sum = max_val; for (uint32_t i = 1; i < shape_size(&m->tail->out->shape); i++) { if (output[i] > max_val) @@ -246,8 +247,13 @@ int32_t nnom_predic_one(nnom_model_t *m) max_val = output[i]; max_index = i; } + sum += output[i]; } - return max_index; + // send results + *label = max_index; + *prob = (float)max_val/(float)sum; + + return NN_SUCCESS; } static void layer_stat(nnom_layer_t *layer)