title: How to extract feature vector for image when using CNN in Keras
body: <p>I am doing a binary classification problem, my model architecture is as follow</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>def CNN_model(height, width, depth):
      input_shape = (height, width, depth)
  
      model = Sequential()
      # Block 1
      model.add(Conv2D(64, kernel_size=(3, 3), strides=1, activation='relu', input_shape=input_shape, padding='VALID'))
      model.add(Conv2D(64, kernel_size=(3, 3), strides=1, activation='relu', padding='VALID'))
      model.add(MaxPooling2D(pool_size=(2, 2)))
  
      # Block 2
      model.add(Conv2D(128, kernel_size=(3, 3), strides=1, activation='relu', padding='VALID'))
      model.add(Conv2D(128, kernel_size=(3, 3), strides=1, activation='relu', padding='VALID'))
      model.add(AveragePooling2D(pool_size=(19, 19)))
  
      # set of FC =&gt; RELU layers
      model.add(Flatten())
      model.add(Dense(128))
      model.add(Activation('relu'))
      model.add(BatchNormalization())
      model.add(Dense(num_classes, activation='softmax'))
      model.compile(loss=keras.losses.binary_crossentropy,
                    optimizer=keras.optimizers.Adadelta(),
                    metrics=['accuracy'])
      return model</code></pre>
  </div>
  </div>
  </p>
  
  <p>I need for each image on a test set, I get a 128-D feature vector collected from FC layer use for SVM classification. More detail, from <code>model.add(Dense(128))</code>. Can you please show me how to solve this problem? Thank you! </p>