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
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. Assert.IsTrue(buffer.Length == buffer.Length);
  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, feed_dict: new FeedItem[]
  33. {
  34. new FeedItem(a, 3.0f),
  35. new FeedItem(b, 2.0f)
  36. });
  37. Assert.AreEqual((float)o, 5.0f);
  38. }
  39. }
  40. [TestMethod]
  41. public void addInConstant()
  42. {
  43. var a = tf.constant(4.0f);
  44. var b = tf.constant(5.0f);
  45. var c = tf.add(a, b);
  46. using (var sess = tf.Session())
  47. {
  48. var o = sess.run(c);
  49. Assert.AreEqual((float)o, 9.0f);
  50. }
  51. }
  52. }
  53. }

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