title: how to freeze some layers when fine tune resnet50
body: <p>I am trying to fine tune resnet 50 with keras. When I freeze all the layers in resnet50, everything works OK. However, I want to freeze some layers of resnet50, not all of them. But when I do this, I get some errors. Here is my code:</p>
  
  <pre><code>base_model = ResNet50(include_top=False, weights="imagenet", input_shape=(input_size, input_size, input_channels))
  model = Sequential()
  model.add(base_model)
  model.add(Flatten())
  model.add(Dense(80, activation="softmax"))
  
  #this is where the error happens. The commented code works fine
  """
  for layer in base_model.layers:
      layer.trainable = False
  """
  for layer in base_model.layers[:-26]:
      layer.trainable = False
  model.summary()
  optimizer = Adam(lr=1e-4)
  model.compile(loss="categorical_crossentropy", optimizer=optimizer, metrics=["accuracy"])
  
  callbacks = [
      EarlyStopping(monitor='val_loss', patience=4, verbose=1, min_delta=1e-4),
      ReduceLROnPlateau(monitor='val_loss', factor=0.1, patience=2, cooldown=2, verbose=1),
      ModelCheckpoint(filepath='weights/renet50_best_weight.fold_' + str(fold_count) + '.hdf5', save_best_only=True,
                      save_weights_only=True)
      ]
  
  model.load_weights(filepath="weights/renet50_best_weight.fold_1.hdf5")
  model.fit_generator(generator=train_generator(), steps_per_epoch=len(df_train) // batch_size,  epochs=epochs, verbose=1,
                    callbacks=callbacks, validation_data=valid_generator(), validation_steps = len(df_valid) // batch_size) 
  </code></pre>
  
  <p>the error is as follows:</p>
  
  <pre><code>Traceback (most recent call last):
  File "/home/jamesben/ai_challenger/src/train.py", line 184, in &lt;module&gt; model.load_weights(filepath="weights/renet50_best_weight.fold_" + str(fold_count) + '.hdf5')
  File "/usr/local/lib/python3.5/dist-packages/keras/models.py", line 719, in load_weights topology.load_weights_from_hdf5_group(f, layers)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/topology.py", line 3095, in load_weights_from_hdf5_group K.batch_set_value(weight_value_tuples)
  File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 2193, in batch_set_value get_session().run(assign_ops, feed_dict=feed_dict)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 767, in run run_metadata_ptr)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 944, in _run % (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape())))
  ValueError: Cannot feed value of shape (128,) for Tensor 'Placeholder_72:0', which has shape '(3, 3, 128, 128)'
  </code></pre>
  
  <p>can anyone give me some help on how many layer should I freeze with resnet50?</p>