title: RuntimeError: Too many failed attempts to build model. keras tuner
body: <p>i want to use keras tuner to tune model hyper parameter 
  using the following code that first create the class to make the optimization as following </p>
  
  <pre><code>class RegressionHyperModel (HyperModel):    
   def __init__(self, input_shape): 
        self.input_shape = input_shape 
   def build(self, hp):
       model = Sequential()
       model.add(
       layers.Dense(
       units=hp.Int('units', 8, 64, 4, default=8),
       activation=hp.Choice(
       'dense_activation',
       values=['relu', 'tanh', 'sigmoid'],
       default='relu'),
       input_shape=input_shape
       )
       )
  
       model.add(
       layers.Dense(
       units=hp.Int('units', 16, 64, 4, default=16),
       activation=hp.Choice(
       'dense_activation',
       values=['relu', 'tanh', 'sigmoid'],
       default='relu')
       )
       )
  
       model.add(
       layers.Dropout(
       hp.Float(
       'dropout',
       min_value=0.0,
       max_value=0.1,
       default=0.005,
       step=0.01)
       )
       )
  
       model.add(layers.Dense(1))
  
       model.compile(
       optimizer='rmsprop',loss='mse',metrics=['mse']
       )
       return model
  
  
  hp.Int('units',8,64,4,default=8)
  hp.Choice('dense_activation', values=['relu', 'tanh', 'sigmoid'], default='relu')
  
  #Let’s instantiate a hypermodel object. Input shape varies per dataset and the problem you are trying to solve.
  
  input_shape = (x_train.shape[1],)
  hypermodel = RegressionHyperModel(input_shape)
  
  
  #tunnig random search
  
  tuner_rs = RandomSearch(
   hypermodel,
   objective='mse',
   seed=42,
   max_trials=10,
   executions_per_trial=2)
  
  #Run the random search tuner using the search method.
  
  tuner_rs.search(x_train_scaled, y_train, epochs=10, validation_split=0.2, verbose=0)
  #Select the best combination of hyperparameters the tuner had tried and evaluate.
  
  best_model = tuner_rs.get_best_models(num_models=1)[0]
  loss, mse = best_model.evaluate(x_test_scaled, y_test)
  </code></pre>
  
  <p>i run the class , but when i try to use any tuners such as random search, hyperband,etc. I got the following error </p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\ProgramData\Anaconda3\lib\site-packages\kerastuner\engine\hypermodel.py", line 105, in build
      model = self.hypermodel.build(hp)
    File "&lt;ipython-input-93-d8d5d966c04f&gt;", line 13, in build
      input_shape=input_shape
    File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\sequential.py", line 133, in add
      'Found: ' + str(layer))
  TypeError: The added layer must be an instance of class Layer. Found: &lt;tensorflow.python.keras.layers.core.Dense object at 0x0000015D19051B38&gt;
  &lt;IPython.core.display.HTML object&gt;
  Traceback (most recent call last):
    File "C:\ProgramData\Anaconda3\lib\site-packages\kerastuner\engine\hypermodel.py", line 105, in build
      model = self.hypermodel.build(hp)
    File "&lt;ipython-input-93-d8d5d966c04f&gt;", line 13, in build
      input_shape=input_shape
    File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\sequential.py", line 133, in add
      'Found: ' + str(layer))
  TypeError: The added layer must be an instance of class Layer. Found: &lt;tensorflow.python.keras.layers.core.Dense object at 0x0000015D196B0908&gt;
  &lt;IPython.core.display.HTML object&gt;
  Traceback (most recent call last):
    File "C:\ProgramData\Anaconda3\lib\site-packages\kerastuner\engine\hypermodel.py", line 105, in build
      model = self.hypermodel.build(hp)
    File "&lt;ipython-input-93-d8d5d966c04f&gt;", line 13, in build
      input_shape=input_shape
    File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\sequential.py", line 133, in add
      'Found: ' + str(layer))
  TypeError: The added layer must be an instance of class Layer. Found: &lt;tensorflow.python.keras.layers.core.Dense object at 0x0000015D19668B38&gt;
  &lt;IPython.core.display.HTML object&gt;
  Traceback (most recent call last):
    File "C:\ProgramData\Anaconda3\lib\site-packages\kerastuner\engine\hypermodel.py", line 105, in build
      model = self.hypermodel.build(hp)
    File "&lt;ipython-input-93-d8d5d966c04f&gt;", line 13, in build
      input_shape=input_shape
    File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\sequential.py", line 133, in add
      'Found: ' + str(layer))
  TypeError: The added layer must be an instance of class Layer. Found: &lt;tensorflow.python.keras.layers.core.Dense object at 0x0000015D19681940&gt;
  &lt;IPython.core.display.HTML object&gt;
  Traceback (most recent call last):
    File "C:\ProgramData\Anaconda3\lib\site-packages\kerastuner\engine\hypermodel.py", line 105, in build
      model = self.hypermodel.build(hp)
    File "&lt;ipython-input-93-d8d5d966c04f&gt;", line 13, in build
      input_shape=input_shape
    File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\sequential.py", line 133, in add
      'Found: ' + str(layer))
  TypeError: The added layer must be an instance of class Layer. Found: &lt;tensorflow.python.keras.layers.core.Dense object at 0x0000015D1109E908&gt;
  &lt;IPython.core.display.HTML object&gt;
  Traceback (most recent call last):
    File "C:\ProgramData\Anaconda3\lib\site-packages\kerastuner\engine\hypermodel.py", line 105, in build
      model = self.hypermodel.build(hp)
    File "&lt;ipython-input-93-d8d5d966c04f&gt;", line 13, in build
      input_shape=input_shape
    File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\sequential.py", line 133, in add
      'Found: ' + str(layer))
  TypeError: The added layer must be an instance of class Layer. Found: &lt;tensorflow.python.keras.layers.core.Dense object at 0x0000015D10E86AC8&gt;
  &lt;IPython.core.display.HTML object&gt;
  Traceback (most recent call last):
  
    File "&lt;ipython-input-100-d0d2704255f3&gt;", line 7, in &lt;module&gt;
      project_name='helloworld')
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\kerastuner\tuners\randomsearch.py", line 175, in __init__
      **kwargs)
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\kerastuner\engine\multi_execution_tuner.py", line 58, in __init__
      oracle, hypermodel, **kwargs)
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\kerastuner\engine\tuner.py", line 103, in __init__
      overwrite=overwrite)
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\kerastuner\engine\base_tuner.py", line 91, in __init__
      self._populate_initial_space()
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\kerastuner\engine\base_tuner.py", line 106, in _populate_initial_space
      self.hypermodel.build(hp)
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\kerastuner\engine\hypermodel.py", line 65, in _build_wrapper
      return self._build(hp, *args, **kwargs)
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\kerastuner\engine\hypermodel.py", line 115, in build
      'Too many failed attempts to build model.')
  
  RuntimeError: Too many failed attempts to build model.
  </code></pre>
  
  <p>please any one can tell me how to solve it </p>