Skip to main content
GWang.3
Associate II
April 11, 2021
Solved

stm32ai quantize error?

  • April 11, 2021
  • 3 replies
  • 1902 views

I'm trying to use STM32AI quantize -q .json to quantize a Keras .H5. However, I never got it working.

Version: STM32 XCUBE-AI 6.0.0

tensorflow: I tried tf 2.0 and tf 1.15 installed

Platform. tried on both window and Linux (ubuntu 18.04)

Command line:

C:\Users\****\STM32Cube\Repository\Packs\STMicroelectronics\X-CUBE-AI\6.0.0\Utilities\windows\stm32ai quantize -q cfg_mnist_ss_sa_pc.json 

Error message:

Neural Network Tools for STM32AI v1.4.1 (STM.ai v6.0.0-RC6)

INTERNAL ERROR: 'Flags' object has no attribute 'module_directory'

    This topic has been closed for replies.
    Best answer by jean-michel.d

    Hello,

    The reported error is a typo issue during the management of a specific error in the quantization script. In this case, the original issue indicates that the script is not able to import the user scripts (referenced by the json fle), directly or indirectly through the imports inside the script itself. To fix the error message, you can duplicate the line "modules_directory" and to replace "modules_directory" by "module_directory", key name w/o "s".

    { 
    ...
     "batch_size": "128",
     "modules_directory": "kws_modules",
     "module_directory": "kws_modules",
    ...
    }

    Note in v6.0, the PIL Python module is not available.

    br,

    Jean-Michel

    3 replies

    jean-michel.dBest answer
    ST Employee
    April 12, 2021

    Hello,

    The reported error is a typo issue during the management of a specific error in the quantization script. In this case, the original issue indicates that the script is not able to import the user scripts (referenced by the json fle), directly or indirectly through the imports inside the script itself. To fix the error message, you can duplicate the line "modules_directory" and to replace "modules_directory" by "module_directory", key name w/o "s".

    { 
    ...
     "batch_size": "128",
     "modules_directory": "kws_modules",
     "module_directory": "kws_modules",
    ...
    }

    Note in v6.0, the PIL Python module is not available.

    br,

    Jean-Michel

    GWang.3
    GWang.3Author
    Associate II
    April 15, 2021

    Actually, it didn't solve my problem. I tried the example Mnist, it is working fine. However, the same approach didn't work for cfg_kws_ss_sa.json and also cfg_kws_ua_ua.json. I also created my own Har.json. Here is my json file:

    {

        "model_name": "Har",

        "path_to_floatingpoint_h5": ".\\Har\\har.h5",

        "quant_test_set_dir":"",

        "quant_test_ratio": "0.3",

        "evaluation_test_set_dir":"",

        "batch_size": "50",

        "modules_directory": ".\\Har\\",

        "module_directory": ".\\Har\\",

        "filename_test_set_generation": "test_har.py",

        "filename_quantizer_algos": "quantizer_algos_user.py",

        "algorithm": "MinMax",

        "arithmetic": "Integer",

        "weights_integer_scheme": "SignedSymmetric",

        "activations_integer_scheme": "SignedAsymmetric",

        "per_channel": "False",

        "output_directory": "HAR_Quantization_results"

    }

    It always said (the same is true for kws example).

    QUANTIZER ERROR: E503(QuantParamError): Unable to load the module "test_har" (modules_dir=.\Har), but the directory is there and also the file.

    For cfg_kws_ss_sa.json, it is the same error:

    E502(QuantParamError): Unable to load the module "test_set_generation_flatten (module_dir=kws_modules) (but the directory and also the file both are in the folder".

    And also the interesting part is: for mnist, even I didn't add

    "module_directory", only have "modules_directory", it worked.

    Please help.

    Thanks,

    Guoping

    GWang.3
    GWang.3Author
    Associate II
    April 16, 2021

    I was able to figure it out. The STM XCUBE-AI uses its own Python packages and Python version. When we are creating customized dataset, we can only use available packages in that folder \6.0.0\Utilities.

    ST Employee
    April 16, 2021

    Hi, Guoping,

    Thanks, I confirm the highlighted point, only the available Python packages from \6.0.0\Utilities\Windows folder can be used.

    A possible workaround, if really necessary is to add (to copy) manually the expected Python package in this directory, however, to be vigilant with the used version to avoid to break the installation. To know the used Python version, following command 'stm32ai --tools-version' can be used.

    br,

    Jean-Michel