Applying PCA on single image

Viewed 126

Firstly I have used annoy for storing my image features and applied PCA with 200 number of feature.

num_feature_dimensions = 200
pca = PCA(n_components=num_feature_dimensions)
pca.fit(feature_list)
feature_list = pca.transform(feature_list)

Then I added features to annoy index and created annoy tree object

annoy_index = AnnoyIndex(200,'angular')  

for i in range(num_images):
    feature = feature_list[i]
    annoy_index.add_item(i, feature)
    
annoy_index.build(40)
annoy_index.save('annoy_micol_prod_index.ann')

Now I want to convert an test image for prediction purpose.

I need 512 feature to 200 feature

after features extraction of an image i added it to a list. which shape is (1,512).

num_feature_dimensions = 200
pcaSingle = PCA(num_feature_dimensions)
pcaSingle.fit(single_feature)
test_img_feature = pcaSingle.transform(single_feature)

Then I am getting the following error.

[ ValueError: n_components=200 must be between 0 and min(n_samples, n_features)=1 with svd_solver='full']

0 Answers
Related