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

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

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