You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

OperationsTest.cs 1.2 kB

6 years ago
6 years ago
6 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using Tensorflow;
  6. namespace TensorFlowNET.UnitTest
  7. {
  8. [TestClass]
  9. public class OperationsTest
  10. {
  11. [TestMethod]
  12. public void placeholder()
  13. {
  14. var x = tf.placeholder(tf.float32);
  15. }
  16. [TestMethod]
  17. public void addInPlaceholder()
  18. {
  19. var a = tf.placeholder(tf.float32);
  20. var b = tf.placeholder(tf.float32);
  21. var c = tf.add(a, b);
  22. using(var sess = tf.Session())
  23. {
  24. var feed_dict = new Dictionary<Tensor, object>();
  25. feed_dict.Add(a, 3.0f);
  26. feed_dict.Add(b, 2.0f);
  27. var o = sess.run(c, feed_dict);
  28. }
  29. }
  30. [TestMethod]
  31. public void addInConstant()
  32. {
  33. var a = tf.constant(4.0f);
  34. var b = tf.constant(5.0f);
  35. var c = tf.add(a, b);
  36. using (var sess = tf.Session())
  37. {
  38. var o = sess.run(c);
  39. Assert.AreEqual(o, 9.0f);
  40. }
  41. }
  42. }
  43. }

tensorflow框架的.NET版本,提供了丰富的特性和API,可以借此很方便地在.NET平台下搭建深度学习训练与推理流程。

Contributors (1)