Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: ModuleNotFoundError: No module named 'tensorflow.keras.layers.experimental' #1923

Open
jordannelson0 opened this issue Jun 27, 2024 · 3 comments

Comments

@jordannelson0
Copy link

Bug Description

I am getting this error: File "C:\Users\jorda\Documents\PhD\Project\NLP_algorithms\CNN_AM.py", line 3, in
import autokeras as ak

File "C:\Users\jorda\Documents\PhD\Project\venv\Lib\site-packages\autokeras_init_.py", line 15, in
from autokeras.auto_model import AutoModel
File "C:\Users\jorda\Documents\PhD\Project\venv\Lib\site-packages\autokeras\auto_model.py", line 26, in
from autokeras import blocks
File "C:\Users\jorda\Documents\PhD\Project\venv\Lib\site-packages\autokeras\blocks_init_.py", line 18, in
from autokeras.blocks.basic import BertBlock
File "C:\Users\jorda\Documents\PhD\Project\venv\Lib\site-packages\autokeras\blocks\basic.py", line 25, in
from autokeras import keras_layers
File "C:\Users\jorda\Documents\PhD\Project\venv\Lib\site-packages\autokeras\keras_layers.py", line 27, in
from tensorflow.keras.layers.experimental import preprocessing
ModuleNotFoundError: No module named 'tensorflow.keras.layers.experimental'

Bug Reproduction

Code for reproducing the bug:
`import os

import autokeras as ak
import numpy as np
from pandas import read_csv
from sklearn.model_selection import train_test_split

os.environ["TF_ENABLE_ONEDNN_OPTS"] = "0"

dataframe = read_csv("ML_Prompts.csv", skiprows=0)
dataset = dataframe.values
x = dataset[:, 0:1744]
y = dataset[:, 1744]

x_train, x_temp, y_train, y_temp = train_test_split(x, y, test_size=0.2)
x_val, x_test, y_val, y_test = train_test_split(x_temp, y_temp, test_size=0.5)

x_train = np.expand_dims(x_train, axis=2)

input_node = ak.Input()
output_node = ak.ConvBlock()(input_node)
output_node = ak.SpatialReduction()(input_node) # optional
output_node = ak.ConvBlock()(input_node)
output_node = ak.SpatialReduction()(output_node) # optional
output_node = ak.ClassificationHead(num_classes=8, multi_label=False)(output_node)
model = ak.AutoModel(
inputs=input_node,
outputs=output_node,
overwrite=True,
max_trials=20,
objective='val_accuracy',
tuner='bayesian'
)

model.fit(x_train, y_train, epochs=50, batch_size=4, verbose=1)
eval_result = model.evaluate(x_test, y_test, verbose=1)
print("Test loss:", eval_result[0])
print("Test accuracy:", eval_result[1])
modelv = model.export_model()
print(type(model.summary()))

try:
modelv.save("CNN_ML_Classifier.keras")
except Exception:
modelv.save("CNN_ML_Classifier.keraas")
`

Data used by the code:

Expected Behavior

Setup Details

Include the details about the versions of:

  • OS type and version: Windows 11
  • Python: 3.12.4
  • autokeras: 1.0.20 (I have been unable to upgrade this package due to a different error)
  • keras-tuner: 1.4.7
  • scikit-learn: 1.5.0
  • numpy: 1.26.4
  • pandas: 2.2.2
  • tensorflow: 2.17.0rc0

Additional context

@Daniel-Alvarenga
Copy link

The error you're encountering (ModuleNotFoundError: No module named 'tensorflow.keras.layers.experimental') suggests that the version of TensorFlow you are using doesn't have the tensorflow.keras.layers.experimental module. This module has been deprecated in the latest versions of TensorFlow.

To resolve this, you can try this:

Check TensorFlow and AutoKeras Compatibility

