ExtractorPredictor

class model.extractor_predictor.feature_extractor.FeatureExtractor

Bases: object

This class represents a feature extractor for image data. It provides an interface for fitting the model to the data and extracting features from the data.

fit(images)
load_model(params)
predict(images)
serialize()
class model.extractor_predictor.feature_extractor.SIFTFeatureExtractor(detector_name='SIFT', n_visual_words=100)

Bases: FeatureExtractor

SIFTFeatureExtractor is a class that extracts SIFT features from images and computes visual words.

visual_words

The computed visual words.

Type:

ndarray

n_visual_words

The number of visual words to compute.

Type:

int

detector

The SIFT detector object. Defaults to SIFT. Other options are RootSIFT and PCASIFT.

Type:

SIFT

Raises:

NotImplementedError – If the specified detector_name is not implemented.

compute_visual_words(descriptors)

Computes the visual words using K-means clustering.

Parameters:

descriptors (ndarray) – The descriptors of the images.

Returns:

The computed visual words.

Return type:

ndarray

fit(images)

Fits the SIFTFeatureExtractor by computing the visual words from the given images.

Parameters:

images (List[ndarray]) – The list of images to fit the extractor on.

classmethod load_model(params)

Loads a serialized SIFTFeatureExtractor object.

Parameters:

params (dict) – A dictionary containing the serialized representation of the object.

Returns:

The loaded SIFTFeatureExtractor object.

Return type:

SIFTFeatureExtractor

predict(images)

Predicts the features of the given images using the computed visual words.

Parameters:

images (List[ndarray]) – The list of images to predict the features for.

Returns:

The predicted features for each image.

Return type:

List[ndarray]

Raises:

Exception – If the model has not been fitted.

serialize()

Serializes the SIFTFeatureExtractor object.

Returns:

A dictionary containing the serialized representation of the object.

Return type:

dict

transform(images)

Transforms the images into descriptors using the type of SIFT detector.

Parameters:

images (List[ndarray]) – The list of images to transform.

Returns:

The descriptors of the images.

Return type:

List[ndarray]

class model.extractor_predictor.feature_extractor.VGG16FeatureExtractor(input_shape=(224, 224, 3), weights='imagenet', pooling='max')

Bases: FeatureExtractor

A class representing a feature extractor based on the VGG16 model.

model

The VGG16 model used for feature extraction.

input_shape

The input shape of the images to be processed.

weights

The weights used by the model.

pooling

The pooling strategy used by the model.

fit(images=None)

Fits the feature extractor to the given images. Since we are only using the imagenet weights for feature extraction, this method does not do anything. However, it is included for compatibility with the ExtractorPredictor class. In future, we can add code here to fine-tune the model on the given images.

classmethod load_model(params)
predict(images)

Predicts the features of the given images using the fitted model.

Parameters:

images (numpy.ndarray) – An array of images to extract features from.

Returns:

An array of extracted features.

Return type:

numpy.ndarray

Raises:

Exception – If the model has not been fitted.

serialize()

Serializes the feature extractor model.

Returns:

A dictionary containing the serialized information of the feature extractor.
  • ”weights”: The weights used by the model (e.g., “imagenet”).

  • ”input_shape”: The shape of the model’s input.

  • ”pooling”: The pooling method used by the model (e.g., “max”).

Return type:

dict