Files
ESPDocs/public/exemplos/zh-CN/esp-nn.c
T
Lucas RayanandClaude Sonnet 5.5 5a9fe676fc
CI / Lint e auditorias (push) Successful in 1m10s
CI / Trivy (dependências e segredos) (push) Successful in 12s
CI / Imagem Docker (linux/arm64) (push) Successful in 2m39s
Release / Plano (reaproveitar a imagem?) (push) Successful in 6s
Release / ci (push) Skipped
Release / Publica a imagem (linux/arm64) (push) Successful in 18s
Release / Cria a release no Gitea (push) Successful in 5s
feat(i18n): Simplified Chinese (zh-CN), search answers per locale, fr/de/es data fixes
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-01 23:28:39 -03:00

45 lines
1.0 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <stdio.h>
#include "esp_nn.h"
#include "esp_nn_defs.h"
#define INPUT_SIZE 4
#define OUTPUT_SIZE 3
void print_array(const char *label, int16_t *array, int size) {
printf("%s: ", label);
for (int i = 0; i < size; i++) {
printf("%d ", array[i]);
}
printf("\n");
}
void app_main(void)
{
// 输入向量(例如上一层的输出)
int16_t input[INPUT_SIZE] = {1, 2, 3, 4};
// 全连接层权重(3x4)
int8_t weights[OUTPUT_SIZE * INPUT_SIZE] = {
1, -1, 2, 0,
0, 1, -1, 1,
2, 0, 1, -2
};
// 每个神经元的偏置
int16_t bias[OUTPUT_SIZE] = {10, -5, 0};
// 输出
int16_t output[OUTPUT_SIZE];
// 矩阵乘法:output = weights * input + bias
esp_nn_mul_mat_16x8_16(weights, input, bias, output,
OUTPUT_SIZE, INPUT_SIZE, /*shift=*/0);
print_array("Before ReLU", output, OUTPUT_SIZE);
// 应用 ReLU 激活函数
esp_nn_relu_16(output, OUTPUT_SIZE);
print_array("After ReLU", output, OUTPUT_SIZE);
}