|
|
|
@@ -1,4 +1,5 @@ |
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using System;
|
|
|
|
using Tensorflow;
|
|
|
|
|
|
|
|
@@ -14,26 +15,30 @@ namespace TensorFlowNET.UnitTest.control_flow_ops_test |
|
|
|
public void testCondTrue()
|
|
|
|
{
|
|
|
|
var graph = tf.Graph().as_default();
|
|
|
|
// tf.train.import_meta_graph("cond_test.meta");
|
|
|
|
var json = JsonConvert.SerializeObject(graph._nodes_by_name, Formatting.Indented);
|
|
|
|
|
|
|
|
with(tf.Session(graph), sess =>
|
|
|
|
{
|
|
|
|
var x = tf.constant(2);
|
|
|
|
var y = tf.constant(5);
|
|
|
|
var pred = tf.less(x, y);
|
|
|
|
var x = tf.constant(2, name: "x"); // graph.get_operation_by_name("Const").output;
|
|
|
|
var y = tf.constant(5, name: "y"); // graph.get_operation_by_name("Const_1").output;
|
|
|
|
var pred = tf.less(x, y); // graph.get_operation_by_name("Less").output;
|
|
|
|
|
|
|
|
Func<ITensorOrOperation> if_true = delegate
|
|
|
|
{
|
|
|
|
return tf.multiply(x, 17);
|
|
|
|
return tf.constant(2, name: "t2");
|
|
|
|
};
|
|
|
|
|
|
|
|
Func<ITensorOrOperation> if_false = delegate
|
|
|
|
{
|
|
|
|
return tf.add(y, 23);
|
|
|
|
return tf.constant(5, name: "f5");
|
|
|
|
};
|
|
|
|
|
|
|
|
var z = control_flow_ops.cond(pred, if_true, if_false);
|
|
|
|
var z = control_flow_ops.cond(pred, if_true, if_false); // graph.get_operation_by_name("cond/Merge").output
|
|
|
|
|
|
|
|
json = JsonConvert.SerializeObject(graph._nodes_by_name, Formatting.Indented);
|
|
|
|
int result = z.eval(sess);
|
|
|
|
assertEquals(result, 34);
|
|
|
|
assertEquals(result, 2);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@@ -58,25 +63,31 @@ namespace TensorFlowNET.UnitTest.control_flow_ops_test |
|
|
|
|
|
|
|
print(result == 24) */
|
|
|
|
|
|
|
|
var graph = tf.Graph().as_default();
|
|
|
|
//tf.train.import_meta_graph("cond_test.meta");
|
|
|
|
//var json = JsonConvert.SerializeObject(graph._nodes_by_name, Formatting.Indented);
|
|
|
|
|
|
|
|
with(tf.Session(), sess =>
|
|
|
|
{
|
|
|
|
var x = tf.constant(2);
|
|
|
|
var y = tf.constant(1);
|
|
|
|
var x = tf.constant(2, name: "x");
|
|
|
|
var y = tf.constant(1, name: "y");
|
|
|
|
var pred = tf.less(x, y);
|
|
|
|
|
|
|
|
Func<ITensorOrOperation> if_true = delegate
|
|
|
|
{
|
|
|
|
return tf.multiply(x, 17);
|
|
|
|
return tf.constant(2, name: "t2");
|
|
|
|
};
|
|
|
|
|
|
|
|
Func<ITensorOrOperation> if_false = delegate
|
|
|
|
{
|
|
|
|
return tf.add(y, 23);
|
|
|
|
return tf.constant(1, name: "f1");
|
|
|
|
};
|
|
|
|
|
|
|
|
var z = control_flow_ops.cond(pred, if_true, if_false);
|
|
|
|
|
|
|
|
var json1 = JsonConvert.SerializeObject(graph._nodes_by_name, Formatting.Indented);
|
|
|
|
int result = z.eval(sess);
|
|
|
|
assertEquals(result, 24);
|
|
|
|
assertEquals(result, 1);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|