concept feature vector in category deep learning

appears as: feature vector, feature vectors, feature vectors, The feature vectors
Deep Learning for Search

This is an excerpt from Manning's book Deep Learning for Search.

Think back to the color histogram or BOVW models—you obtained a feature vector for each image. A CNN gives you more than that: the dense layer close to the output layer contains the feature vectors you can use to compare images, and you also have a trained CNN that you can use to tag new images.

After training has finished, if you want to index the feature vectors learned for each image by the convolutional neural network, you have to iterate again over the image dataset, perform a feed-forward computation for each image, and extract the feature vectors generated by the CNN.

Listing 8.3. Extracting feature vectors
DataSetIterator iterator = ...                        #1
while (iterator.hasNext()) {                          #2

  DataSet batch = iterator.next(batchSize);           #3
  for (int k = 0; k < batchSize; k++) {

    DataSet dataSet = batch.get(k);                   #4

    List<INDArray> activations = model.
        feedForward(dataSet.getFeatureMatrix(),
         false);                                      #5

    INDArray imageRepresentation = activations
        .get(activations.size() - 2);                 #6

    INDArray classification = activations.get(
        activations.size() - 1);                      #7
    ...                                               #8
  }
}

You’re now ready to learn how you can efficiently index and search the feature vectors extracted by a CNN (although this applies generally for any feature vector).

Listing 8.4. Indexing a feature vector as a point
List<INDArray> activations = cnnModel.feedForward(currentImage, false);
INDArray imageRepresentation = activations
    .get(activations.size() - 2);                #1
float[] aFloat = imageRepresentation.data()
    .asFloat();                                  #2
doc.add(new FloatPoint("features", floats));     #3

Unfortunately, as of Lucene 7, FloatPoints can index points whose dimension is at most 8. Feature vectors are usually much bigger than that: for example, our example CNN for CIFAR generates feature vectors whose dimension is 1,024. You’ll need to reduce the float[] used to instantiate FloatPoint from having 1,024 values to holding at most 8.

To test the usage of an autoencoder with unlabeled data, you’ll still use the CIFAR dataset, but you won’t use the classes attached to each image to train the network. You’ll instead use them to evaluate whether the search results are good after training has finished. But the important part of this approach is that you’ll have a way to generate a dense vector representation, like a feature vector, for your images, even when they’re not labeled.