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

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