Usage of `train_encoding` is not clear

Hi,

I am trying to fine-tune a CNN for RBG images. To do so, I am using `train_encoding` to optimize the weights and biases of the layers. However, it fails on that because it says `you cannot mix tensors and non-tensors`. The given list of mixed tensors and non-tensors only include `avgpool` layers and its operations. Yet, when I pass the shown layers to `layers_to_freeze`, it still keeps failing.

Am I doing something wrong?

Hi @Isaac_Nunez ,

Maybe the following might assist:

  1. Use pre‑quantization optimizations for problematic avgpools

For avgpool layers that cause quantization/encoding issues (especially global or near‑global pools), the recommended approach is to transform them before quantization, e.g.:

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

This reduces the spatial dimensions before the final global pool and can make the layer more quantization‑friendly. See: Average Pool error cannot quantize and An error occurred when compiling the custom model into a HEF file

If your failing layers are global or large‑kernel avgpools, applying such a pre‑quantization optimization before train_encoding may avoid the internal inconsistency that leads to the tensor/non‑tensor mix error.

  1. Confirm layers_to_freeze usage

The docs define layers_to_freeze as:

Freeze (don’t modify weights&biases for) any layer whose name includes one of this list as a substring.

See: https://hailo.ai/developer-zone/documentation/dataflow-compiler-v3-33-0/?sp_referrer=sdk%2Fmodel_optimization.html#train-encoding and https://hailo.ai/developer-zone/documentation/dataflow-compiler-v5-2-0/?sp_referrer=sdk%2Fmodel_optimization.html#finetune

That means:

  • You must pass substrings that actually appear in the Hailo‑HN layer names (e.g. avgpool1, avgpool), not framework‑side names.

  • Freezing a layer only prevents its weights/biases from being updated; it doesn’t change how its tensors are represented in the graph. So if the error is about mixing tensor/non‑tensor objects in the computation graph, freezing alone may not resolve it.

Please let me know if that was helpful.
Thanks,