title: Changing a pretrained Keras model with fixed input to a flexible one in tensoflow?
body: <p>I want to use a pre-trained BagNet (<a href="https://github.com/wielandbrendel/bag-of-local-features-models" rel="nofollow noreferrer">https://github.com/wielandbrendel/bag-of-local-features-models</a>) to extract features. The net has fixed input height and width, the input is <code>(None,3,224,224)</code>. Now, I want to build a new model with fexible input sizes. I tried approaches with model.layers.pop()[0] to remove the first layer and replace it with a flexible input but I get errors:</p>
  
  <blockquote>
    <p>ValueError: Graph disconnected: cannot obtain value for tensor Tensor("input0_6:0", shape=(?, 3, 224, 224), dtype=float32) at layer "input0". The following previous layers were accessed without issue: []</p>
  </blockquote>
  
  <pre><code>keras_model = bagnets.keras.bagnet8()
  keras_model.layers.pop()[0]
  x = Input(batch_shape=(None, 3, None, None))   
  newModel = Model(x, keras_model.output)
  </code></pre>
  
  <p>How could I ressolve this issue or what are other options?</p>