-
Notifications
You must be signed in to change notification settings - Fork 45
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
ModuleNotFoundError: No module named 'tensorflow.keras.wrappers' #118
Comments
Another Approach you can try |
I have the same problem. On MacOS, "pip install tensorflow==2.12.0" does not work either |
Hello everyone, |
Hi everyone, PS: you made need to upgrade your Tensorflow version to 2.15, but ADAPT should work with previous versions too. |
Beginner here, how do I apply this fix, I'm encountering the same issue. Thanks in advance! |
Hi @juliog23, Please try (in your environment): pip install --upgrade adapt If you are using a jupyter notebook, you can run the following command in a coding cell: !pip install --upgrade adapt |
Thank you for the quick response. I just got around to running the code you supplied and it installed successfully but still getting the same error. When I look in the directory there is no module named “wrappers”. My current file path is “../site-packages/tensorflow/python/keras On Jan 10, 2024, at 1:21 AM, antoinedemathelin ***@***.***> wrote:
Hi @juliog23,
Do you know which version of Adapt you are using ? The issue should be resolved with Adapt 0.4.4
Please try (in your environment):
pip install --upgrade adapt
If you are using a jupyter notebook, you can run the following command in a coding cell:
!pip install --upgrade adapt
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Hi @juliog23, Can you please share the whole error message you get ? Do you work in a conda environment ? If yes, can you please share the versions of your packages by copy-pasting the prompt of:
Maybe you can resolve the issue by installing
|
Hello, here is the full error message:2024-01-11 10:36:54.385678: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.WARNING:tensorflow:From C:\Users\julio\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead.
Traceback (most recent call last): File "C:\Users\julio\OneDrive\NBA Games\NBA 23-24 Season\polyfit_deep_learning_rev2.py", line 12, in <module> from tensorflow.keras.wrappers.scikit_learn import KerasRegressorModuleNotFoundError: No module named 'tensorflow.keras.wrappers'
Thank you!
On Thursday, January 11, 2024 at 07:09:26 AM PST, antoinedemathelin ***@***.***> wrote:
Hi @juliog23,
Can you please share the whole error message you get ?
Do you work in a conda environment ? If yes, can you please share the versions of your packages by copy-pasting the prompt of:
conda list
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Hi @juliog23, I think the error can be resolved by installing scikeras, can you please try:
|
If the error is still not resolved, you can watch the installed package versions with:
or
To verify that you have the last version of adapt installed. PS : don't forget to put "!" before the commands, if you are executing them in a jupyter cell ( |
I already had scikeras installed but I uninstalled it and then reinstalled it just in case. The scikeras path in my computer is: ".........\Programs\Python\Python311\Lib\site-packages\scikeras"
The code from my understanding is erroring with "ModuleNotFoundError: No module named 'tensorflow.keras.wrappers'" (error from my previous message). But when I look in my file path in tensorflow: "....\site-packages\tensorflow\python\keras" the keras folder doesn't have a module called "wrappers". Or does it know to look for this module elsewhere based on how the error code is being spit out. This is the beginning of the code:
import pandas as pdimport scipy.sparseimport osfrom tensorflow import kerasfrom sklearn.model_selection import train_test_split, cross_val_score, KFoldfrom sklearn.preprocessing import StandardScaler, OneHotEncoderfrom sklearn.compose import ColumnTransformerfrom sklearn.metrics import mean_squared_errorfrom tensorflow.keras.models import Sequential, load_modelfrom tensorflow.keras.layers import Dense, Dropoutfrom tensorflow.keras.wrappers.scikit_learn import KerasRegressorimport joblibfrom imblearn.over_sampling import SMOTE
**I also have another keras folder in ".....\site-packages\keras" not sure if this matters.
Here is the pip list (I'm running all this on cmd as well):
Package Version---------------------------- ---------absl-py 2.0.0adapt 0.4.4alembic 1.13.1altair 5.1.1amply 0.1.5astunparse 1.6.3attrs 23.1.0blinker 1.6.2cachetools 5.3.1certifi 2023.7.22charset-normalizer 3.2.0click 8.1.7colorama 0.4.6colorlog 6.8.0contourpy 1.1.0copulas 0.9.0cvxopt 1.3.2cycler 0.11.0docutils 0.20.1et-xmlfile 1.1.0flatbuffers 23.5.26fonttools 4.40.0fuzzywuzzy 0.18.0gast 0.5.4gitdb 4.0.10GitPython 3.1.37google-auth 2.26.1google-auth-oauthlib 1.0.0google-pasta 0.2.0greenlet 3.0.3grpcio 1.60.0h2o 3.44.0.3h5py 3.10.0idna 3.4imbalanced-learn 0.11.0importlib-metadata 6.8.0Jinja2 3.1.2joblib 1.3.2json5 0.9.14jsonschema 4.19.1jsonschema-specifications 2023.7.1keras 2.15.0kiwisolver 1.4.4Levenshtein 0.21.0libclang 16.0.6llvmlite 0.41.1Mako 1.3.0Markdown 3.5.1markdown-it-py 3.0.0MarkupSafe 2.1.3matplotlib 3.7.2mdurl 0.1.2ml-dtypes 0.2.0numba 0.58.1numpy 1.24.3oauthlib 3.2.2openpyxl 3.1.2opt-einsum 3.3.0optuna 3.5.0package-name 0.1packaging 23.1pandas 2.0.2patsy 0.5.4Pillow 9.5.0pip 23.3.2ply 3.11protobuf 4.23.4PuLP 2.4pyarrow 13.0.0pyasn1 0.5.1pyasn1-modules 0.3.0pydeck 0.8.1b0pydfs-lineup-optimizer 3.6.1Pygments 2.16.1Pyomo 6.6.1pyparsing 3.0.9python-dateutil 2.8.2python-Levenshtein 0.21.0pytz 2023.3PyYAML 6.0.1rapidfuzz 3.0.0referencing 0.30.2requests 2.31.0requests-oauthlib 1.3.1rich 13.5.3rpds-py 0.10.3rsa 4.9scikeras 0.12.0scikit-learn 1.3.2scipy 1.11.1seaborn 0.12.2setuptools 65.5.0six 1.16.0smmap 5.0.1SQLAlchemy 2.0.25statsmodels 0.14.0streamlit 1.27.0tabulate 0.9.0tenacity 8.2.3tensorboard 2.15.1tensorboard-data-server 0.7.2tensorflow 2.15.0tensorflow-estimator 2.15.0tensorflow-intel 2.15.0tensorflow-io-gcs-filesystem 0.31.0termcolor 2.4.0threadpoolctl 3.2.0timedelta 2020.12.3toml 0.10.2toolz 0.12.0tornado 6.3.3tqdm 4.65.0typing_extensions 4.8.0tzdata 2023.3tzlocal 5.0.1urllib3 2.0.5validators 0.22.0watchdog 3.0.0Werkzeug 3.0.1wheel 0.42.0wrapt 1.14.1zipp 3.17.0
On Friday, January 12, 2024 at 01:14:23 AM PST, antoinedemathelin ***@***.***> wrote:
If the error is still not resolved, you can watch the installed package versions with:
pip list
or
conda list
To verify that you have the last version of adapt installed.
PS : don't forget to put "!" before the commands, if you are executing them in a jupyter cell (!pip list)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Hi @juliog23, You have the last version of adapt (0.4.4) so the bug doesn't come from the adapt library. Your issue comes from this import : Best, |
This last suggestion may have fixed it, no more error on that. Will work through some other modifications I need to do to run the code in its entirety. Thank you for your guidance and patience. On Jan 13, 2024, at 6:10 AM, antoinedemathelin ***@***.***> wrote:
Hi @juliog23,
The module keras.wrappershas been removed in tensorflow 2.15, so its normal you don't find it.
You have the last version of adapt (0.4.4) so the bug doesn't come from the adapt library.
Your issue comes from this import : from tensorflow.keras.wrappers.scikit_learn import KerasRegressor
You should replace this line with: from scikeras.wrappers import KerasRegressor
Best,
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
the error for the module not found is resolved I think. However, when using GridSearchCV, the fit function is not working properly. The code is very simple: `import numpy as np Generate synthetic regression dataX, y = make_regression(n_samples=1000, n_features=5, noise=0.1, random_state=42) Scale the featuresscaler = StandardScaler() Define the ANN model functiondef create_model(units=64, activation='relu', learning_rate=0.001): Create KerasRegressor objectkeras_model = KerasRegressor(build_fn=create_model, verbose=0) Define the hyperparameter gridparam_grid = { Create the GridSearchCV objectgrid_search = GridSearchCV(estimator=keras_model, param_grid=param_grid, cv=3, scoring="neg_mean_squared_error") Fit the model with GridSearchCVgrid_search.fit(X_scaled, y) Get the best model and parametersbest_model = grid_search.best_estimator_ Print the best parametersprint("Best Hyperparameters:", best_params) Use the best model for predictiony_pred = best_model.predict(X_scaled) Evaluate the model (replace with your desired evaluation metric)from sklearn.metrics import mean_squared_error ValueError Traceback (most recent call last) File C:\ProgramData\anaconda3\Lib\site-packages\sklearn\base.py:1151, in _fit_context..decorator..wrapper(estimator, *args, **kwargs) File C:\ProgramData\anaconda3\Lib\site-packages\sklearn\model_selection_search.py:898, in BaseSearchCV.fit(self, X, y, groups, **fit_params) File C:\ProgramData\anaconda3\Lib\site-packages\sklearn\model_selection_search.py:1419, in GridSearchCV._run_search(self, evaluate_candidates) File C:\ProgramData\anaconda3\Lib\site-packages\sklearn\model_selection_search.py:845, in BaseSearchCV.fit..evaluate_candidates(candidate_params, cv, more_results) File C:\ProgramData\anaconda3\Lib\site-packages\sklearn\utils\parallel.py:65, in Parallel.call(self, iterable) File C:\ProgramData\anaconda3\Lib\site-packages\joblib\parallel.py:1085, in Parallel.call(self, iterable) File C:\ProgramData\anaconda3\Lib\site-packages\joblib\parallel.py:901, in Parallel.dispatch_one_batch(self, iterator) File C:\ProgramData\anaconda3\Lib\site-packages\joblib\parallel.py:819, in Parallel._dispatch(self, batch) File C:\ProgramData\anaconda3\Lib\site-packages\joblib_parallel_backends.py:208, in SequentialBackend.apply_async(self, func, callback) File C:\ProgramData\anaconda3\Lib\site-packages\joblib_parallel_backends.py:597, in ImmediateResult.init(self, batch) File C:\ProgramData\anaconda3\Lib\site-packages\joblib\parallel.py:288, in BatchedCalls.call(self) File C:\ProgramData\anaconda3\Lib\site-packages\joblib\parallel.py:288, in (.0) File C:\ProgramData\anaconda3\Lib\site-packages\sklearn\utils\parallel.py:127, in _FuncWrapper.call(self, *args, **kwargs) File C:\ProgramData\anaconda3\Lib\site-packages\sklearn\model_selection_validation.py:720, in _fit_and_score(estimator, X, y, scorer, train, test, verbose, parameters, fit_params, return_train_score, return_parameters, return_n_test_samples, return_times, return_estimator, split_progress, candidate_progress, error_score) File ~\AppData\Roaming\Python\Python311\site-packages\scikeras\wrappers.py:1165, in BaseWrapper.set_params(self, params) ValueError: Invalid parameter activation for estimator KerasRegressor. Can anyone tell me what the problem is? |
Hi @Griffunus, Just change this line: keras_model = KerasRegressor(build_fn=create_model, verbose=0) For this one: keras_model = KerasRegressor(build_fn=create_model, verbose=0, activation="relu", learning_rate=0.1, units=24) The idea is that you need to give random parameters for activation, learning_rate and units, such that KerasRegressor knows that they are "valid" parameters. Best, |
I am using tensorflow 2.13.0 and keras 2.13.1. I got this error? could you please advise what is the version of compitable TensorFlow
The text was updated successfully, but these errors were encountered: