def cluster_images(data_batch, k, smart_init = False): fo = open(data_batch, 'rb') dict = cPickle.load(fo) fo.close() m = dict['data'] kmeans_out = kmeans_warm_up.kmeans(m, k, smart_init) error = kmeans_out['error'] mu = kmeans_out['mu'] resp = kmeans_out['resp'] result = kmeans_out['dist'] # creates cluster directories and saves images for i in range(k): if not os.path.exists(str(i)): os.makedirs(str(i)) get_image(mu[i], str(i) + "/0.png") num_pts = m.shape[0] for i in range(num_pts): get_image(m[i], str(resp[i][0]) + "/" + str(np.min(result[i])) + ".png") return error
from kmeans_warm_up import kmeans def unpickle(file): import cPickle fo = open(file, 'rb') dict = cPickle.load(fo) fo.close() return dict['data'] kmeans(unpickle('/home/aaron/Downloads/cifar-10-batches-py/data_batch_1'),5)