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.5 kB

6 years ago
6 years ago
6 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using Tensorflow;
  6. using Buffer = Tensorflow.Buffer;
  7. namespace TensorFlowNET.UnitTest
  8. {
  9. [TestClass]
  10. public class OperationsTest
  11. {
  12. /// <summary>
  13. /// Port from tensorflow\c\c_api_test.cc
  14. /// `TEST(CAPI, GetAllOpList)`
  15. /// </summary>
  16. [TestMethod]
  17. public void GetAllOpList()
  18. {
  19. var handle = c_api.TF_GetAllOpList();
  20. var buffer = new Buffer(handle);
  21. Assert.IsTrue(buffer.Length == buffer.Length);
  22. }
  23. [TestMethod]
  24. public void addInPlaceholder()
  25. {
  26. var a = tf.placeholder(tf.float32);
  27. var b = tf.placeholder(tf.float32);
  28. var c = tf.add(a, b);
  29. using(var sess = tf.Session())
  30. {
  31. var feed_dict = new Dictionary<Tensor, object>();
  32. feed_dict.Add(a, 3.0f);
  33. feed_dict.Add(b, 2.0f);
  34. var o = sess.run(c, feed_dict);
  35. }
  36. }
  37. [TestMethod]
  38. public void addInConstant()
  39. {
  40. var a = tf.constant(4.0f);
  41. var b = tf.constant(5.0f);
  42. var c = tf.add(a, b);
  43. using (var sess = tf.Session())
  44. {
  45. var o = sess.run(c);
  46. Assert.AreEqual(o, 9.0f);
  47. }
  48. }
  49. }
  50. }

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

Contributors (1)