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.

TensorTest.cs 939 B

12345678910111213141516171819202122232425262728293031
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using NumSharp.Core;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Runtime.InteropServices;
  7. using System.Text;
  8. using Tensorflow;
  9. namespace TensorFlowNET.UnitTest
  10. {
  11. [TestClass]
  12. public class TensorTest
  13. {
  14. [TestMethod]
  15. public unsafe void NewTensor()
  16. {
  17. var nd = np.array(1f, 2f, 3f, 4f, 5f, 6f).reshape(2, 3);
  18. var tensor = new Tensor(nd);
  19. var array = tensor.Data<float>();
  20. Assert.AreEqual(tensor.dtype, TF_DataType.TF_FLOAT);
  21. Assert.AreEqual(tensor.rank, nd.ndim);
  22. Assert.AreEqual(tensor.shape[0], nd.shape[0]);
  23. Assert.AreEqual(tensor.shape[1], nd.shape[1]);
  24. Assert.AreEqual(tensor.bytesize, (uint)nd.size * sizeof(float));
  25. Assert.IsTrue(Enumerable.SequenceEqual(nd.Data<float>(), array));
  26. }
  27. }
  28. }

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

Contributors (1)