TAGGED: scade, SCADE-SUITE
-
-
March 28, 2025 at 5:22 pm
mihnea.apostolescu
SubscriberHello!
I encountered two issues while I was trying to convert a .keras convolutional neural networked trained and saved using tensorflow 2.16.1. I encountered the error below when I called the method : keras_importer.importer.model_import(loaded_model, "scade_model_path"), where loaded_model was my .keras CNN loaded using the tensorflow method keras_CNN_model = tf.keras.models.load_model(keras_CNN_path, compile=False)
"ANSYS(R) SCADE(R) - Keras Importer - Version 20220216.16 (C) 2022 ANSYS, Inc. Unauthorized use, distribution, or duplication is prohibited. Importing keras model to scade ... Translation of Conv2D layer: conv2d (id: 2320059174448) 'Conv2D' object has no attribute 'input_shape' Error: Keras Importer execution failurec:\Users\\AppData\Local\Programs\Python\Python312\Lib\site-packages\keras\src\layers\core\input_layer.py:25 : UserWarning: Argumentinput_shape
is deprecated. Useshape
instead. warnings.warn(1Â
"
That "1" is printed due to the return in the model_import method of the keras importer, which is part of the SCADE NN Package.
I tried converting a Keras model trained and saved using tensorflow 2.16.1 because of the compatibilities that the Nerual Networks Package described in its documentation :
However, I tried installing older versions of tensorflow (mostly 2.6.0) on a virtual environment which used python 3.9.4. Tensorflow 2.6.0 was not compatible with Python 3.12 which I used in the begining.
However, even if I tried installing the 2.6.0 versions of tensorflow and its tensorboard and tensorflow-estimator dependencies, I haven't succeeded in importing the keras importer of the SCADE NN Package afterwards. This is the error I encountered :
---------------------------------------------------------------------------ImportError                Traceback (most recent call last)Cell In[1], line 5   3 SCADE_keras_importer_path = os.path.join(os.getcwd(), 'ACT_Neural_Networks_Package_v1', 'src')   4 sys.path.append(SCADE_keras_importer_path)----> 5 import keras_importer.importer as ki   6 import tensorflow as tfÂFile c:\\SCADE implementation\ACT_Neural_Networks_Package_v1\src\keras_importer\importer.py:101    96   return opts   98 ###########################################################################   99 # Model translation--> 101 def import_model(model:tf.keras.Model) -> scade.Model:  102   # initialize project from template  103   dir = module.opts['target_dir']  104   res_dir = pathlib.Path(script_dir) / ".." / ".." / "resources" / "keras_importer"ÂFile c:\\scade_environment\lib\site-packages\tensorflow\python\util\lazy_loader.py:62, in LazyLoader.__getattr__(self, item)    61 def __getattr__(self, item):---> 62  module = self._load()   63  return getattr(module, item)ÂFile c:\\scade_environment\lib\site-packages\tensorflow\python\util\lazy_loader.py:45, in LazyLoader._load(self)    43 """Load the module and insert it into the parent's globals."""   44 # Import the target module and insert it into the parent's namespace---> 45 module = importlib.import_module(self.__name__)   46 self._parent_module_globals[self._local_name] = module   48 # Emit a warning if one was specifiedÂFile C:\Python39\lib\importlib\__init__.py:127, in import_module(name, package)  125       break  126     level += 1--> 127 return _bootstrap._gcd_import(name[level:], package, level)ÂFile c:\\scade_environment\lib\site-packages\keras\__init__.py:3    1 """AUTOGENERATED. DO NOT EDIT."""----> 3 from keras import __internal__   4 from keras import activations   5 from keras import applicationsÂFile c:\\scade_environment\lib\site-packages\keras\__internal__\__init__.py:3    1 """AUTOGENERATED. DO NOT EDIT."""----> 3 from keras.__internal__ import backend   4 from keras.__internal__ import layers   5 from keras.__internal__ import lossesÂFile c:\\scade_environment\lib\site-packages\keras\__internal__\backend\__init__.py:3    1 """AUTOGENERATED. DO NOT EDIT."""----> 3 from keras.src.backend import _initialize_variables as initialize_variables   4 from keras.src.backend import track_variableÂFile c:\\scade_environment\lib\site-packages\keras\src\__init__.py:21    1 # Copyright 2015 The TensorFlow Authors. All Rights Reserved.   2 #   3 # Licensed under the Apache License, Version 2.0 (the "License");  (...)   13 # limitations under the License.   14 # ==============================================================================   15 """Implementation of the Keras API, the high-level API of TensorFlow.   16   17 Detailed documentation and user guides are available at   18 [keras.io](https://keras.io).   19 """---> 21 from keras.src import applications   22 from keras.src import distribute   23 from keras.src import modelsÂFile c:\\scade_environment\lib\site-packages\keras\src\applications\__init__.py:18    1 # Copyright 2016 The TensorFlow Authors. All Rights Reserved.   2 #   3 # Licensed under the Apache License, Version 2.0 (the "License");  (...)   13 # limitations under the License.   14 # ==============================================================================   15 """Keras Applications are premade architectures with pre-trained weights."""---> 18 from keras.src.applications.convnext import ConvNeXtBase   19 from keras.src.applications.convnext import ConvNeXtLarge   20 from keras.src.applications.convnext import ConvNeXtSmallÂFile c:\\scade_environment\lib\site-packages\keras\src\applications\convnext.py:28    25 import numpy as np   26 import tensorflow.compat.v2 as tf---> 28 from keras.src import backend   29 from keras.src import initializers   30 from keras.src import layersÂFile c:\\scade_environment\lib\site-packages\keras\src\backend.py:34    32 from keras.src import backend_config   33 from keras.src.distribute import distribute_coordinator_utils as dc---> 34 from keras.src.dtensor import dtensor_api as dtensor   35 from keras.src.engine import keras_tensor   36 from keras.src.utils import control_flow_utilÂFile c:\\scade_environment\lib\site-packages\keras\src\dtensor\__init__.py:18    1 # Copyright 2022 The TensorFlow Authors. All Rights Reserved.   2 #   3 # Licensed under the Apache License, Version 2.0 (the "License");  (...)   13 # limitations under the License.   14 # ==============================================================================   15 """Keras' DTensor library."""---> 18 from tensorflow.compat.v2.experimental import dtensor as dtensor_apiÂImportError: cannot import name 'dtensor' from 'tensorflow.compat.v2.experimental' (c:\\scade_environment\lib\site-packages\tensorflow\_api\v2\compat\v2\experimental\__init__.py) ÂÂCould you please help me solve these issues and find a solution for using the keras importer and the python wrapper included in the SCADE NN Package?Â
Thank you in advance!
-
- You must be logged in to reply to this topic.
-
2773
-
960
-
825
-
599
-
591
© 2025 Copyright ANSYS, Inc. All rights reserved.