def computeKMeans(self): """Computes K means Clustering and returns the K centroids""" #centroids, labels = scipy.cluster.vq.kmeans(self.patch_set,self.KMeans,self.Kmeans_iterations) #Compute Kmeans on the set of patches centroids = cluster.k_means(self.patch_set,self.KMeans) centroids = centroids[0] for i in xrange(centroids.shape[0]): #Save these means as images to visualize (also enlarge for better visualiztion) scipy.misc.imsave('CIFAR/Kmean/name'+str(i)+'.jpg', scipy.misc.imresize(centroids[i].reshape(3,PATCH_SIZE,PATCH_SIZE),(50,50))) return None
def computeKMeans(self): """Computes K means Clustering and returns the K centroids""" # centroids, labels = scipy.cluster.vq.kmeans(self.patch_set,self.KMeans,self.Kmeans_iterations) centroids, labels, error = cluster.k_means(self.patch_set, self.KMeans) for i in xrange( centroids.shape[0] ): # Save these means as images to visualize (also enlarge for better visualiztion) scipy.misc.imsave( "Kaggle/Kmean/name" + str(i) + ".jpg", scipy.misc.imresize(centroids[i].reshape(self.Patch_size, self.Patch_size, 3), (50, 50)), ) return None
def whittenMeans(self): """Whittens the data and Computes K means Clustering and returns the K centroids""" #pca_Obj = PCA(whiten=True) #Initialise the skLearn PCA decomposer for whittening the data #transformed_patch_set = pca_Obj.fit_transform(self.patch_set.T) #transformed_patch_set = pca_Obj.inverse_transform(transformed_patch_set) transformed_patch_set = self.WhittenByPCA() #centroids, labels = scipy.cluster.vq.kmeans(np.real(transformed_patch_set.T),self.KMeans,self.Kmeans_iterations) #K-means on this Whittened data centroids = cluster.k_means(np.real(transformed_patch_set.T),self.KMeans) centroids = centroids[0] for i in xrange(centroids.shape[0]): scipy.misc.imsave('CIFAR/Whitten/name'+str(i)+'.jpg', scipy.misc.imresize(centroids[i].reshape(3,PATCH_SIZE,PATCH_SIZE),(50,50))) print 'Computed and Saved the means' return None
def whittenMeans(self): """Whittens the data and Computes K means Clustering and returns the K centroids""" pca_Obj = PCA(whiten=True) # Initialise the skLearn PCA decomposer for whittening the data # transformed_patch_set = pca_Obj.fit_transform(self.patch_set.T) transformed_patch_set = self.WhittenByPCA() # centroids, labels = scipy.cluster.vq.kmeans(np.real(transformed_patch_set.T),self.KMeans,self.Kmeans_iterations) #K-means on this Whittened data centroids, labels, error = cluster.k_means(np.real(transformed_patch_set.T), self.KMeans) for i in xrange(centroids.shape[0]): scipy.misc.imsave( "Kaggle/Whitten/name" + str(i) + ".jpg", scipy.misc.imresize(centroids[i].reshape(self.Patch_size, self.Patch_size, 3), (50, 50)), ) print "Computed and Saved the means" return None