|
|
@@ -33,19 +33,41 @@ namespace TensorFlowNET.Examples |
|
|
|
|
|
|
|
public bool Run() |
|
|
|
{ |
|
|
|
PrepareData(); |
|
|
|
|
|
|
|
var graph = tf.Graph().as_default(); |
|
|
|
|
|
|
|
tf.train.import_meta_graph("kmeans.meta"); |
|
|
|
|
|
|
|
// Input images |
|
|
|
var X = tf.placeholder(tf.float32, shape: new TensorShape(-1, num_features)); |
|
|
|
var X = graph.get_operation_by_name("Placeholder").output; // tf.placeholder(tf.float32, shape: new TensorShape(-1, num_features)); |
|
|
|
// Labels (for assigning a label to a centroid and testing) |
|
|
|
var Y = tf.placeholder(tf.float32, shape: new TensorShape(-1, num_classes)); |
|
|
|
var Y = graph.get_operation_by_name("Placeholder_1").output; // tf.placeholder(tf.float32, shape: new TensorShape(-1, num_classes)); |
|
|
|
|
|
|
|
// K-Means Parameters |
|
|
|
var kmeans = new KMeans(X, k, distance_metric: KMeans.COSINE_DISTANCE, use_mini_batch: true); |
|
|
|
//var kmeans = new KMeans(X, k, distance_metric: KMeans.COSINE_DISTANCE, use_mini_batch: true); |
|
|
|
|
|
|
|
// Build KMeans graph |
|
|
|
var training_graph = kmeans.training_graph(); |
|
|
|
|
|
|
|
//var training_graph = kmeans.training_graph(); |
|
|
|
|
|
|
|
var init_vars = tf.global_variables_initializer(); |
|
|
|
Tensor init_op = graph.get_operation_by_name("cond/Merge"); |
|
|
|
var train_op = graph.get_operation_by_name("group_deps"); |
|
|
|
Tensor avg_distance = graph.get_operation_by_name("Mean"); |
|
|
|
Tensor cluster_idx = graph.get_operation_by_name("Squeeze_1"); |
|
|
|
|
|
|
|
with(tf.Session(graph), sess => |
|
|
|
{ |
|
|
|
sess.run(init_vars, new FeedItem(X, full_data_x)); |
|
|
|
sess.run(init_op, new FeedItem(X, full_data_x)); |
|
|
|
|
|
|
|
// Training |
|
|
|
foreach(var i in range(1, num_steps + 1)) |
|
|
|
{ |
|
|
|
var result = sess.run(new Tensor[] { avg_distance, cluster_idx }, new FeedItem(X, full_data_x)); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|