keras-team / autokeras

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

RuntimeError: Too many failed attempts to build model. | KeyError: 'structured_data_block_2/normalize' #1476

Open hemangjoshi37a opened 3 years ago

hemangjoshi37a commented 3 years ago

Code :

reg = ak.StructuredDataRegressor(overwrite=True,max_trials=3)
reg.fit(train_file_path,'next_close',epochs=10)

predicted_y = reg.predict(test_file_path)
print(reg.evaluate(test_file_path, 'next_close'))

Error :

Traceback (most recent call last):
  File "/home/hemang/.local/lib/python3.8/site-packages/kerastuner/engine/hypermodel.py", line 104, in build
    model = self.hypermodel.build(hp)
  File "/home/hemang/.local/lib/python3.8/site-packages/kerastuner/engine/hypermodel.py", line 64, in _build_wrapper
    return self._build(hp, *args, **kwargs)
  File "/home/hemang/.local/lib/python3.8/site-packages/autokeras/graph.py", line 250, in build
    outputs = block.build(hp, inputs=temp_inputs)
  File "/home/hemang/.local/lib/python3.8/site-packages/autokeras/engine/block.py", line 38, in _build_wrapper
    return super()._build_wrapper(hp, *args, **kwargs)
  File "/home/hemang/.local/lib/python3.8/site-packages/kerastuner/engine/hypermodel.py", line 64, in _build_wrapper
    return self._build(hp, *args, **kwargs)
  File "/home/hemang/.local/lib/python3.8/site-packages/autokeras/blocks/wrapper.py", line 251, in build
    if self.normalize is None and hp.Boolean(NORMALIZE):
  File "/home/hemang/.local/lib/python3.8/site-packages/kerastuner/engine/hyperparameters.py", line 814, in Boolean
    return self._retrieve(hp)
  File "/home/hemang/.local/lib/python3.8/site-packages/kerastuner/engine/hyperparameters.py", line 625, in _retrieve
    return self.values[hp.name]
KeyError: 'structured_data_block_2/normalize'
kaloomte commented 3 years ago

@hemangjoshi37a change overwrite=True to overwrite=False . It should works.

hemangjoshi37a commented 3 years ago

Thank you sir for your support.

On Mon, 4 Jan 2021 at 17:54, Mehmet Gunes notifications@github.com wrote:

@hemangjoshi37a https://github.com/hemangjoshi37a change overwrite=True to overwrite=False . It should works.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/keras-team/autokeras/issues/1476#issuecomment-753946207, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC6RPGO4KH2L5VTVXLRTXPLSYGXPLANCNFSM4VNH4FIA .

-- Regards, Hemang Joshi, Email : hemangjoshi37a@gmail.com mobile : +919409077371

mdalvi commented 3 years ago

The error is occurring at random even with overwrite=False

haifeng-jin commented 3 years ago

@mdalvi I cannot reproduce the bug. Do you see structured_data_block_2 in your output or structured_data_block_1? It would be great if you can set a seed StructuredDataRegressor(..., seed=5, ...). That would either don't cause the error, or help me reproduce the error : )

Robbertvld commented 3 years ago

I got the same error, even when i normalize the data before using the fit function.

The traceback:

Search: Running Trial #1 
Hyperparameter |Value |Best Value So Far structured_data...|True |? structured_data...|2 |? structured_data...|False |? structured_data...|0 |? structured_data...|32 |? structured_data...|32 |? regression_head...|0 |? optimizer |adam |? learning_rate |0.001 |? 
Traceback (most recent call last): 
File "~/Automl/.venv/lib/python3.7/site-packages/kerastuner/engine/hypermodel.py", line 104, in build model = self.hypermodel.build(hp) 
File "~/Automl/.venv/lib/python3.7/site-packages/kerastuner/engine/hypermodel.py", line 64, in _build_wrapper return self._build(hp, *args, **kwargs)
File "~/Automl/.venv/lib/python3.7/site-packages/autokeras/graph.py", line 250, in build outputs = block.build(hp, inputs=temp_inputs) 
File "~/Automl/.venv/lib/python3.7/site-packages/autokeras/engine/block.py", line 38, in _build_wrapper return super()._build_wrapper(hp, *args, **kwargs) 
File "~/Automl/.venv/lib/python3.7/site-packages/kerastuner/engine/hypermodel.py", line 64, in _build_wrapper return self._build(hp, *args, **kwargs) 
File "~/Automl/.venv/lib/python3.7/site-packages/autokeras/blocks/wrapper.py", line 251, in build if self.normalize is None and hp.Boolean(NORMALIZE): 
File "~/Automl/.venv/lib/python3.7/site-packages/kerastuner/engine/hyperparameters.py", line 814, in Boolean return self._retrieve(hp) 
File "~/Automl/.venv/lib/python3.7/site-packages/kerastuner/engine/hyperparameters.py", line 625, in _retrieve return self.values[hp.name] KeyError: 'structured_data_block_2/normalize' 
Invalid model 0/5 

and the key error

KeyError                                  Traceback (most recent call last)
~/Automl/.venv/lib/python3.7/site-packages/kerastuner/engine/hypermodel.py in build(self, hp)
    103                 with maybe_distribute(self.distribution_strategy):
--> 104                     model = self.hypermodel.build(hp)
    105             except:

