data = tf.data.Dataset.from_tensor_slices((labels)) data = data.map(load.loadImage) iterator = data.make_initializable_iterator() next_element = iterator.get_next() with tf.Session() as sess: sess.run(iterator.initializer) while True: try: elem = next_element.eval() next_element = iterator.get_next() except tf.errors.OutOfRangeError: break clusters = KMeans(elem, 6) img = clusters.clustering(5) plt.figure() plt.ion() plt.imshow(img) plt.colorbar() plt.show() plt.pause(0.001) def input_fn(): return tf.train.limit_epochs( tf.convert_to_tensor(points, dtype=tf.float32), num_epochs=1) points = elem.flatten(); points = load.adjustDimension(points) kmeans = tf.contrib.factorization.KMeansClustering(num_clusters=6, use_mini_batch=False) num_iterations = 8
print("Clustering K-means") for i in range(10): print("Kmeans itr ", i) st = time.time() #load data into mem hd_data = np.loadtxt(fname, delimiter=delim) kmeans = KMeans(hd_data.tolist(), nb_cts) #cluster kmeans.clustering() et = time.time() km_avg += (et - st) #remove data from mem del hd_data km_avg = km_avg / 10 #gathering data for bar charts bar_x = np.arange(2) c_times = [np.min(times), km_avg] #plotting