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
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. var op_list = OpList.Parser.ParseFrom(buffer);
  22. Assert.IsTrue(op_list.Op.Count > 1000);
  23. }
  24. [TestMethod]
  25. public void addInPlaceholder()
  26. {
  27. var a = tf.placeholder(tf.float32);
  28. var b = tf.placeholder(tf.float32);
  29. var c = tf.add(a, b);
  30. using(var sess = tf.Session())
  31. {
  32. var o = sess.run(c,
  33. new FeedItem(a, 3.0f),
  34. new FeedItem(b, 2.0f));
  35. Assert.AreEqual((float)o, 5.0f);
  36. }
  37. }
  38. [TestMethod]
  39. public void addInConstant()
  40. {
  41. var a = tf.constant(4.0f);
  42. var b = tf.constant(5.0f);
  43. var c = tf.add(a, b);
  44. using (var sess = tf.Session())
  45. {
  46. var o = sess.run(c);
  47. Assert.AreEqual((float)o, 9.0f);
  48. }
  49. }
  50. }
  51. }

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