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.

PythonTest.cs 1.2 kB

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using Microsoft.VisualStudio.TestTools.UnitTesting;
  7. using Tensorflow;
  8. namespace TensorFlowNET.UnitTest
  9. {
  10. /// <summary>
  11. /// Use as base class for test classes to get additional assertions
  12. /// </summary>
  13. public class PythonTest : Python
  14. {
  15. public void assertItemsEqual(ICollection expected, ICollection given)
  16. {
  17. Assert.IsNotNull(expected);
  18. Assert.IsNotNull(given);
  19. var e = expected.OfType<object>().ToArray();
  20. var g = given.OfType<object>().ToArray();
  21. Assert.AreEqual(e.Length, g.Length, $"The collections differ in length expected {e.Length} but got {g.Length}");
  22. for(int i=0; i<e.Length; i++)
  23. Assert.AreEqual(e[i], g[i], $"Items differ at index {i}, expected {e[i]} but got {g[i]}");
  24. }
  25. public void assertEqual(object given, object expected)
  26. {
  27. Assert.AreEqual(expected, given);
  28. }
  29. protected PythonTest self { get => this; }
  30. }
  31. }

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