~/Automl/.venv/lib/python3.7/site-packages/kerastuner/engine/hypermodel.py in _build_wrapper(self, hp, *args, **kwargs)
     63             hp = hp.copy()
---> 64         return self._build(hp, *args, **kwargs)
     65 

~/Automl/.venv/lib/python3.7/site-packages/autokeras/graph.py in build(self, hp)
    249             ]
--> 250             outputs = block.build(hp, inputs=temp_inputs)
    251             outputs = nest.flatten(outputs)

~/Automl/.venv/lib/python3.7/site-packages/autokeras/engine/block.py in _build_wrapper(self, hp, *args, **kwargs)
     37         with hp.name_scope(self.name):
---> 38             return super()._build_wrapper(hp, *args, **kwargs)
     39 

~/Automl/.venv/lib/python3.7/site-packages/kerastuner/engine/hypermodel.py in _build_wrapper(self, hp, *args, **kwargs)
     63             hp = hp.copy()
---> 64         return self._build(hp, *args, **kwargs)
     65 

~/Automl/.venv/lib/python3.7/site-packages/autokeras/blocks/wrapper.py in build(self, hp, inputs)
    250 
--> 251         if self.normalize is None and hp.Boolean(NORMALIZE):
    252             with hp.conditional_scope(NORMALIZE, [True]):

~/Automl/.venv/lib/python3.7/site-packages/kerastuner/engine/hyperparameters.py in Boolean(self, name, default, parent_name, parent_values)
    813                          conditions=self._conditions)
--> 814             return self._retrieve(hp)
    815 

~/Automl/.venv/lib/python3.7/site-packages/kerastuner/engine/hyperparameters.py in _retrieve(self, hp)
    624             if self._conditions_are_active(hp.conditions):
--> 625                 return self.values[hp.name]
    626             return None  # Ensures inactive values are not relied on by user.

KeyError: 'structured_data_block_2/normalize'

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
<ipython-input-11-5e49ad249fd6> in <module>
     13     start_time = time.time()
     14 
---> 15     reg.fit(X_train, y_train, validation_split=0.25, epochs=5, callbacks=[mc], verbose=1)
     16 
     17     hours = int((time.time() - start_time)/3600)

~/Automl/.venv/lib/python3.7/site-packages/autokeras/tasks/structured_data.py in fit(self, x, y, epochs, callbacks, validation_split, validation_data, **kwargs)
    139             validation_split=validation_split,
    140             validation_data=validation_data,
--> 141             **kwargs
    142         )
    143 

~/Automl/.venv/lib/python3.7/site-packages/autokeras/auto_model.py in fit(self, x, y, batch_size, epochs, callbacks, validation_split, validation_data, **kwargs)
    277             validation_data=validation_data,
    278             validation_split=validation_split,
--> 279             **kwargs
    280         )
    281 

~/Automl/.venv/lib/python3.7/site-packages/autokeras/engine/tuner.py in search(self, epochs, callbacks, validation_split, **fit_kwargs)
    179         self.oracle.update_space(hp)
    180 
--> 181         super().search(epochs=epochs, callbacks=new_callbacks, **fit_kwargs)
    182 
    183         # Train the best model use validation data.

~/Automl/.venv/lib/python3.7/site-packages/kerastuner/engine/base_tuner.py in search(self, *fit_args, **fit_kwargs)
    129 
    130             self.on_trial_begin(trial)
--> 131             self.run_trial(trial, *fit_args, **fit_kwargs)
    132             self.on_trial_end(trial)
    133         self.on_search_end()

~/Automl/.venv/lib/python3.7/site-packages/kerastuner/engine/tuner.py in run_trial(self, trial, *fit_args, **fit_kwargs)
    170         copied_fit_kwargs['callbacks'] = callbacks
    171 
--> 172         self._build_and_fit_model(trial, fit_args, copied_fit_kwargs)
    173 
    174     def save_model(self, trial_id, model, step=0):

~/Automl/.venv/lib/python3.7/site-packages/autokeras/engine/tuner.py in _build_and_fit_model(self, trial, fit_args, fit_kwargs)
     96         pipeline.save(self._pipeline_path(trial.trial_id))
     97 
---> 98         model = self.hypermodel.build(trial.hyperparameters)
     99         self.adapt(model, fit_kwargs["x"])
    100 

~/Automl/.venv/lib/python3.7/site-packages/kerastuner/engine/hypermodel.py in _build_wrapper(self, hp, *args, **kwargs)
     62             # to the search space.
     63             hp = hp.copy()
---> 64         return self._build(hp, *args, **kwargs)
     65 
     66 

~/Automl/.venv/lib/python3.7/site-packages/kerastuner/engine/hypermodel.py in build(self, hp)
    111                 if i == self._max_fail_streak:
    112                     raise RuntimeError(
--> 113                         'Too many failed attempts to build model.')
    114                 continue
    115 

RuntimeError: Too many failed attempts to build model.

The code I used for the call was:


reg = ak.StructuredDataRegressor(overwrite=True, max_trials=5, seed=1)

reg.fit(X_train, y_train, validation_split=0.25, epochs=5, callbacks=[mc], verbose=1)
jcdelpiano commented 2 years ago

Hello everyone,

any news about this issue? I'm getting the same error in here with my data (normalizing or not).

J.