Skip to content

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

Open
@jordannelson0

Description

@jordannelson0

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions