Skip to content

esp_nn_conv_s8_esp32s3 returns unespected values #23

@gabrieldcgms-png

Description

@gabrieldcgms-png

Checklist

  • Checked the issue tracker for similar issues to ensure this is not a duplicate
  • Read the documentation to confirm the issue is not addressed there and your configuration is set correctly
  • Tested with the latest version to ensure the issue hasn't been fixed

How often does this bug occurs?

always

Expected behavior

The esp-nn optimized convolution functions are producing incorrect outputs, leading to a significant drop in model accuracy from 92% to below 70%. When using the standard ANSI C implementation, the model performs as expected.
When running the CNN model with esp-nn optimizations enabled, the model should maintain an accuracy similar to the standard C implementation (around 92%). The convolution layers' outputs should be a range of values, not predominantly clamped to -128.

Actual behavior (suspected bug)

Enable esp-nn optimizations. Run the model again. Observe that the accuracy drops significantly, typically below 70%.
Use debugging tools (like printf statements) within the esp_nn_conv_s8_filter_aligned_input_padded_esp32s3 function to inspect the output data. Confirm that the out_data array contains many instances of the value -128.
The attached debug logs show the out_data of multiple convolution layers, consistently containing -128 values, indicating a saturation or clamping issue.
When esp-nn optimization is toggled on, the model's accuracy drops below 70%. Debugging the optimized esp_nn_conv_s8_filter_aligned_input_padded_esp32s3 function shows that the output (out_data) of the convolution operation is filled with an excessive number of -128 values.
This clamping of values suggests a potential issue in the quantization parameters or the implementation of the optimized convolution kernel, causing the output to consistently hit the lowest possible value for an 8-bit signed integer.

Error logs or terminal output

Log Snippets:

--- DEBUG: Funcao otimizada executada! Verificando a saida ---
  Primeiros 32 bytes de out_data:
-128 -128 -128 -128 -128 -116 -128 -119 -128 -128 -113 -127 -116 -125 -128 -128 -118 -120 -128 -123 -124 -128 -128 -128 -128 -121 -123 -127 -121 -128 -128 -128
This is the output for the first convolution layer, where many values are already -128.

--- DEBUG: Funcao otimizada executada! Verificando a saida ---
  Primeiros 32 bytes de out_data:
-128 -128 -128 -128 -128 -128 -97 -128 -128 -124 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128 -114 -128 -128 -128 -128 -120 -128 -94 -128 -128 -128
This is the output for the second convolution layer, which also shows widespread -128 values.

--- DEBUG: Funcao otimizada executada! Verificando a saida ---
  Primeiros 32 bytes de out_data:
-128 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128 -126 -128 -128 -128 -128 -128 -128 -128 -123 -128 -128 -128 -128 -128 -128 -128
This is the output for the third convolution layer, where almost all values are -128.

The input offset and output offset values from the esp_nn function calls are shown to be -17 and -128, respectively. These values might be contributing to the problem.

Steps to reproduce the behavior

Configure a CNN model with the following architecture:

conv2d_46 (Conv2D)

max_pooling2d_46 (MaxPooling2D)

conv2d_47 (Conv2D)

max_pooling2d_47 (MaxPooling2D)

conv2d_48 (Conv2D)

max_pooling2d_48 (MaxPooling2D)

dropout_30 (Dropout)

flatten_15 (Flatten)

dropout_31 (Dropout)

dense_17 (Dense)

Run the model with esp-nn optimizations disabled. Observe that the model achieves an accuracy of approximately 92%.

Enable esp-nn optimizations. Run the model again. Observe that the accuracy drops significantly, typically below 70%.

Use debugging tools (like printf statements) within the esp_nn_conv_s8_filter_aligned_input_padded_esp32s3 function to inspect the output data. Confirm that the out_data array contains many instances of the value -128.

Project release version

Lastest

System architecture

other (details in Additional context)

Operating system

Windows

Operating system version

Windows 11

Shell

PowerShell

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions