the number of words used does not usually have big impact on the final performance of the algorithm naturallyif the number is extremely small (ten or twentywhen you have few thousand images)then the overall system will not perform well similarlyif you have too many words (many more than the number of images for example)the system will not perform well howeverin between these two extremesthere is often very large plateau where you can choose the number of words without big impact on the result as rule of thumbusing value such as or if you have very many imagesshould give you good result we are going to start by computing the featuresalldescriptors [for im in imagesim mh imread(imas_grey=trueim im astype(np uint alldescriptors append(surf surf(imdescriptors_only)this results in over , local descriptors nowwe use -means clustering to obtain the centroids we could use all the descriptorsbut we are going to use smaller sample for extra speedconcatenated np concatenate(alldescriptorsget all descriptors into single array concatenated concatenated[:: use only every nd vector from sklearn cluster import kmeans km kmeans(kkm fit(concatenatedafter this is done (which will take while)we have km containing information about the centroids we now go back to the descriptors and build feature vectorsfeatures [for in alldescriptorsc km predict(dfeatures appendnp array([np sum( =cifor ci in range( )]features np array(featuresthe end result of this loop is that features[fiis histogram corresponding to the image at position fi (the same could have been computed faster with the np histogram functionbut getting the arguments just right is little trickyand the rest of the code isin any casemuch slower than this simple step