keras-team / autokeras

AutoML library for deep learning
http://autokeras.com/
Apache License 2.0
9.12k stars 1.4k forks source link

AttributeError: module 'numpy' has no attribute 'object' when using autokeras with structured data #1898

Open GhulamMustafa0324 opened 10 months ago

GhulamMustafa0324 commented 10 months ago

I am encountering an error when using autokeras for structured data classification. When I try to fit a model, I receive the following error message:

AttributeError: module 'numpy' has no attribute 'object'. np.object was a deprecated alias for the builtin object. To avoid this error in existing code, use object by itself. Doing this will not modify any behavior and is safe. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

I have already upgraded the autokeras library to the latest version, but the error persists.

Here is an example of how I am using autokeras:

import autokeras as ak
from kerastuner import Objective

f1_objective = Objective("f1", direction="max")

clf = ak.StructuredDataClassifier(
    objective=f1_objective,
    max_trials=10,
)

clf.fit(X_train, y_train)

best_model_id = clf.get_best_model_id()
print("Best model ID:", best_model_id)

best_model = clf.export_model(best_model_id)
print("Best model:", best_model)

trials = clf.get_trials()
for trial in trials:
    print("Trial ID:", trial.id)
    print("Hyperparameters:", trial.hyperparameters)
    print("Performance metrics:", trial.metrics)
hanzigs commented 9 months ago

I got the same error for StructuredDataClassifier, Since Numpy 1.24, np.object is deprecated, and to be replaced with object

ERROR:500 Internal Server Error: module 'numpy' has no attribute 'object'.
`np.object` was a deprecated alias for the builtin `object`. To avoid this error in existing code, use `object` by itself. Doing this will not modify any behavior and is safe.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

on here

  File "C:\Users\PA\anaconda3\envs\py3117\Lib\site-packages\autokeras\adapters\input_adapters.py", line 73, in convert_to_dataset
    if isinstance(dataset, np.ndarray) and dataset.dtype == np.object:

I replaced np.object --> object, It worked. Can we update the library. Using Python 3.11.7 Autokeras 1.0.20 Numpy 1.26.3

SarthakNikhal commented 8 months ago

Can I work on this issue? @haifeng-jin

Gafar1994 commented 7 months ago

Its numpy latest version problem. Use pip install numpy==1.23.4

haifeng-jin commented 7 months ago

@SarthakNikhal Sorry for the late reply. Anyone interested can work on this.

wstlxx commented 4 months ago

Also, if someone is having <module 'numpy' has no attribute 'unicode'> you can simply replace np.unicode into np.str_ in input_adapters.py