Average Pool error cannot quantize

Hey @oscar.mendez


It seems that the error is related to quantization, particularly with the average pooling layer. Here are a few potential solutions to address this:

  1. Use the global_avgpool_reduction Command:
    The error message suggests applying a pre-quantization optimization to reduce the spatial dimensions of the global average pooling layer. You can include the following command in your model script:

    pre_quantization_optimization(global_avgpool_reduction, layers=avgpool1, division_factors=[4, 4])
    

    This command reduces the height and width of the global average pooling layer by a factor of 4. You can adjust the division_factors as needed.

  2. Adjust Optimization Level:
    Since you’re running the process without a GPU, the optimization level defaults to 0. If possible, try using a machine with a GPU to enable higher optimization levels. Alternatively, you can manually set a higher optimization level by using:

    model_optimization_flavor(optimization_level=2)
    
  3. Use 16-bit Precision:
    If the problem persists, consider setting the problematic layer to use 16-bit precision with the following command:

    quantization_param(avgpool1, precision_mode=a16_w16)
    
  4. Modify the Model Architecture:
    If the above solutions don’t resolve the issue, you might need to adjust the model architecture. One option is to replace the global average pooling layer with a standard average pooling layer that uses a large kernel size, followed by a flatten operation.

  5. Expand the Calibration Dataset:
    Consider increasing the size of your calibration dataset. Instead of random data, use a representative set of real images that reflect your expected input distribution.

To apply these solutions, create a model script file (e.g., rtmdet_script.alls) with your chosen commands, and include it in your optimization command:

hailo optimize --hw-arch hailo8 --calib-path /path/to/calibration/images --alls rtmdet_script.alls --output-har-path ./MODELS/rtmdet_tiny_optimized.har ./MODELS/rtmdet_tiny.har

If the issue persists, you might want to analyze the model structure to identify any layers or operations that are particularly challenging for quantization. Using the Hailo Model Profiler can help provide more insights into the quantization process and highlight problematic layers.


Regards

1 Like