app打包公司有哪些,甘肃网站建设方案优化,优设网页官网,国产服务器前三强此教程为目前全网为数不多用于使用STM32实时跑神经网络结果输出的教程#xff0c;不涉及原理讲解#xff0c;只为帮助想在stm32上使用神经网络的朋友
基本步骤为先跑出神经网络得到xxx.h5文件#xff0c;然后用cubemx把h5文件移植到stm32中#xff0c;然后初始化设置输入输…此教程为目前全网为数不多用于使用STM32实时跑神经网络结果输出的教程不涉及原理讲解只为帮助想在stm32上使用神经网络的朋友
基本步骤为先跑出神经网络得到xxx.h5文件然后用cubemx把h5文件移植到stm32中然后初始化设置输入输出实时输入数据进行神经网络检测需要做的工作主要有会写或者会改神经网络代码输出.h5文件使用Tesoroflow产生得有版本要求太高得可能不行使用cubemx来移植到stm32上初始化输入输出来使之能把数据输入到神经网络进行运算。
1、 自行上网查询stm32AI教程网上90%的教程会教到能把官方例程跑出来使用cubemx进行验证跑不出来检查步骤有无错误时钟设置是否正确串口设置是否正确 2、 但如果想实时跑数据进行神经网络检测在Cubemx上能验证是没有用的需要在代码中设置输入输出。 3、 根据我给得输入输出初始化函数来进行初始化自己得输入输出参数然后进行验证。 使用STM32跑神经网络需要的初始化代码
static void AI_Run(float* pIn, float* pOut) //神经网络实时计算代码填入输入输出数组即可
{ai_i32 batch;ai_error err;/* 1 - Create the AI buffer IO handlers with the default definition */ai_buffer ai_input[AI_NETWORK_IN_NUM] AI_NETWORK_IN;ai_buffer ai_output[AI_NETWORK_OUT_NUM] AI_NETWORK_OUT;/* 2 - Update IO handlers with the data payload */ai_input[0].n_batches 1;ai_input[0].data AI_HANDLE_PTR(pIn);ai_output[0].n_batches 1;ai_output[0].data AI_HANDLE_PTR(pOut);batch ai_network_run(network, ai_input, ai_output);if (batch ! 1) {err ai_network_get_error(network);printf(AI ai_network_run error - type%d code%d\r\n, err.type, err.code);
// Error_Handler();}
}static void AI_Init(ai_handle w_addr, ai_handle act_addr) //初始化代码
{ai_error err;printf(AI_NETWORK_IN_NUM%d AI_NETWORK_OUT_NUM%d\r\n, AI_NETWORK_IN_NUM, AI_NETWORK_OUT_NUM);/* 1 - Create an instance of the model */err ai_network_create(network, AI_NETWORK_DATA_CONFIG);if (err.type ! AI_ERROR_NONE) {printf(ai_network_create error - type%d code%d\r\n, err.type, err.code);
// Error_Handler();}/* 2 - Initialize the instance */const ai_network_params params AI_NETWORK_PARAMS_INIT(AI_NETWORK_DATA_WEIGHTS(w_addr),AI_NETWORK_DATA_ACTIVATIONS(act_addr));if (!ai_network_init(network, params)) {err ai_network_get_error(network);printf(ai_network_init error - type%d code%d\r\n, err.type, err.code);
// Error_Handler();}
}給出一个可参考的伪代码(参考使用方式以下代码无法直接跑只是示意)实例 #include sys.h
#include delay.h/*bsp*/
#include usart.h
#include led.h
#include key.h
#include timer.h
#include adc.h
#include arc_de.h
#include main.h
#include crc.h
#include usart.h
#include gpio.h
#include app_x-cube-ai.h/*宏定义*//**********************全局变量****************************/
float team_data[3] { 0 };
float Arc_data[DATASIZE][3] { 0 }, FFt_Out[DATASIZE / 2] { 0 }, minValue 3, maxValue 0, F_maxValue 0, FFt_Out1[DATASIZE / 2] { 0 }, Freqy 0;
u16 adcx, i 0;
u16 n 0, m 0;
float F_rate[3] { 0 };
/* Reference index at which max energy of bin ocuurs */
uint32_t Index 0;struct arc_eigenvalue arc_eig;
ai_handle network AI_HANDLE_NULL;
/**********************函数申明****************************/
static void AI_Init(ai_handle w_addr, ai_handle act_addr);
static void AI_Run(float* pIn, float* pOut);void hard_init(void)
{}
int main(void)
{arm_rfft_fast_instance_f32 S;float aiInData[row][AI_NETWORK_IN_1_SIZE] {};float aiOutData[AI_NETWORK_OUT_1_SIZE];ai_u8 activations[AI_NETWORK_DATA_ACTIVATIONS_SIZE];hard_init();
//初始化AIMX_CRC_Init();MX_X_CUBE_AI_Init();AI_Init(ai_network_data_weights_get(), activations);delay_ms(1);while (1){ AI_Run(aiInData[i], aiOutData);//实时运行}}#ifdef USE_FULL_ASSERTstatic void AI_Run(float* pIn, float* pOut)
{ai_i32 batch;ai_error err;/* 1 - Create the AI buffer IO handlers with the default definition */ai_buffer ai_input[AI_NETWORK_IN_NUM] AI_NETWORK_IN;ai_buffer ai_output[AI_NETWORK_OUT_NUM] AI_NETWORK_OUT;/* 2 - Update IO handlers with the data payload */ai_input[0].n_batches 1;ai_input[0].data AI_HANDLE_PTR(pIn);ai_output[0].n_batches 1;ai_output[0].data AI_HANDLE_PTR(pOut);batch ai_network_run(network, ai_input, ai_output);if (batch ! 1) {err ai_network_get_error(network);printf(AI ai_network_run error - type%d code%d\r\n, err.type, err.code);}
}static void AI_Init(ai_handle w_addr, ai_handle act_addr)
{ai_error err;printf(AI_NETWORK_IN_NUM%d AI_NETWORK_OUT_NUM%d\r\n, AI_NETWORK_IN_NUM, AI_NETWORK_OUT_NUM);/* 1 - Create an instance of the model */err ai_network_create(network, AI_NETWORK_DATA_CONFIG);if (err.type ! AI_ERROR_NONE) {printf(ai_network_create error - type%d code%d\r\n, err.type, err.code);}/* 2 - Initialize the instance */const ai_network_params params AI_NETWORK_PARAMS_INIT(AI_NETWORK_DATA_WEIGHTS(w_addr),AI_NETWORK_DATA_ACTIVATIONS(act_addr));if (!ai_network_init(network, params)) {err ai_network_get_error(network);printf(ai_network_init error - type%d code%d\r\n, err.type, err.code);}
}