First, ensure that your versions of TensorFlow and AutoKeras are compatible. AutoKeras 1.0.20 might not be fully compatible with TensorFlow 2.17.0rc0. You can check the compatibility matrix on the AutoKeras documentation or GitHub repository.

Update or Downgrade TensorFlow

You may need to downgrade TensorFlow to a version compatible with AutoKeras 1.0.20. For example, TensorFlow 2.4.1 is known to be compatible with AutoKeras 1.0.20. You can downgrade TensorFlow using pip:

pip install tensorflow==2.4.1

Install the Latest AutoKeras

If downgrading TensorFlow is not an option, you may need to upgrade AutoKeras. However, since you mentioned an error while upgrading AutoKeras, we'll address that next.

Resolve AutoKeras Upgrade Issue

Try upgrading AutoKeras to the latest version using pip:

pip install --upgrade autokeras

If you encounter errors during the upgrade, you can try uninstalling and then reinstalling it:

pip uninstall autokeras
pip install autokeras

@jordannelson0
Copy link
Author

The error you're encountering (ModuleNotFoundError: No module named 'tensorflow.keras.layers.experimental') suggests that the version of TensorFlow you are using doesn't have the tensorflow.keras.layers.experimental module. This module has been deprecated in the latest versions of TensorFlow.

To resolve this, you can try this:

Check TensorFlow and AutoKeras Compatibility

First, ensure that your versions of TensorFlow and AutoKeras are compatible. AutoKeras 1.0.20 might not be fully compatible with TensorFlow 2.17.0rc0. You can check the compatibility matrix on the AutoKeras documentation or GitHub repository.

Update or Downgrade TensorFlow

You may need to downgrade TensorFlow to a version compatible with AutoKeras 1.0.20. For example, TensorFlow 2.4.1 is known to be compatible with AutoKeras 1.0.20. You can downgrade TensorFlow using pip:

pip install tensorflow==2.4.1

Install the Latest AutoKeras

If downgrading TensorFlow is not an option, you may need to upgrade AutoKeras. However, since you mentioned an error while upgrading AutoKeras, we'll address that next.

Resolve AutoKeras Upgrade Issue

Try upgrading AutoKeras to the latest version using pip:

pip install --upgrade autokeras

If you encounter errors during the upgrade, you can try uninstalling and then reinstalling it:

pip uninstall autokeras
pip install autokeras

I can't get autokeras 2.0 because of this:
The conflict is caused by:
keras-nlp 0.14.0 depends on tensorflow-text; platform_system != "Darwin"
keras-nlp 0.12.1 depends on tensorflow-text; platform_system != "Darwin"
keras-nlp 0.12.0 depends on tensorflow-text; platform_system != "Darwin"
keras-nlp 0.11.1 depends on tensorflow-text; platform_system != "Darwin"
keras-nlp 0.11.0 depends on tensorflow-text; platform_system != "Darwin"
keras-nlp 0.10.0 depends on tensorflow-text; platform_system != "Darwin"
keras-nlp 0.9.3 depends on tensorflow-text; platform_system != "Darwin"
keras-nlp 0.9.2 depends on tensorflow-text; platform_system != "Darwin"
keras-nlp 0.9.1 depends on tensorflow-text; platform_system != "Darwin"
keras-nlp 0.9.0 depends on tensorflow-text; platform_system != "Darwin"
keras-nlp 0.8.2 depends on tensorflow-text; platform_system != "Darwin"
keras-nlp 0.8.1 depends on tensorflow-text; platform_system != "Darwin"
keras-nlp 0.8.0 depends on tensorflow-text; platform_system != "Darwin"

@j2322
Copy link

j2322 commented Sep 16, 2024

We also received the conflict errors with tensorflow-text. It looks like tensorflow-text is not currently available in pip for Python 3.12. We resolved this by using Python 3.10. The package info also states it has support for 3.9 or 3.11, so those should work as well. After we were able to install and use Autokeras 2.0.0 with Tensorflow 2.17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants