Modify to adapt to the new version nncase and SDK
parent
b1e680f1a0
commit
2c8db47408
|
@ -4,22 +4,24 @@ Make a directory named `ncc`. Download [nncase](<https://github.com/kendryte/nnc
|
||||||
|
|
||||||
#### *pb* file to tflite
|
#### *pb* file to tflite
|
||||||
|
|
||||||
Copy the pretrained model `mobilenetv1_1.0.pb` in `pretrained` directory to `ncc\bin`.
|
Copy the pretrained model `mobilenetv1_1.0.pb` in `pretrained` directory to `ncc/bin`.
|
||||||
|
|
||||||
Enter `ncc\bin` directory.
|
Enter `ncc/bin` directory.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
./toco --input_file=mobilenetv1_1.0.pb --input_format=TENSORFLOW_GRAPHDEF --output_file=mobilenetv1_1.0.tflite --output_format=TFLITE --input_shape=1,224,224,3 --input_array=inputs --output_array=MobileNetV1/Bottleneck2/BatchNorm/Reshape_1 --inference=FLOAT
|
toco --graph_def_file=mobilenetv1_1.0.pb --output_file=mobilenetv1_1.0.tflite --output_format=TFLITE --input_shape=1,224,224,3 --input_arrays=inputs --output_arrays=MobileNetV1/Bottleneck2/BatchNorm/Reshape_1 --inference_type=FLOAT
|
||||||
```
|
```
|
||||||
|
|
||||||
#### tflite to kmodel
|
#### tflite to kmodel
|
||||||
|
|
||||||
Enter `ncc` directory and place the dataset into `ncc\dataset` directory.
|
Enter `ncc` directory and place a few pictures of your dataset into `ncc/dataset` directory.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
./ncc -i tflite -o k210model --dataset ./dataset ./bin/mobilenetv1_1.0.tflite ./bin/mobilenetv1_1.0.kmodel
|
./ncc compile ./bin/mobilenetv1_1.0.tflite ./bin/mobilenetv1_1.0.kmodel -i tflite -o kmodel --dataset ./dataset/
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Note**: Pictures in `ncc/dataset` are used for quantization. They should cover all classes of your dataset.
|
||||||
|
|
||||||
### Prepare image for test
|
### Prepare image for test
|
||||||
|
|
||||||
Convert an image, for example `eagle.jpg`, to a C file.
|
Convert an image, for example `eagle.jpg`, to a C file.
|
||||||
|
@ -39,6 +41,7 @@ with open('image.c','w') as f:
|
||||||
|
|
||||||
### Test
|
### Test
|
||||||
|
|
||||||
Copy the `K210code` directory to `kendryte-standalone-sdk\src`. Build and download to KD233 to check the results.
|
Copy the `K210code` directory to `kendryte-standalone-sdk/src`. Build and download to KD233 to check the results.
|
||||||
|
|
||||||
|
**Note**: `develop` branch of `kendryte-standalone-sdk` is required.
|
||||||
|
|
||||||
**Note**: `develop` branch of `kendryte-standalone-sdk` is required.
|
|
|
@ -14,15 +14,18 @@
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sysctl.h>
|
#include <sysctl.h>
|
||||||
|
#include <string.h>
|
||||||
#include "uarths.h"
|
#include "uarths.h"
|
||||||
#include "kpu.h"
|
#include "kpu.h"
|
||||||
#include "incbin.h"
|
#include "incbin.h"
|
||||||
|
#include "iomem.h"
|
||||||
|
#include "syscalls.h"
|
||||||
|
|
||||||
#define INCBIN_STYLE INCBIN_STYLE_SNAKE
|
#define INCBIN_STYLE INCBIN_STYLE_SNAKE
|
||||||
#define INCBIN_PREFIX
|
#define INCBIN_PREFIX
|
||||||
|
|
||||||
#define PLL0_OUTPUT_FREQ 800000000UL
|
#define PLL0_OUTPUT_FREQ 800000000UL
|
||||||
#define PLL1_OUTPUT_FREQ 300000000UL
|
#define PLL1_OUTPUT_FREQ 400000000UL
|
||||||
|
|
||||||
INCBIN(model, "mobilenetv1_1.0.kmodel");
|
INCBIN(model, "mobilenetv1_1.0.kmodel");
|
||||||
|
|
||||||
|
@ -32,6 +35,9 @@ volatile uint32_t g_ai_done_flag;
|
||||||
|
|
||||||
extern const unsigned char gImage_image[] __attribute__((aligned(128)));
|
extern const unsigned char gImage_image[] __attribute__((aligned(128)));
|
||||||
|
|
||||||
|
#define IMAGE_DATA_SIZE (224 * 224 * 3)
|
||||||
|
uint8_t *pImage;
|
||||||
|
|
||||||
static int ai_done(void *ctx)
|
static int ai_done(void *ctx)
|
||||||
{
|
{
|
||||||
g_ai_done_flag = 1;
|
g_ai_done_flag = 1;
|
||||||
|
@ -48,9 +54,20 @@ int main()
|
||||||
uarths_init();
|
uarths_init();
|
||||||
plic_init();
|
plic_init();
|
||||||
|
|
||||||
|
pImage = (uint8_t*)iomem_malloc(IMAGE_DATA_SIZE);
|
||||||
|
if (pImage)
|
||||||
|
{
|
||||||
|
memcpy(pImage, gImage_image, IMAGE_DATA_SIZE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Bad allocation!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (kpu_load_kmodel(&task, model_data) != 0)
|
if (kpu_load_kmodel(&task, model_data) != 0)
|
||||||
{
|
{
|
||||||
printf("\nmodel init error\n");
|
printf("\nmodel init error\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +75,7 @@ int main()
|
||||||
|
|
||||||
printf("System Start\n");
|
printf("System Start\n");
|
||||||
g_ai_done_flag = 0;
|
g_ai_done_flag = 0;
|
||||||
kpu_run_kmodel(&task, gImage_image, DMAC_CHANNEL5, ai_done, NULL);
|
kpu_run_kmodel(&task, pImage, DMAC_CHANNEL5, ai_done, NULL);
|
||||||
while (g_ai_done_flag == 0);
|
while (g_ai_done_flag == 0);
|
||||||
float *output;
|
float *output;
|
||||||
size_t output_size;
|
size_t output_size;
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue