cancel
Showing results for 
Search instead for 
Did you mean: 

Error while analyzing Keras model with X-CUBE-AI (DLL load failed)

EZeli.1
Associate II

Hi, I have installed STM32 cube IDE and the latest version of CUBE AI software pack to convert a pretrained neural nework implemented and trained with Keras/TF. After creating a project, when I try to add a network from a saved model.h5 from the file system, when I try to analyze it I have the following error:

Analyzing model 

C:/Users/<username>/STM32Cube/Repository/Packs/STMicroelectronics/X-CUBE-AI/6.0.0/Utilities/windows/stm32ai analyze --name network -m C:/Users/<username>/facedetection/pnet.h5 --type keras --compression 1 --verbosity 1 --workspace C:\Users\<username>\AppData\Local\Temp\mxAI_workspace85208706500011701743944848630527 --output C:\Users\<username>\.stm32cubemx  

[456] Failed to execute script stm32ai 

Traceback (most recent call last): 

  File "tensorflow\python\pywrap_tensorflow.py", line 64, in <module> 

    from tensorflow.python._pywrap_tensorflow_internal import * 

ImportError: DLL load failed: Routine di inizializzazione della libreria di collegamento dinamico (DLL) non riuscita. 

 

During handling of the above exception, another exception occurred: 

 

Traceback (most recent call last): 

  File "stm32ai.py", line 376, in <module> 

  File "c:\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module 

  File "irs\objects\ai_layer_factory.py", line 22, in <module> 

  File "c:\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module 

  File "irs\objects\layers\bidirectional.py", line 23, in <module> 

  File "c:\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module 

  File "irs\objects\layers\gru.py", line 24, in <module> 

  File "c:\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module 

  File "irs\objects\layers\recurrent_layer.py", line 24, in <module> 

  File "c:\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module 

  File "utilities\keras_utilities.py", line 28, in <module> 

  File "c:\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module 

  File "tensorflow\__init__.py", line 41, in <module> 

    from tensorflow.python.tools import module_util as _module_util 

  File "c:\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module 

  File "tensorflow\python\__init__.py", line 40, in <module> 

    from tensorflow.python.eager import context 

  File "c:\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module 

  File "tensorflow\python\eager\context.py", line 35, in <module> 

    from tensorflow.python import pywrap_tfe 

  File "c:\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module 

  File "tensorflow\python\pywrap_tfe.py", line 28, in <module> 

    from tensorflow.python import pywrap_tensorflow 

  File "c:\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module 

  File "tensorflow\python\pywrap_tensorflow.py", line 83, in <module> 

    raise ImportError(msg) 

ImportError: Traceback (most recent call last): 

  File "tensorflow\python\pywrap_tensorflow.py", line 64, in <module> 

    from tensorflow.python._pywrap_tensorflow_internal import * 

ImportError: DLL load failed: Routine di inizializzazione della libreria di collegamento dinamico (DLL) non riuscita. 

 

 

Failed to load the native TensorFlow runtime. 

 

See https://www.tensorflow.org/install/errors 

 

for some common reasons and solutions.  Include the entire stack trace 

above this error message when asking for help

The above error can be translated as:

ImportError:  DLL load failed: DLL initialization routine failed.

This it the STM32CubeIDE version:

Version: 1.6.1

Build: 9958_20210326_1446 (UTC)

My OS is windows 10. I already tried to install the Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019, but nothing changed.

Do you have any suggestion about what could be wrong in my environment setup?

Thanks,

Enrico

5 REPLIES 5
EZeli.1
Associate II

UPDATE:

A similar error occurs if I switch to a previous version of X-CUBE-AI (5.0.0):

Analyzing model 

Neural Network Tools for STM32 v1.2.0 (AI tools v5.0.0) 

TOOL ERROR: Traceback (most recent call last): 

  File "C:\Users\<username>\STM32Cube\Repository\Packs\STMicroelectronics\X-CUBE-AI\5.0.0\Utilities\windows\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module> 

    from tensorflow.python.pywrap_tensorflow_internal import * 

  File "C:\Users\<username>\STM32Cube\Repository\Packs\STMicroelectronics\X-CUBE-AI\5.0.0\Utilities\windows\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module> 

    _pywrap_tensorflow_internal = swig_import_helper() 

  File "C:\Users\<username>\STM32Cube\Repository\Packs\STMicroelectronics\X-CUBE-AI\5.0.0\Utilities\windows\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper 

    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) 

  File "imp.py", line 242, in load_module 

  File "imp.py", line 342, in load_dynamic 

ImportError: DLL load failed: Routine di inizializzazione della libreria di collegamento dinamico (DLL) non riuscita. 

 

 

Failed to load the native TensorFlow runtime. 

 

See https://www.tensorflow.org/install/errors 

 

for some common reasons and solutions.  Include the entire stack trace 

above this error message when asking for help.

fauvarque.daniel
ST Employee

We had a similar issue in the past with vcruntime (the vcruntime140_1.dll was missing in the directory).

Can you try to see if you have another vcruntimexxxx.dll in C:\Windows\System32 and copy it into

C:\Users\<username>\STM32Cube\Repository\Packs\STMicroelectronics\X-CUBE-AI\5.0.0\Utilities\windows

Regards


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
EZeli.1
Associate II

Hi Daniel,

Thanks for your help!

The library vcruntime140_1.dll was actually missing in C:\Users\<username>\STM32Cube\Repository\Packs\STMicroelectronics\X-CUBE-AI\5.0.0\Utilities\windows, but adding it didn't solve the problem. I also tried adding other related files (e.g. vcruntime140.dll, replacing it with the version in my C:\Windows\System32 directory), but nothing seems to work. The error I am having is exactly the same as before.

Shall I try to install older versions of STM32 cube IDE?

If yes, do you have any suggestion on which configuration to try first?

Thanks,

Enrico

Jmart.1
Associate

Please tell me if u find an answer, i cant get through this either.

emark.1
Associate

To make it short, it means that you lacked some "dependencies" for the libraries you wanted to use. This is a common problem when installing python packages, mainly in windows. Before trying to use any kind of library, first it is suggested to look up whether it needs another library in python "family". 

The solution is to provide the python interpreter with the path-to-your-module/library. The simplest solution is to append that python path to your sys.path list. In your notebook, first try:

import sys
 
sys.path.append('my/path/to/module/folder')

This isn't a permanent change in sys.path, because when you log out, your environment is reset, so any variables you may have set are lost.

The better (and more permanent) way to solve this is to set your PYTHONPATH, which provides the interpreter with additional directories look in for python packages/modules.

from BASH type: export PYTHONPATH=/path/to/new/folder:/another/path/...../    #each path must be separated by a colon