question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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'

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
kaloomtecommented, Jan 4, 2021

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

3reactions
Robbertvldcommented, May 31, 2021

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)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Too many failed attempts to build model. keras tuner - Stack ...
RuntimeError : Too many failed attempts to build model. keras tuner ; class RegressionHyperModel (HyperModel): ; 'tanh', 'sigmoid'], default='relu' ...
Read more >
RuntimeError: Too many failed attempts to build model.
RuntimeError : Too many failed attempts to build model. | KeyError: 'structured_data_block_2/normalize'
Read more >
Too many failed attempts to build model. keras tuner
i want to use keras tuner to tune model hyper parameter using the following code that first create the class to make the...
Read more >
Keras Tuner _ Hello World - Kaggle
Int('units_' + str(i), 32, 512, 32), activation='relu')) model.add(layers. ... 116 continue 117 RuntimeError: Too many failed attempts to build model.
Read more >
KerasTuner KeyError issue.ipynb - Colaboratory - Google Colab
same error with this alternative code if the script is run twice ... RuntimeError: Too many failed attempts to build model. Search Stack...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found