title: Keras model optimization with bayesian optimization. Model summary is different
body: <p>I am trying to tune my cnn model with tuner keras. After running the bayesian search, when I display <code>model.summary()</code> it is totally different from the the bayesian optimization parameters found by the algorithm.</p>
  <p>I define my function model_builder as follow:</p>
  <pre><code>def model_builder2(hp):
    model = Sequential()
    #model.add(Input(shape=(50,50,3)))
    for i in range(hp.Int('num_blocks', 1,5)):
      hp_padding=hp.Choice('padding_'+ str(i), values=['valid', 'same'])
      hp_filters=hp.Choice('filters_'+ str(i), values=[32, 64])
  
      model.add(Conv2D(hp_filters, (3, 3), padding=hp_padding, activation='relu', kernel_initializer='he_uniform', input_shape=(50, 50, 3)))
      model.add(MaxPooling2D((2, 2)))
      model.add(Dropout(hp.Choice('dropout_'+ str(i), values=[0.2, 0.5])))
  
      model.add(Flatten())
  
      hp_units = hp.Int('units', min_value=25, max_value=512, step=25)
      model.add(Dense(hp_units, activation='relu', kernel_initializer='he_uniform'))
      model.add(Dense(2,activation=&quot;sigmoid&quot;))
      hp_learning_rate = hp.Choice('learning_rate', values=[1e-2, 1e-3, 1e-5])
      #hp_optimizer=hp.Choice('Optimizer', values=['Adam', 'SGD'])
      #hp_optimizer=hp.Choice('Optimizer', values=['Adam'])
  
      #model.compile(loss=keras.losses.binary_crossentropy, optimizer=tf.keras.optimizers.Adam(learning_rate=hp_learning_rate), metrics=['accuracy'])
      model.compile(optimizer=tf.optimizers.Adam(learning_rate=hp_learning_rate),loss=keras.losses.binary_crossentropy,metrics=['accuracy'])
      return model
  </code></pre>
  <p>After running the algorith, I have as best hyperparameters:</p>
  <pre><code>Best Hyper-parameters
  {'dropout_0': 0.5,
   'filters_0': 32,
   'learning_rate': 0.01,
   'num_blocks': 5,
   'padding_0': 'same',
   'units': 250}
  </code></pre>
  <p>But, when I do <code>model.summary()</code>, I have:</p>
  <pre><code>Model: &quot;sequential_1&quot;
  _________________________________________________________________
   Layer (type)                Output Shape              Param #   
  =================================================================
   conv2d_1 (Conv2D)           (None, 50, 50, 32)        896       
                                                                   
   max_pooling2d_1 (MaxPooling  (None, 25, 25, 32)       0         
   2D)                                                             
                                                                   
   dropout_1 (Dropout)         (None, 25, 25, 32)        0         
                                                                   
   flatten_1 (Flatten)         (None, 20000)             0         
                                                                   
   dense_2 (Dense)             (None, 250)               5000250   
                                                                   
   dense_3 (Dense)             (None, 2)                 502       
                                                                   
  =================================================================
  Total params: 5,001,648
  Trainable params: 5,001,648
  Non-trainable params: 0
  </code></pre>
  <p>It seems I don't have 5 blocks. Any idea ?</p>